• E
    qapi-visit: Convert to new qapi union layout · 150d0564
    Eric Blake 提交于
    We have two issues with our qapi union layout:
    1) Even though the QMP wire format spells the tag 'type', the
    C code spells it 'kind', requiring some hacks in the generator.
    2) The C struct uses an anonymous union, which places all tag
    values in the same namespace as all non-variant members. This
    leads to spurious collisions if a tag value matches a non-variant
    member's name.
    
    Make the conversion to the new layout for qapi-visit.py.
    
    Generated code changes look like:
    
    |@@ -4912,16 +4912,16 @@ void visit_type_MemoryDeviceInfo(Visitor
    |     if (!*obj) {
    |         goto out_obj;
    |     }
    |-    visit_type_MemoryDeviceInfoKind(v, &(*obj)->kind, "type", &err);
    |+    visit_type_MemoryDeviceInfoKind(v, &(*obj)->type, "type", &err);
    |     if (err) {
    |         goto out_obj;
    |     }
    |-    if (!visit_start_union(v, !!(*obj)->data, &err) || err) {
    |+    if (!visit_start_union(v, !!(*obj)->u.data, &err) || err) {
    |         goto out_obj;
    |     }
    |-    switch ((*obj)->kind) {
    |+    switch ((*obj)->type) {
    |     case MEMORY_DEVICE_INFO_KIND_DIMM:
    |-        visit_type_PCDIMMDeviceInfo(v, &(*obj)->dimm, "data", &err);
    |+        visit_type_PCDIMMDeviceInfo(v, &(*obj)->u.dimm, "data", &err);
    |         break;
    |     default:
    |         abort();
    |@@ -4930,7 +4930,7 @@ out_obj:
    |     error_propagate(errp, err);
    |     err = NULL;
    |     if (*obj) {
    |-        visit_end_union(v, !!(*obj)->data, &err);
    |+        visit_end_union(v, !!(*obj)->u.data, &err);
    |     }
    |     error_propagate(errp, err);
    |     err = NULL;
    Signed-off-by: NEric Blake <eblake@redhat.com>
    Message-Id: <1445898903-12082-14-git-send-email-eblake@redhat.com>
    [Commit message tweaked slightly]
    Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
    150d0564
qapi-visit.py 11.3 KB