On 10/23/2015 01:14 PM, Markus Armbruster wrote: > Eric Blake <[email protected]> writes: > >> Rather than storing a base class as a pointer to a box, just >> store the fields of that base class in the same order, so that >> a child struct can be directly cast to its parent. This gives >> less malloc overhead, less pointer dereferencing, and even less >> generated code. Compare to the earlier commit 1e6c1616a "qapi: >> Generate a nicer struct for flat unions" (although that patch >> had fewer places to change, as less of qemu was directly using >> qapi structs for flat unions). It also drops a hack that was >> needed for type-safe casting to the base class of a struct. >> >> Changes to the generated code look like this in qapi-types.h: >>
>>
>> as well as:
>>
>> | static inline SpiceBasicInfo *qapi_SpiceChannel_base(const SpiceChannel
>> *obj)
>> | {
>> |- return (SpiceBasicInfo *)obj->base;
>> |+ return (SpiceBasicInfo *)obj;
>> | }
>
> No more, PATCH 09 hides this change. If you limit that one to just
> unions, it'll be visible again here, but it'll look different.
No, this change is new to v10, because of patch 09. In v9, we did not
have gen_upcast(); in v10, patch 9's version of gen_upcast() had to
special-case struct to output 'obj->base', and patch 10 gets rid of the
special case to output 'obj' always.
If I limit patch 9 to just unions, then there would be no clients using
the upcast wrappers in patch 9. The only users of upcasts that benefit
from the result of gen_upcast() are the struct users in ui/*.c, that
were touched in patch 9, and then where _this_ change in the generated
code in patch 10 lets ui/ code remain unchanged (the way the upcast
happens changed, but it was nicely hidden behind the nice wrapper
interface).
>
>>
>> and this in qapi-visit.c:
>>
>> | static void visit_type_SpiceChannel_fields(Visitor *v, SpiceChannel **obj,
>> Error **errp)
>> | {
>> | Error *err = NULL;
>> |
>> |- visit_type_implicit_SpiceBasicInfo(v, &(*obj)->base, &err);
>> |+ visit_type_SpiceBasiInfo_fields(v, (SpiceBasicInfo **)obj, &err);
>
> s/BasiI/BasicI/
I should have used the mouse to copy-paste instead of typing late at
night :)
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
