[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] Re: [PATCH 02/29] Introduce QInt
From: |
Luiz Capitulino |
Subject: |
[Qemu-devel] Re: [PATCH 02/29] Introduce QInt |
Date: |
Thu, 13 Aug 2009 11:16:12 -0300 |
On Thu, 13 Aug 2009 16:55:50 +0300
Avi Kivity <address@hidden> 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.
- [Qemu-devel] [PATCH v0 00/29] QMonitor, Luiz Capitulino, 2009/08/13
- [Qemu-devel] [PATCH 03/29] Introduce QString, Luiz Capitulino, 2009/08/13
- [Qemu-devel] [PATCH 04/29] Introduce QDict, Luiz Capitulino, 2009/08/13
- [Qemu-devel] [PATCH 05/29] Add wrappers to functions used by the Monitor, Luiz Capitulino, 2009/08/13
- [Qemu-devel] [PATCH 06/29] monitor: New format for handlers argument types, Luiz Capitulino, 2009/08/13
- [Qemu-devel] [PATCH 07/29] monitor: Setup a QDict with arguments to handlers, Luiz Capitulino, 2009/08/13
- [Qemu-devel] [PATCH 09/29] monitor: Port handler_0 to use QDict, Luiz Capitulino, 2009/08/13
- [Qemu-devel] [PATCH 08/29] monitor: Export QDict header, Luiz Capitulino, 2009/08/13
- [Qemu-devel] [PATCH 11/29] monitor: Port handler_2 to use QDict, Luiz Capitulino, 2009/08/13
- [Qemu-devel] [PATCH 10/29] monitor: Port handler_1 to use QDict, Luiz Capitulino, 2009/08/13