On 03/30/2017 10:03 AM, Markus Armbruster wrote: >>> +SocketAddress *socket_address_crumple(SocketAddressFlat *addr_flat) >>> +{ >>> + SocketAddress *addr = g_new(SocketAddress, 1); >>> + >>> + addr->type = addr_flat->type; >> >> Works only because our enum is defined in the same order as the simple >> union's members. A bit fragile, so maybe we want to comment in the >> .json file that we can't reorder members of either the enum or the >> simple union's 'data'? Or it might even tickle a picky compiler to warn >> about assignment between incompatible enum types. Another option would >> be making it robust by instead doing switch(addr_flat->type) and >> assigning to addr->type in each branch of the switch. > > Sold. >
> Now looks like this: > > SocketAddress *socket_address_crumple(SocketAddressFlat *addr_flat) > { > SocketAddress *addr = g_new(SocketAddress, 1); > > switch (addr_flat->type) { > case SOCKET_ADDRESS_FLAT_TYPE_INET: > addr->type = SOCKET_ADDRESS_KIND_INET; > addr->u.inet.data = QAPI_CLONE(InetSocketAddress, > &addr_flat->u.inet); > break; Yes, that's better, and no tweaks to the .json file needed. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature