qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 2/3] qobject: assume base of a qobject is at off


From: Marc-André Lureau
Subject: Re: [Qemu-devel] [PATCH 2/3] qobject: assume base of a qobject is at offset 0
Date: Wed, 21 Mar 2018 15:21:56 +0100

Hi

On Wed, Mar 21, 2018 at 3:19 PM, Eric Blake <address@hidden> wrote:
> On 03/21/2018 09:08 AM, Marc-André Lureau wrote:
>>
>> Hi
>>
>> On Wed, Mar 21, 2018 at 3:01 PM, Paolo Bonzini <address@hidden>
>> wrote:
>>>
>>> On 21/03/2018 14:40, Marc-André Lureau wrote:
>>>>
>>>> +/* A typecast, checking for the type of arguments */
>>>> +/* QObject is at offset 0, for all QObject-derived types */
>>>> +#define QOBJECT(x) QEMU_GENERIC(x,              \
>>>> +    (QNull *, (QObject *) x),                   \
>>>> +    (const QNull *, (const QObject *) x),       \
>>>> +    (QNum *, (QObject *) x),                    \
>>>> +    (const QNum *, (const QObject *) x),        \
>>>> +    (QString *, (QObject *) x),                 \
>>>> +    (const QString *, (const QObject *) x),     \
>>>> +    (QDict *, (QObject *) x),                   \
>>>> +    (const QDict *, (const QObject *) x),       \
>>>> +    (QList *, (QObject *) x),                   \
>>>> +    (const QList *, (const QObject *) x),       \
>>>> +    (QBool *, (QObject *) x),                   \
>>>> +    (const QBool *, (const QObject *) x),       \
>>>> +    (QObject *, x),                             \
>>>> +    (const QObject *, x),                       \
>>>> +    qobject_unknown_type(x))
>>>
>>>
>>> Why not just
>>>
>>>          QEMU_GENERIC(x,
>>>                  (QObject *, x),
>>>                  (const QObject *, x),
>>>                  ({ \
>>>                          QEMU_BUILD_BUG_ON(offsetof(typeof(*x), base));
>>>                          &(x)->base;
>>>                  }))
>>>
>>> That is just an extension of what was being done before, and it is
>>> resilient against people putting a random "QObject base" in the middle
>>> of a struct.
>>>
>>
>> Yeah, I tried a few of those approaches. Here the problem is that
>> QObject doesn't have base field. So you get a compile time error with
>> a QObject * as argument.
>
>
> So the compiler requires &(x)->base to resolve even when it is not on the
> branch that gets selected?
>

Unfortunately, yes, all branches must compile apparently (I know)...



reply via email to

[Prev in Thread] Current Thread [Next in Thread]