]> git.proxmox.com Git - mirror_qemu.git/commitdiff
qapi: Reuse code for flat union base validation
authorEric Blake <eblake@redhat.com>
Tue, 29 Sep 2015 22:21:07 +0000 (16:21 -0600)
committerMarkus Armbruster <armbru@redhat.com>
Mon, 12 Oct 2015 16:46:49 +0000 (18:46 +0200)
Rather than open-code the check for a valid base type, we
should reuse the common functionality. This allows for
consistent error messages, and also makes it easier for a
later patch to turn on support for inline anonymous base
structures.

Test flat-union-inline is updated to test only one feature
(anonymous branch dictionaries), which can be implemented
independently (test flat-union-bad-base already covers the
idea of an anonymous base dictionary).

Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1443565276-4535-10-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
scripts/qapi.py
tests/qapi-schema/flat-union-bad-base.err
tests/qapi-schema/flat-union-base-any.err
tests/qapi-schema/flat-union-base-union.err
tests/qapi-schema/flat-union-inline.err
tests/qapi-schema/flat-union-inline.json
tests/qapi-schema/flat-union-no-base.err
tests/qapi-schema/union-invalid-base.err

index 8d2681b24bb79432da9337de20465fb4468a21b2..c0728d73e12617cd5b87c54ae3b08e8e4c84ad85 100644 (file)
@@ -560,15 +560,14 @@ def check_union(expr, expr_info):
     # Else, it's a flat union.
     else:
         # The object must have a string member 'base'.
-        if not isinstance(base, str):
+        check_type(expr_info, "'base' for union '%s'" % name,
+                   base, allow_metas=['struct'])
+        if not base:
             raise QAPIExprError(expr_info,
-                                "Flat union '%s' must have a string base field"
+                                "Flat union '%s' must have a base"
                                 % name)
         base_fields = find_base_fields(base)
-        if not base_fields:
-            raise QAPIExprError(expr_info,
-                                "Base '%s' is not a valid struct"
-                                % base)
+        assert base_fields
 
         # The value of member 'discriminator' must name a non-optional
         # member of the base struct.
index f9c31b2bf57a91a2cb66a374c1c84e14ce31adc3..79b8a71eb8778a8dd132499da647663ad0e001e8 100644 (file)
@@ -1 +1 @@
-tests/qapi-schema/flat-union-bad-base.json:9: Flat union 'TestUnion' must have a string base field
+tests/qapi-schema/flat-union-bad-base.json:9: 'base' for union 'TestUnion' should be a type name
index ad4d629e75a5277049b2de9795d67d39084a2d4b..646f1c9cd1168ce8beead3e49bee7448699f6178 100644 (file)
@@ -1 +1 @@
-tests/qapi-schema/flat-union-base-any.json:8: Base 'any' is not a valid struct
+tests/qapi-schema/flat-union-base-any.json:8: 'base' for union 'TestUnion' cannot use built-in type 'any'
index 28725ed1e3f292f64e30264c49b3208319a2454d..f138395e456a6f30b6ca9dffd1cd9ea1685dbac0 100644 (file)
@@ -1 +1 @@
-tests/qapi-schema/flat-union-base-union.json:14: Base 'UnionBase' is not a valid struct
+tests/qapi-schema/flat-union-base-union.json:14: 'base' for union 'TestUnion' cannot use union type 'UnionBase'
index ec586277b72b686aa3e0f861b1a2db46e938ab13..2333358d28b7850ddeb1d604d4871e75cecbe2db 100644 (file)
@@ -1 +1 @@
-tests/qapi-schema/flat-union-inline.json:7: Flat union 'TestUnion' must have a string base field
+tests/qapi-schema/flat-union-inline.json:7: Member 'value1' of union 'TestUnion' should be a type name
index 6bfdd65811df9d5b9ca9f7adbd5d4240cf3e05da..62c7cda61750fa72701a3d6b2f626a65d9064d5a 100644 (file)
@@ -1,11 +1,11 @@
 # we require branches to be a struct name
-# TODO: should we allow anonymous inline types?
+# TODO: should we allow anonymous inline branch types?
 { 'enum': 'TestEnum',
   'data': [ 'value1', 'value2' ] }
 { 'struct': 'Base',
   'data': { 'enum1': 'TestEnum', 'kind': 'str' } }
 { 'union': 'TestUnion',
-  'base': { 'enum1': 'TestEnum', 'kind': 'str' },
+  'base': 'Base',
   'discriminator': 'enum1',
   'data': { 'value1': { 'string': 'str' },
             'value2': { 'integer': 'int' } } }
index bb3f70874763fddea29e249f3acb2f4d8ab34fc0..841c93b55443eef661e4fb4e1980a7ee12f4d2b1 100644 (file)
@@ -1 +1 @@
-tests/qapi-schema/flat-union-no-base.json:9: Flat union 'TestUnion' must have a string base field
+tests/qapi-schema/flat-union-no-base.json:9: Flat union 'TestUnion' must have a base
index 9f637963e8f43c8124ce4569bf13be4ff2d88794..03d7b97a93ba94853c8e2a78824f69c8bb25305e 100644 (file)
@@ -1 +1 @@
-tests/qapi-schema/union-invalid-base.json:8: Base 'int' is not a valid struct
+tests/qapi-schema/union-invalid-base.json:8: 'base' for union 'TestUnion' cannot use built-in type 'int'