[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v11 13/24] qapi-visit: Convert to new qapi union lay
From: |
Eric Blake |
Subject: |
[Qemu-devel] [PATCH v11 13/24] qapi-visit: Convert to new qapi union layout |
Date: |
Mon, 26 Oct 2015 16:34:52 -0600 |
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 QMP 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: Eric Blake <address@hidden>
---
v11: hoist qapi.py change back to 13/25, and drop testsuite change;
enhance commit message
v10: new patch, split from 7/17 an 8/17
v9: new patch, but incorporates parts of v5 31/46 and Markus' RFC:
http://lists.gnu.org/archive/html/qemu-devel/2015-10/msg02236.html
---
scripts/qapi-visit.py | 24 +++++++++---------------
1 file changed, 9 insertions(+), 15 deletions(-)
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index 33c013a..f40c3c7 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -189,18 +189,18 @@ void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj,
const char *name, Error
if (err) {
goto out;
}
- visit_get_next_type(v, (int*) &(*obj)->kind, %(c_name)s_qtypes, name,
&err);
+ visit_get_next_type(v, (int*) &(*obj)->type, %(c_name)s_qtypes, name,
&err);
if (err) {
goto out_obj;
}
- switch ((*obj)->kind) {
+ switch ((*obj)->type) {
''',
c_name=c_name(name))
for var in variants.variants:
ret += mcgen('''
case %(case)s:
- visit_type_%(c_type)s(v, &(*obj)->%(c_name)s, name, &err);
+ visit_type_%(c_type)s(v, &(*obj)->u.%(c_name)s, name, &err);
break;
''',
case=c_enum_const(variants.tag_member.type.name,
@@ -261,22 +261,16 @@ void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj,
const char *name, Error
visit_type_%(c_type)s(v, &(*obj)->%(c_name)s, "%(name)s", &err);
''',
c_type=variants.tag_member.type.c_name(),
- # TODO ugly special case for simple union
- # Use same tag name in C as on the wire to get rid of
- # it, then: c_name=c_name(variants.tag_member.name)
- c_name='kind',
+ c_name=c_name(variants.tag_member.name),
name=variants.tag_member.name)
ret += gen_err_check(label='out_obj')
ret += mcgen('''
- if (!visit_start_union(v, !!(*obj)->data, &err) || err) {
+ if (!visit_start_union(v, !!(*obj)->u.data, &err) || err) {
goto out_obj;
}
switch ((*obj)->%(c_name)s) {
''',
- # TODO ugly special case for simple union
- # Use same tag name in C as on the wire to get rid of
- # it, then: c_name=c_name(variants.tag_member.name)
- c_name=c_name(variants.tag_name or 'kind'))
+ c_name=c_name(variants.tag_member.name))
for var in variants.variants:
# TODO ugly special case for simple union
@@ -288,13 +282,13 @@ void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj,
const char *name, Error
var.name))
if simple_union_type:
ret += mcgen('''
- visit_type_%(c_type)s(v, &(*obj)->%(c_name)s, "data", &err);
+ visit_type_%(c_type)s(v, &(*obj)->u.%(c_name)s, "data", &err);
''',
c_type=simple_union_type.c_name(),
c_name=c_name(var.name))
else:
ret += mcgen('''
- visit_type_implicit_%(c_type)s(v, &(*obj)->%(c_name)s, &err);
+ visit_type_implicit_%(c_type)s(v, &(*obj)->u.%(c_name)s, &err);
''',
c_type=var.type.c_name(),
c_name=c_name(var.name))
@@ -310,7 +304,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;
--
2.4.3
- [Qemu-devel] [PATCH v11 00/24] qapi collision reduction (post-introspection subset B'), Eric Blake, 2015/10/26
- [Qemu-devel] [PATCH v11 04/24] qapi: Reserve '*List' type names for list types, Eric Blake, 2015/10/26
- [Qemu-devel] [PATCH v11 07/24] qapi-visit: Split off visit_type_FOO_fields forward decl, Eric Blake, 2015/10/26
- [Qemu-devel] [PATCH v11 01/24] tests/qapi-schema: Test for reserved names, empty struct, Eric Blake, 2015/10/26
- [Qemu-devel] [PATCH v11 05/24] qapi: Reserve 'q_*' and 'has_*' member names, Eric Blake, 2015/10/26
- [Qemu-devel] [PATCH v11 11/24] qapi-visit: Remove redundant functions for flat union base, Eric Blake, 2015/10/26
- [Qemu-devel] [PATCH v11 12/24] qapi: Start converting to new qapi union layout, Eric Blake, 2015/10/26
- [Qemu-devel] [PATCH v11 13/24] qapi-visit: Convert to new qapi union layout,
Eric Blake <=
- [Qemu-devel] [PATCH v11 10/24] qapi: Unbox base members, Eric Blake, 2015/10/26
- [Qemu-devel] [PATCH v11 14/24] tests: Convert to new qapi union layout, Eric Blake, 2015/10/26
- [Qemu-devel] [PATCH v11 08/24] qapi-types: Refactor base fields output, Eric Blake, 2015/10/26
- [Qemu-devel] [PATCH v11 09/24] qapi: Prefer typesafe upcasts to qapi base classes, Eric Blake, 2015/10/26
- [Qemu-devel] [PATCH v11 24/24] qapi: Simplify gen_struct_field(), Eric Blake, 2015/10/26