All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] qapi: Fix crash on redefinition with a different condition
@ 2021-08-06 12:05 Markus Armbruster
  2021-08-06 21:09 ` Eric Blake
  0 siblings, 1 reply; 2+ messages in thread
From: Markus Armbruster @ 2021-08-06 12:05 UTC (permalink / raw)
  To: qemu-devel; +Cc: marcandre.lureau, jsnow

QAPISchema._make_implicit_object_type() asserts that when an implicit
object type is used multiple times, @ifcond is the same for all uses.
It will be for legitimate uses, i.e. simple union branch wrapper
types.  A comment explains this.

The assertion fails when a command or event is redefined with a
different condition.  The redefinition is an error, but it's flagged
only later.

Fixing the assertion would complicate matters further.  Not
worthwhile, drop it instead.  We really need to get rid of simple
unions.

Tweak test case redefined-event to cover redefinition with a different
condition.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 scripts/qapi/schema.py                 | 22 +++++++++++-----------
 tests/qapi-schema/redefined-event.json |  2 +-
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py
index d1d27ff7ee..a4ce3972a4 100644
--- a/scripts/qapi/schema.py
+++ b/scripts/qapi/schema.py
@@ -997,18 +997,18 @@ def _make_implicit_object_type(self, name, info, ifcond, role, members):
         name = 'q_obj_%s-%s' % (name, role)
         typ = self.lookup_entity(name, QAPISchemaObjectType)
         if typ:
-            # The implicit object type has multiple users.  This can
-            # happen only for simple unions' implicit wrapper types.
-            # Its ifcond should be the disjunction of its user's
-            # ifconds.  Not implemented.  Instead, we always pass the
-            # wrapped type's ifcond, which is trivially the same for all
-            # users.  It's also necessary for the wrapper to compile.
-            # But it's not tight: the disjunction need not imply it.  We
-            # may end up compiling useless wrapper types.
+            # The implicit object type has multiple users.  This is
+            # either a duplicate definition (which will be flagged
+            # later), or an implicit wrapper type used for multiple
+            # simple unions.  In the latter case, ifcond should be the
+            # disjunction of its user's ifconds.  Not implemented.
+            # Instead, we always pass the wrapped type's ifcond, which
+            # is trivially the same for all users.  It's also
+            # necessary for the wrapper to compile.  But it's not
+            # tight: the disjunction need not imply it.  We may end up
+            # compiling useless wrapper types.
             # TODO kill simple unions or implement the disjunction
-
-            # pylint: disable=protected-access
-            assert (ifcond or []) == typ._ifcond
+            pass
         else:
             self._def_entity(QAPISchemaObjectType(
                 name, info, None, ifcond, None, None, members, None))
diff --git a/tests/qapi-schema/redefined-event.json b/tests/qapi-schema/redefined-event.json
index 7717e91c18..09eff18412 100644
--- a/tests/qapi-schema/redefined-event.json
+++ b/tests/qapi-schema/redefined-event.json
@@ -1,3 +1,3 @@
 # we reject duplicate events
 { 'event': 'EVENT_A', 'data': { 'myint': 'int' } }
-{ 'event': 'EVENT_A', 'data': { 'myint': 'int' } }
+{ 'event': 'EVENT_A', 'data': { 'myint': 'int' }, 'if': 'defined(FOO)' }
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] qapi: Fix crash on redefinition with a different condition
  2021-08-06 12:05 [PATCH] qapi: Fix crash on redefinition with a different condition Markus Armbruster
@ 2021-08-06 21:09 ` Eric Blake
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Blake @ 2021-08-06 21:09 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: marcandre.lureau, jsnow, qemu-devel

On Fri, Aug 06, 2021 at 02:05:10PM +0200, Markus Armbruster wrote:
> QAPISchema._make_implicit_object_type() asserts that when an implicit
> object type is used multiple times, @ifcond is the same for all uses.
> It will be for legitimate uses, i.e. simple union branch wrapper
> types.  A comment explains this.
> 
> The assertion fails when a command or event is redefined with a
> different condition.  The redefinition is an error, but it's flagged
> only later.
> 
> Fixing the assertion would complicate matters further.  Not
> worthwhile, drop it instead.  We really need to get rid of simple
> unions.
> 
> Tweak test case redefined-event to cover redefinition with a different
> condition.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---

6.2 material (this corner case doesn't fire in our 6.1 code base, and
really only matters for developers adding new interfaces which won't
happen in 6.1).

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

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-08-06 21:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-06 12:05 [PATCH] qapi: Fix crash on redefinition with a different condition Markus Armbruster
2021-08-06 21:09 ` Eric Blake

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.