[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v5 1/5] qobject: ensure base is at offset 0
From: |
Marc-André Lureau |
Subject: |
Re: [Qemu-devel] [PATCH v5 1/5] qobject: ensure base is at offset 0 |
Date: |
Wed, 18 Apr 2018 18:58:57 +0200 |
Hi
On Wed, Apr 18, 2018 at 6:45 PM, Markus Armbruster <address@hidden> wrote:
> Eric Blake <address@hidden> writes:
>
>> On 04/17/2018 08:35 AM, Marc-André Lureau wrote:
>>> All QObject types have the base QObject as first field. This allows to
>>
>> s/as/as their/
>>
>>> simplify qobject_to() and will allow further simplification in
>>
>> s/allows to simplify/allows the simplification of/
>> s/in/in the/
>>
>>> following patch.
>>
>> Might also be worth mentioning that this explicitly guarantees that
>> existing casts work correctly (even though we'd prefer to get rid of
>> such casts in any location except the qobject.h macros); Markus pointed out:
>>
>>>> Uh, there's another reason: existing type casts from QObject * to
>>>> subtypes. I just spotted one in tests/check-qdict.c:
>>>>
>>>> dst = (QDict *)qdict_crumple(src, &error_abort);
>
> As far as I'm concerned, that's the real reason. The simplification
> plus the check to make it safe seems like a wash.
>
> The cast I spotted appears to be the only one, though:
>
> $ git-grep '(Q[A-Z][a-z]* \*)'
> hmp.c: qmp_device_add((QDict *)qdict, NULL, &err);
> include/qapi/qmp/qobject.h: return (QObject *)obj;
> qobject/qobject.c:static void (*qdestroy[QTYPE__MAX])(QObject *) = {
> tests/check-qdict.c: dst = (QDict *)qdict_crumple(src, &error_abort);
>
> The first two cast away const, the third isn't a type cast. The fourth
> one should use qobject_to() instead, regardless of this patch.
>
> Do we want to force base to come first anyway?
to simplify qobject_to and allow static casting?
> Where does PATCH 2 exploit "base first"?
patch 2 no longer needs that afaict
[Qemu-devel] [PATCH v5 2/5] qobject: use a QObjectBase_ struct, Marc-André Lureau, 2018/04/17
[Qemu-devel] [PATCH v5 4/5] qobject: modify qobject_ref() to return obj, Marc-André Lureau, 2018/04/17
[Qemu-devel] [PATCH v5 5/5] qobject: modify qobject_ref() to assert on NULL, Marc-André Lureau, 2018/04/17