qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: mdroth@linux.vnet.ibm.com, eblake@redhat.com, quintela@redhat.com
Subject: [Qemu-devel] [PATCH 7/7] qapi: Fix array first used in a different module
Date: Fri,  1 Mar 2019 16:40:51 +0100	[thread overview]
Message-ID: <20190301154051.23317-8-armbru@redhat.com> (raw)
In-Reply-To: <20190301154051.23317-1-armbru@redhat.com>

We generally put implicitly defined types in whatever module triggered
their definition.  This is wrong for array types, as the included test
case demonstrates.  Let's have a closer look at it.

Type 'Status' is defined sub-sub-module.json.  Array type ['Status']
occurs in main module qapi-schema-test.json and in
include/sub-module.json.  The main module's use is first, so the array
type gets put into the main module.

The generated C headers define StatusList in qapi-types.h.  But
include/qapi-types-sub-module.h uses it without including
qapi-types.h.  Oops.

To fix that, put the array type into its element type's module.

Now StatusList gets generated into qapi-types-sub-module.h, which all
its users include.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 scripts/qapi/common.py                    | 9 +++++----
 tests/qapi-schema/include/sub-module.json | 2 ++
 tests/qapi-schema/qapi-schema-test.out    | 5 +++++
 3 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
index f51948364c..f07869ec73 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -1089,6 +1089,9 @@ class QAPISchemaEntity(object):
             self.ifcond = typ.ifcond
         else:
             self.ifcond = listify_cond(self._ifcond)
+        if self.info:
+            self.module = os.path.relpath(self.info['file'],
+                                          os.path.dirname(schema.fname))
 
     def is_implicit(self):
         return not self.info
@@ -1262,6 +1265,7 @@ class QAPISchemaArrayType(QAPISchemaType):
         self.element_type = schema.lookup_type(self._element_type_name)
         assert self.element_type
         self.element_type.check(schema)
+        self.module = self.element_type.module
         self.ifcond = self.element_type.ifcond
 
     def is_implicit(self):
@@ -1603,7 +1607,7 @@ class QAPISchemaEvent(QAPISchemaEntity):
 
 class QAPISchema(object):
     def __init__(self, fname):
-        self._fname = fname
+        self.fname = fname
         if sys.version_info[0] >= 3:
             f = open(fname, 'r', encoding='utf-8')
         else:
@@ -1626,9 +1630,6 @@ class QAPISchema(object):
         self._entity_list.append(ent)
         if ent.name is not None:
             self._entity_dict[ent.name] = ent
-        if ent.info:
-            ent.module = os.path.relpath(ent.info['file'],
-                                         os.path.dirname(self._fname))
 
     def lookup_entity(self, name, typ=None):
         ent = self._entity_dict.get(name)
diff --git a/tests/qapi-schema/include/sub-module.json b/tests/qapi-schema/include/sub-module.json
index f2bdbd3990..afdb267228 100644
--- a/tests/qapi-schema/include/sub-module.json
+++ b/tests/qapi-schema/include/sub-module.json
@@ -3,3 +3,5 @@
 # Sub-module of ../qapi-schema-test.json
 
 { 'include': '../sub-sub-module.json' }
+
+{ 'struct': 'SecondArrayRef', 'data': { 's': ['Status'] } }
diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qapi-schema-test.out
index 38c1de70d8..77fb1e1aa9 100644
--- a/tests/qapi-schema/qapi-schema-test.out
+++ b/tests/qapi-schema/qapi-schema-test.out
@@ -144,7 +144,9 @@ object q_obj_sizeList-wrapper
     member data: sizeList optional=False
 object q_obj_anyList-wrapper
     member data: anyList optional=False
+module sub-sub-module.json
 array StatusList Status
+module qapi-schema-test.json
 object q_obj_StatusList-wrapper
     member data: StatusList optional=False
 enum UserDefListUnionKind
@@ -189,6 +191,9 @@ enum Status
     member good
     member bad
     member ugly
+module include/sub-module.json
+object SecondArrayRef
+    member s: StatusList optional=False
 module qapi-schema-test.json
 command user_def_cmd None -> None
    gen=True success_response=True boxed=False oob=False preconfig=False
-- 
2.17.2

  parent reply	other threads:[~2019-03-01 15:46 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-01 15:40 [Qemu-devel] [PATCH 0/7] qapi: Code generation fixes Markus Armbruster
2019-03-01 15:40 ` [Qemu-devel] [PATCH 1/7] tests/qapi-schema: Make test-qapi.py print arrays Markus Armbruster
2019-03-01 15:45   ` Eric Blake
2019-03-04  8:17     ` Markus Armbruster
2019-03-01 15:40 ` [Qemu-devel] [PATCH 2/7] tests/qapi-schema: Cover conditional arrays Markus Armbruster
2019-03-01 15:46   ` Eric Blake
2019-03-01 15:40 ` [Qemu-devel] [PATCH 3/7] qapi: Pass file name to QAPIGen constructor instead of methods Markus Armbruster
2019-03-01 15:49   ` Eric Blake
2019-03-01 15:40 ` [Qemu-devel] [PATCH 4/7] qapi: Fix code generation for sub-modules in other directories Markus Armbruster
2019-03-01 16:00   ` Eric Blake
2019-03-04  8:26     ` Markus Armbruster
2019-03-01 15:40 ` [Qemu-devel] [PATCH 5/7] tests: Rename UserDefNativeListUnion to UserDefListUnion Markus Armbruster
2019-03-01 16:21   ` Eric Blake
2019-03-01 15:40 ` [Qemu-devel] [PATCH 6/7] tests/qapi-schema: Cover forward reference to sub-module Markus Armbruster
2019-03-01 16:22   ` Eric Blake
2019-03-01 15:40 ` Markus Armbruster [this message]
2019-03-01 16:25   ` [Qemu-devel] [PATCH 7/7] qapi: Fix array first used in a different module Eric Blake

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190301154051.23317-8-armbru@redhat.com \
    --to=armbru@redhat.com \
    --cc=eblake@redhat.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).