mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-27 12:23:53 -06:00
qapi: Fix generated code when flat union has member 'kind'
A flat union's tag member gets renamed to 'kind' in the generated code. Breaks when another member named 'kind' exists. Example, adapted from qapi-schema-test.json: { 'struct': 'UserDefUnionBase', 'data': { 'kind': 'str', 'enum1': 'EnumOne' } } We generate: struct UserDefFlatUnion { EnumOne kind; union { void *data; UserDefA *value1; UserDefB *value2; UserDefB *value3; }; char *kind; }; Kill the silly rename. Reported-by: Eric Blake <eblake@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
5aa05d3f72
commit
0f61af3eb3
4 changed files with 9 additions and 5 deletions
|
@ -288,20 +288,23 @@ void visit_type_%(name)s(Visitor *m, %(name)s **obj, const char *name, Error **e
|
|||
name=c_name(name))
|
||||
|
||||
if not discriminator:
|
||||
tag = 'kind'
|
||||
disc_key = "type"
|
||||
else:
|
||||
tag = discriminator
|
||||
disc_key = discriminator
|
||||
ret += mcgen('''
|
||||
visit_type_%(disc_type)s(m, &(*obj)->kind, "%(disc_key)s", &err);
|
||||
visit_type_%(disc_type)s(m, &(*obj)->%(c_tag)s, "%(disc_key)s", &err);
|
||||
if (err) {
|
||||
goto out_obj;
|
||||
}
|
||||
if (!visit_start_union(m, !!(*obj)->data, &err) || err) {
|
||||
goto out_obj;
|
||||
}
|
||||
switch ((*obj)->kind) {
|
||||
switch ((*obj)->%(c_tag)s) {
|
||||
''',
|
||||
disc_type = disc_type,
|
||||
c_tag=c_name(tag),
|
||||
disc_key = disc_key)
|
||||
|
||||
for key in members:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue