diff options
author | Markus Armbruster <armbru@redhat.com> | 2015-07-31 10:30:04 +0200 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2015-09-04 15:47:13 +0200 |
commit | 0f61af3eb396ae163cd1572ce12e05f5d08d7c15 (patch) | |
tree | 6bf37b6d51adf1446d7cd4f1f22beb061e380f5a /scripts | |
parent | 5aa05d3f72e556752167f7005d6a3dea0f4432c5 (diff) |
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>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/qapi-types.py | 3 | ||||
-rw-r--r-- | scripts/qapi-visit.py | 7 |
2 files changed, 7 insertions, 3 deletions
diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index 4902440ce3..ac8dad3171 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -200,11 +200,12 @@ def generate_union(expr, meta): ret = mcgen(''' struct %(name)s { - %(discriminator_type_name)s kind; + %(discriminator_type_name)s %(discriminator)s; union { void *data; ''', name=name, + discriminator=c_name(discriminator or 'kind'), discriminator_type_name=c_name(discriminator_type_name)) for key in typeinfo: diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py index e8ee2688e6..4ec79a6db8 100644 --- a/scripts/qapi-visit.py +++ b/scripts/qapi-visit.py @@ -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: |