qemu-devel
[Top][All Lists]
Advanced

[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: Eric Blake
Subject: Re: [Qemu-devel] [PATCH v5 1/5] qobject: ensure base is at offset 0
Date: Wed, 18 Apr 2018 12:04:01 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0

On 04/18/2018 11:45 AM, Markus Armbruster wrote:

>> 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?
> 
> Where does PATCH 2 exploit "base first"?

It doesn't, but PATCH 4 does:

>  /**
>   * qobject_ref(): Increment QObject's reference count
> + *
> + * Returns: the same @obj. The type of @obj will be propagated to the
> + * return type.
>   */
> -#define qobject_ref(obj) qobject_ref_impl(QOBJECT(obj))
> +#define qobject_ref(obj) ((typeof(obj)) qobject_ref_impl(QOBJECT(obj)))
>  


-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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