diff mbox series

[RFC,15/32] tests/qapi-schema: Improve simple union coverage

Message ID 20171002152552.27999-16-armbru@redhat.com
State New
Headers show
Series Command line QAPIfication | expand

Commit Message

Markus Armbruster Oct. 2, 2017, 3:25 p.m. UTC
This demonstrates a bug in the lowering of simple unions: if more than
one schema uses the same built-in type T for a simple union member,
they all generate the same q_obj_T_wrapper into their qapi-types.h.
They clash when you include more than one schema's qapi-types.h.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 tests/qapi-schema/qapi-schema-test.json |  6 ++++++
 tests/qapi-schema/qapi-schema-test.out  | 10 ++++++++++
 2 files changed, 16 insertions(+)

Comments

Marc-André Lureau Oct. 4, 2017, 12:02 p.m. UTC | #1
On Mon, Oct 2, 2017 at 5:25 PM, Markus Armbruster <armbru@redhat.com> wrote:
> This demonstrates a bug in the lowering of simple unions: if more than
> one schema uses the same built-in type T for a simple union member,
> they all generate the same q_obj_T_wrapper into their qapi-types.h.
> They clash when you include more than one schema's qapi-types.h.

Ah, I don't remember seeing that when I splitted the schema in my
qapi-if / conditional series.

Could it happen with non-built-in types ?

> Signed-off-by: Markus Armbruster <armbru@redhat.com>

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>


> ---
>  tests/qapi-schema/qapi-schema-test.json |  6 ++++++
>  tests/qapi-schema/qapi-schema-test.out  | 10 ++++++++++
>  2 files changed, 16 insertions(+)
>
> diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qapi-schema-test.json
> index c72dbd8050..c091626635 100644
> --- a/tests/qapi-schema/qapi-schema-test.json
> +++ b/tests/qapi-schema/qapi-schema-test.json
> @@ -82,6 +82,12 @@
>    'base': 'UserDefZero',
>    'data': { 'string': 'str', 'enum1': 'EnumOne' } }
>
> +{ 'union': 'UserDefSimpleUnion',
> +  'data': { 'value1': 'UserDefA',
> +# FIXME generated q_obj_int_wrapper clashes with qapi-schema.json's
> +#           'value2': 'int',
> +            'value3': 'UserDefB' } }
> +
>  # this variant of UserDefFlatUnion defaults to a union that uses members with
>  # allocated types to test corner cases in the cleanup/dealloc visitor
>  { 'union': 'UserDefFlatUnion2',
> diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qapi-schema-test.out
> index 4b42db23b2..97bb02f2fd 100644
> --- a/tests/qapi-schema/qapi-schema-test.out
> +++ b/tests/qapi-schema/qapi-schema-test.out
> @@ -108,6 +108,12 @@ object UserDefOptions
>      member u16: uint16List optional=True
>      member i64x: int optional=True
>      member u64x: uint64 optional=True
> +object UserDefSimpleUnion
> +    member type: UserDefSimpleUnionKind optional=False
> +    tag type
> +    case value1: q_obj_UserDefA-wrapper
> +    case value3: q_obj_UserDefB-wrapper
> +enum UserDefSimpleUnionKind ['value1', 'value3']
>  object UserDefTwo
>      member string0: str optional=False
>      member dict1: UserDefTwoDict optional=False
> @@ -169,6 +175,10 @@ object q_obj_EVENT_D-arg
>      member b: str optional=False
>      member c: str optional=True
>      member enum3: EnumOne optional=True
> +object q_obj_UserDefA-wrapper
> +    member data: UserDefA optional=False
> +object q_obj_UserDefB-wrapper
> +    member data: UserDefB optional=False
>  object q_obj_UserDefFlatUnion2-base
>      member integer: int optional=True
>      member string: str optional=False
> --
> 2.13.6
>
>
Markus Armbruster Oct. 5, 2017, 4:29 a.m. UTC | #2
Marc-André Lureau <marcandre.lureau@gmail.com> writes:

> On Mon, Oct 2, 2017 at 5:25 PM, Markus Armbruster <armbru@redhat.com> wrote:
>> This demonstrates a bug in the lowering of simple unions: if more than
>> one schema uses the same built-in type T for a simple union member,
>> they all generate the same q_obj_T_wrapper into their qapi-types.h.
>> They clash when you include more than one schema's qapi-types.h.
>
> Ah, I don't remember seeing that when I splitted the schema in my
> qapi-if / conditional series.

Simple union members of built-in type are rare.  I spotted the problem
with options, then realized it's already possible with simple unions.

> Could it happen with non-built-in types ?

Yes, but multiple q_obj_T_wrapper can clash only when their T also
clash.  Name your types more wisely then.

>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>
> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

Thanks!
diff mbox series

Patch

diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qapi-schema-test.json
index c72dbd8050..c091626635 100644
--- a/tests/qapi-schema/qapi-schema-test.json
+++ b/tests/qapi-schema/qapi-schema-test.json
@@ -82,6 +82,12 @@ 
   'base': 'UserDefZero',
   'data': { 'string': 'str', 'enum1': 'EnumOne' } }
 
+{ 'union': 'UserDefSimpleUnion',
+  'data': { 'value1': 'UserDefA',
+# FIXME generated q_obj_int_wrapper clashes with qapi-schema.json's
+#           'value2': 'int',
+            'value3': 'UserDefB' } }
+
 # this variant of UserDefFlatUnion defaults to a union that uses members with
 # allocated types to test corner cases in the cleanup/dealloc visitor
 { 'union': 'UserDefFlatUnion2',
diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qapi-schema-test.out
index 4b42db23b2..97bb02f2fd 100644
--- a/tests/qapi-schema/qapi-schema-test.out
+++ b/tests/qapi-schema/qapi-schema-test.out
@@ -108,6 +108,12 @@  object UserDefOptions
     member u16: uint16List optional=True
     member i64x: int optional=True
     member u64x: uint64 optional=True
+object UserDefSimpleUnion
+    member type: UserDefSimpleUnionKind optional=False
+    tag type
+    case value1: q_obj_UserDefA-wrapper
+    case value3: q_obj_UserDefB-wrapper
+enum UserDefSimpleUnionKind ['value1', 'value3']
 object UserDefTwo
     member string0: str optional=False
     member dict1: UserDefTwoDict optional=False
@@ -169,6 +175,10 @@  object q_obj_EVENT_D-arg
     member b: str optional=False
     member c: str optional=True
     member enum3: EnumOne optional=True
+object q_obj_UserDefA-wrapper
+    member data: UserDefA optional=False
+object q_obj_UserDefB-wrapper
+    member data: UserDefB optional=False
 object q_obj_UserDefFlatUnion2-base
     member integer: int optional=True
     member string: str optional=False