diff mbox

[v8.5,3/4] qapi: Fix check for variant tag values collision

Message ID 1446504092-29008-4-git-send-email-eblake@redhat.com
State New
Headers show

Commit Message

Eric Blake Nov. 2, 2015, 10:41 p.m. UTC
Now that commit e4ba22b3 has separated the C representation of
qapi unions so that tag values no longer collide with non-variant
members, we must adjust QAPISchemaObjectTypeVariant.check() to
match.  The fix is conceptually simple - track a separate
dictionary of tag names we have seen so far, different from the
dictionary of non-variant names.  And while the non-variant seen
array gets reset for each new variant (because the JSON object
does not have collisions between separate branches), the map of
tag names is not reset.

Signed-off-by: Eric Blake <eblake@redhat.com>

---
v9: new patch, split off from v8 7/17
---
 scripts/qapi.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
diff mbox

Patch

diff --git a/scripts/qapi.py b/scripts/qapi.py
index 3cf051f..10bf16f 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -1055,10 +1055,11 @@  class QAPISchemaObjectTypeVariants(object):
         else:                # simple union or alternate
             assert self.tag_member in seen.itervalues()
         assert isinstance(self.tag_member.type, QAPISchemaEnumType)
+        cases = {}
         for v in self.variants:
             # Reset seen array for each variant, since QMP names from one
             # branch do not affect another branch
-            v.check(schema, self.tag_member.type, dict(seen), union)
+            v.check(schema, self.tag_member.type, dict(seen), cases, union)


 class QAPISchemaObjectTypeVariant(QAPISchemaObjectTypeMember):
@@ -1066,8 +1067,8 @@  class QAPISchemaObjectTypeVariant(QAPISchemaObjectTypeMember):
         QAPISchemaObjectTypeMember.__init__(self, name, typ, False)

     # TODO drop 'union' param once tag_type is sufficient to spot alternates
-    def check(self, schema, tag_type, seen, union):
-        QAPISchemaObjectTypeMember.check(self, schema, dict(seen))
+    def check(self, schema, tag_type, seen, cases, union):
+        QAPISchemaObjectTypeMember.check(self, schema, cases)
         assert self.name in tag_type.values
         if union:
             # If this variant is used within a union, then each member