From 44bd1276a7dea747c41f250cb71ab65965343a7f Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Mon, 4 May 2015 09:05:08 -0600 Subject: qapi: Tighten checking of unions Previous commits demonstrated that the generator had several flaws with less-than-perfect unions: - a simple union that listed the same branch twice (or two variant names that map to the same C enumerator, including the implicit MAX sentinel) ended up generating invalid C code - an anonymous union that listed two branches with the same qtype ended up generating invalid C code - the generator crashed on anonymous union attempts to use an array type - the generator was silently ignoring a base type for anonymous unions - the generator allowed unknown types or nested anonymous unions as a branch in an anonymous union Signed-off-by: Eric Blake Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- scripts/qapi-types.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) (limited to 'scripts/qapi-types.py') diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index f6fb930279..2390887f28 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -181,17 +181,8 @@ const int %(name)s_qtypes[QTYPE_MAX] = { name=name) for key in members: - qapi_type = members[key] - if builtin_types.has_key(qapi_type): - qtype = builtin_types[qapi_type] - elif find_struct(qapi_type): - qtype = "QTYPE_QDICT" - elif find_union(qapi_type): - qtype = "QTYPE_QDICT" - elif find_enum(qapi_type): - qtype = "QTYPE_QSTRING" - else: - assert False, "Invalid anonymous union member" + qtype = find_anonymous_member_qtype(members[key]) + assert qtype, "Invalid anonymous union member" ret += mcgen(''' [ %(qtype)s ] = %(abbrev)s_KIND_%(enum)s, -- cgit v1.2.3