From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mbb6U-0001Jf-Ga for qemu-devel@nongnu.org; Thu, 13 Aug 2009 10:16:30 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mbb6P-0001Gz-F6 for qemu-devel@nongnu.org; Thu, 13 Aug 2009 10:16:29 -0400 Received: from [199.232.76.173] (port=43185 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mbb6P-0001Gu-BO for qemu-devel@nongnu.org; Thu, 13 Aug 2009 10:16:25 -0400 Received: from mx2.redhat.com ([66.187.237.31]:51872) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Mbb6N-0007IN-Tf for qemu-devel@nongnu.org; Thu, 13 Aug 2009 10:16:24 -0400 Date: Thu, 13 Aug 2009 11:16:12 -0300 From: Luiz Capitulino Message-ID: <20090813111612.6c5bee23@doriath> In-Reply-To: <4A841B66.4000907@redhat.com> References: <1250171428-29308-1-git-send-email-lcapitulino@redhat.com> <1250171428-29308-3-git-send-email-lcapitulino@redhat.com> <4A841B66.4000907@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] Re: [PATCH 02/29] Introduce QInt List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Avi Kivity Cc: aliguori@us.ibm.com, qemu-devel@nongnu.org On Thu, 13 Aug 2009 16:55:50 +0300 Avi Kivity wrote: > On 08/13/2009 04:50 PM, Luiz Capitulino wrote: > > + > > +/** > > + * qobject_to_qint(): Convert a QObject into a QInt > > + */ > > +static inline QInt *qobject_to_qint(const QObject *obj) > > +{ > > + return container_of(obj, QInt, base); > > +} > > + > > > > It's worthwhile to check the type here and return NULL if not an > integer. That allows users to > > QInt *qi = qobject_to_qint(...); > > if (qi) { > do something > } else { > error handling > } > > (this is equivalent to C++'s static_cast vs. dynamic_cast) OK. Note that QDict has high-level helpers like qdict_get_int() that assumes that the stored key is a QInt. I was in doubt about how to fail. I chose to use assert() and consider this a programming error.