On 09/23/2015 08:02 AM, Markus Armbruster wrote:

>> However, I'm not sure it would always help.  The conversion of
>> netdev_add to full qapi relies on being able to access the variant
>> through a named struct (such as NetdevTapOptions); unboxing the variant
>> would get rid of the convenient access to these named sub-structs.
> 
> struct Union {
>     EnumType type;
>     /* union tag is @type */
>     union {
>         One one;
>         Two two;
>     };
> };
> 
> For base, we go one step further and peel off the struct, to save some
> notational overhead.  Pointless for unions.

Ah, I see. Instead of malloc'ing a sub-struct and calling (roughly)

ptr = visit_start_struct(Union) // mallocs
subptr = visit_start_implicit_struct(One) // also mallocs
visit_type_fields(subptr)
visit_end_implicit_struct()

we would instead use inline allocation, with:

ptr = visit_start_struct(Union) // mallocs
visit_type_fields(&ptr->one)

seems straightforward enough; I'll play with the idea on top of my series.


-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to