Hi
On Wed, Mar 21, 2018 at 3:01 PM, Paolo Bonzini <[email protected]> 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.
>
That would work with an anonymous union though:
struct QObject {
union {
QType type;
QType base;
};
size_t refcnt;
};
If it's acceptable, I think I'll take this approach.