All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, berto@igalia.co, armbru@redhat.com
Subject: [Qemu-devel] [PATCH v6 35/36] qapi: Drop support for inline nested types
Date: Sat,  4 Apr 2015 22:08:06 -0600	[thread overview]
Message-ID: <1428206887-7921-36-git-send-email-eblake@redhat.com> (raw)
In-Reply-To: <1428206887-7921-1-git-send-email-eblake@redhat.com>

A future patch will be using a 'name':{dictionary} entry in the
QAPI schema to specify a default value for an optional argument
(see previous commit messages for more details why); but existing
use of inline nested structs conflicts with that goal. Now that
all commands have been changed to avoid inline nested structs,
nuke support for them, and turn it into a hard error. Update the
testsuite to reflect tighter parsing rules.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>

---

v6: rebase onto earlier changes
---
 scripts/qapi-commands.py                     |  8 +++---
 scripts/qapi-event.py                        |  4 +--
 scripts/qapi-types.py                        |  9 ++-----
 scripts/qapi-visit.py                        | 37 ++++------------------------
 scripts/qapi.py                              | 20 ++++++---------
 tests/qapi-schema/event-nest-struct.err      |  2 +-
 tests/qapi-schema/nested-struct-data.err     |  1 +
 tests/qapi-schema/nested-struct-data.exit    |  2 +-
 tests/qapi-schema/nested-struct-data.json    |  2 +-
 tests/qapi-schema/nested-struct-data.out     |  3 ---
 tests/qapi-schema/nested-struct-returns.err  |  1 +
 tests/qapi-schema/nested-struct-returns.exit |  2 +-
 tests/qapi-schema/nested-struct-returns.json |  2 +-
 tests/qapi-schema/nested-struct-returns.out  |  3 ---
 14 files changed, 27 insertions(+), 69 deletions(-)

diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py
index 053ba85..db81044 100644
--- a/scripts/qapi-commands.py
+++ b/scripts/qapi-commands.py
@@ -28,7 +28,7 @@ def type_visitor(name):

 def generate_command_decl(name, args, ret_type):
     arglist=""
-    for argname, argtype, optional, structured in parse_args(args):
+    for argname, argtype, optional in parse_args(args):
         argtype = c_type(argtype, is_param=True)
         if optional:
             arglist += "bool has_%s, " % c_var(argname)
@@ -53,7 +53,7 @@ def gen_sync_call(name, args, ret_type, indent=0):
     retval=""
     if ret_type:
         retval = "retval = "
-    for argname, argtype, optional, structured in parse_args(args):
+    for argname, argtype, optional in parse_args(args):
         if optional:
             arglist += "has_%s, " % c_var(argname)
         arglist += "%s, " % (c_var(argname))
@@ -96,7 +96,7 @@ Visitor *v;
 def gen_visitor_input_vars_decl(args):
     ret = ""
     push_indent()
-    for argname, argtype, optional, structured in parse_args(args):
+    for argname, argtype, optional in parse_args(args):
         if optional:
             ret += mcgen('''
 bool has_%(argname)s = false;
@@ -139,7 +139,7 @@ v = qapi_dealloc_get_visitor(md);
 v = qmp_input_get_visitor(mi);
 ''')

-    for argname, argtype, optional, structured in parse_args(args):
+    for argname, argtype, optional in parse_args(args):
         if optional:
             ret += mcgen('''
 visit_optional(v, &has_%(c_name)s, "%(name)s", %(errp)s);
diff --git a/scripts/qapi-event.py b/scripts/qapi-event.py
index 601e307..47dc041 100644
--- a/scripts/qapi-event.py
+++ b/scripts/qapi-event.py
@@ -21,7 +21,7 @@ def _generate_event_api_name(event_name, params):
     l = len(api_name)

     if params:
-        for argname, argentry, optional, structured in parse_args(params):
+        for argname, argentry, optional in parse_args(params):
             if optional:
                 api_name += "bool has_%s,\n" % c_var(argname)
                 api_name += "".ljust(l)
@@ -93,7 +93,7 @@ def generate_event_implement(api_name, event_name, params):
 """,
                 event_name = event_name)

-        for argname, argentry, optional, structured in parse_args(params):
+        for argname, argentry, optional in parse_args(params):
             if optional:
                 ret += mcgen("""
     if (has_%(var)s) {
diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
index a429d9e..2bf8145 100644
--- a/scripts/qapi-types.py
+++ b/scripts/qapi-types.py
@@ -63,18 +63,13 @@ typedef struct %(name)sList
 def generate_struct_fields(members):
     ret = ''

-    for argname, argentry, optional, structured in parse_args(members):
+    for argname, argentry, optional in parse_args(members):
         if optional:
             ret += mcgen('''
     bool has_%(c_name)s;
 ''',
                          c_name=c_var(argname))
-        if structured:
-            push_indent()
-            ret += generate_struct({ "field": argname, "data": argentry})
-            pop_indent()
-        else:
-            ret += mcgen('''
+        ret += mcgen('''
     %(c_type)s %(c_name)s;
 ''',
                      c_type=c_type(argentry), c_name=c_var(argname))
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index eeeca82..f5d4355 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -51,27 +51,6 @@ def generate_visit_struct_fields(name, field_prefix, fn_prefix, members, base =
     else:
         full_name = "%s_%s" % (name, fn_prefix)

-    for argname, argentry, optional, structured in parse_args(members):
-        if structured:
-            if not fn_prefix:
-                nested_fn_prefix = argname
-            else:
-                nested_fn_prefix = "%s_%s" % (fn_prefix, argname)
-
-            nested_field_prefix = "%s%s." % (field_prefix, argname)
-            ret += generate_visit_struct_fields(name, nested_field_prefix,
-                                                nested_fn_prefix, argentry)
-            ret += mcgen('''
-
-static void visit_type_%(full_name)s_field_%(c_name)s(Visitor *m, %(name)s **obj, Error **errp)
-{
-''',
-                         name=name, full_name=full_name, c_name=c_var(argname))
-            ret += generate_visit_struct_body(full_name, argname, argentry)
-            ret += mcgen('''
-}
-''')
-
     if base:
         ret += generate_visit_implicit_struct(base)

@@ -94,7 +73,7 @@ if (err) {
                      c_prefix=c_var(field_prefix),
                      type=type_name(base), c_name=c_var('base'))

-    for argname, argentry, optional, structured in parse_args(members):
+    for argname, argentry, optional in parse_args(members):
         if optional:
             ret += mcgen('''
 visit_optional(m, &(*obj)->%(c_prefix)shas_%(c_name)s, "%(name)s", &err);
@@ -104,18 +83,12 @@ if (!err && (*obj)->%(prefix)shas_%(c_name)s) {
                          c_name=c_var(argname), name=argname)
             push_indent()

-        if structured:
-            ret += mcgen('''
-visit_type_%(full_name)s_field_%(c_name)s(m, obj, &err);
-''',
-                         full_name=full_name, c_name=c_var(argname))
-        else:
-            ret += mcgen('''
+        ret += mcgen('''
 visit_type_%(type)s(m, &(*obj)->%(c_prefix)s%(c_name)s, "%(name)s", &err);
 ''',
-                         c_prefix=c_var(field_prefix), prefix=field_prefix,
-                         type=type_name(argentry), c_name=c_var(argname),
-                         name=argname)
+                     c_prefix=c_var(field_prefix), prefix=field_prefix,
+                     type=type_name(argentry), c_name=c_var(argname),
+                     name=argname)

         if optional:
             pop_indent()
diff --git a/scripts/qapi.py b/scripts/qapi.py
index effba38..9fd9b96 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -373,10 +373,12 @@ def check_type(expr_info, source, value, allow_array = False,
     for (key, arg) in value.items():
         check_name(expr_info, "Member of %s" % source, key,
                    allow_optional=allow_optional)
+        # Todo: allow dictionaries to represent default values of
+        # an optional argument.
         check_type(expr_info, "Member '%s' of %s" % (key, source), arg,
-                   allow_array=True, allow_dict=True, allow_optional=True,
+                   allow_array=True, allow_star=allow_star,
                    allow_metas=['built-in', 'union', 'alternate', 'struct',
-                                'enum'], allow_star=allow_star)
+                                'enum'])

 def check_command(expr, expr_info):
     name = expr['command']
@@ -404,13 +406,6 @@ def check_event(expr, expr_info):
     check_type(expr_info, "'data' for event '%s'" % name,
                expr.get('data'), allow_dict=True, allow_optional=True,
                allow_metas=['union', 'struct'])
-    if params:
-        for argname, argentry, optional, structured in parse_args(params):
-            if structured:
-                raise QAPIExprError(expr_info,
-                                    "Nested structure define in event is not "
-                                    "supported, event '%s', argname '%s'"
-                                    % (expr['event'], argname))

 def check_union(expr, expr_info):
     name = expr['union']
@@ -671,13 +666,12 @@ def parse_args(typeinfo):
         argname = member
         argentry = typeinfo[member]
         optional = False
-        structured = False
         if member.startswith('*'):
             argname = member[1:]
             optional = True
-        if isinstance(argentry, OrderedDict):
-            structured = True
-        yield (argname, argentry, optional, structured)
+        # Todo: allow argentry to be OrderedDict, for providing the
+        # value of an optional argument.
+        yield (argname, argentry, optional)

 def de_camel_case(name):
     new_name = ''
diff --git a/tests/qapi-schema/event-nest-struct.err b/tests/qapi-schema/event-nest-struct.err
index 91bde1c..5a42701 100644
--- a/tests/qapi-schema/event-nest-struct.err
+++ b/tests/qapi-schema/event-nest-struct.err
@@ -1 +1 @@
-tests/qapi-schema/event-nest-struct.json:1: Nested structure define in event is not supported, event 'EVENT_A', argname 'a'
+tests/qapi-schema/event-nest-struct.json:1: Member 'a' of 'data' for event 'EVENT_A' should be a type name
diff --git a/tests/qapi-schema/nested-struct-data.err b/tests/qapi-schema/nested-struct-data.err
index e69de29..da767ba 100644
--- a/tests/qapi-schema/nested-struct-data.err
+++ b/tests/qapi-schema/nested-struct-data.err
@@ -0,0 +1 @@
+tests/qapi-schema/nested-struct-data.json:2: Member 'a' of 'data' for command 'foo' should be a type name
diff --git a/tests/qapi-schema/nested-struct-data.exit b/tests/qapi-schema/nested-struct-data.exit
index 573541a..d00491f 100644
--- a/tests/qapi-schema/nested-struct-data.exit
+++ b/tests/qapi-schema/nested-struct-data.exit
@@ -1 +1 @@
-0
+1
diff --git a/tests/qapi-schema/nested-struct-data.json b/tests/qapi-schema/nested-struct-data.json
index 0247c8c..3d52d2b 100644
--- a/tests/qapi-schema/nested-struct-data.json
+++ b/tests/qapi-schema/nested-struct-data.json
@@ -1,4 +1,4 @@
-# FIXME: inline subtypes collide with our desired future use of defaults
+# inline subtypes collide with our desired future use of defaults
 { 'command': 'foo',
   'data': { 'a' : { 'string' : 'str', 'integer': 'int' }, 'b' : 'str' },
   'returns': {} }
diff --git a/tests/qapi-schema/nested-struct-data.out b/tests/qapi-schema/nested-struct-data.out
index 999cbb8..e69de29 100644
--- a/tests/qapi-schema/nested-struct-data.out
+++ b/tests/qapi-schema/nested-struct-data.out
@@ -1,3 +0,0 @@
-[OrderedDict([('command', 'foo'), ('data', OrderedDict([('a', OrderedDict([('string', 'str'), ('integer', 'int')])), ('b', 'str')])), ('returns', OrderedDict())])]
-[]
-[]
diff --git a/tests/qapi-schema/nested-struct-returns.err b/tests/qapi-schema/nested-struct-returns.err
index e69de29..5238d07 100644
--- a/tests/qapi-schema/nested-struct-returns.err
+++ b/tests/qapi-schema/nested-struct-returns.err
@@ -0,0 +1 @@
+tests/qapi-schema/nested-struct-returns.json:2: Member 'a' of 'returns' for command 'foo' should be a type name
diff --git a/tests/qapi-schema/nested-struct-returns.exit b/tests/qapi-schema/nested-struct-returns.exit
index 573541a..d00491f 100644
--- a/tests/qapi-schema/nested-struct-returns.exit
+++ b/tests/qapi-schema/nested-struct-returns.exit
@@ -1 +1 @@
-0
+1
diff --git a/tests/qapi-schema/nested-struct-returns.json b/tests/qapi-schema/nested-struct-returns.json
index 5a46840..d2cd047 100644
--- a/tests/qapi-schema/nested-struct-returns.json
+++ b/tests/qapi-schema/nested-struct-returns.json
@@ -1,3 +1,3 @@
-# FIXME: inline subtypes collide with our desired future use of defaults
+# inline subtypes collide with our desired future use of defaults
 { 'command': 'foo',
   'returns': { 'a' : { 'string' : 'str', 'integer': 'int' }, 'b' : 'str' } }
diff --git a/tests/qapi-schema/nested-struct-returns.out b/tests/qapi-schema/nested-struct-returns.out
index c53d23b..e69de29 100644
--- a/tests/qapi-schema/nested-struct-returns.out
+++ b/tests/qapi-schema/nested-struct-returns.out
@@ -1,3 +0,0 @@
-[OrderedDict([('command', 'foo'), ('returns', OrderedDict([('a', OrderedDict([('string', 'str'), ('integer', 'int')])), ('b', 'str')]))])]
-[]
-[]
-- 
2.1.0

  parent reply	other threads:[~2015-04-05  4:08 UTC|newest]

Thread overview: 72+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-05  4:07 [Qemu-devel] [PATCH v6 00/36] drop qapi nested structs Eric Blake
2015-04-05  4:07 ` [Qemu-devel] [PATCH v6 01/36] qapi: Add copyright declaration on docs Eric Blake
2015-04-27 14:42   ` Markus Armbruster
2015-04-05  4:07 ` [Qemu-devel] [PATCH v6 02/36] qapi: Document type-safety considerations Eric Blake
2015-04-08 16:50   ` Eric Blake
2015-04-27 15:42   ` Markus Armbruster
2015-04-28 19:42   ` Eric Blake
2015-04-05  4:07 ` [Qemu-devel] [PATCH v6 03/36] qapi: Simplify builtin type handling Eric Blake
2015-04-05  4:07 ` [Qemu-devel] [PATCH v6 04/36] qapi: Fix generation of 'size' builtin type Eric Blake
2015-04-05  4:07 ` [Qemu-devel] [PATCH v6 05/36] qapi: Require ASCII in schema Eric Blake
2015-04-05  4:07 ` [Qemu-devel] [PATCH v6 06/36] qapi: Add some enum tests Eric Blake
2015-04-27 16:00   ` Markus Armbruster
2015-04-05  4:07 ` [Qemu-devel] [PATCH v6 07/36] qapi: Better error messages for bad enums Eric Blake
2015-04-28 23:08   ` Eric Blake
2015-04-05  4:07 ` [Qemu-devel] [PATCH v6 08/36] qapi: Add some union tests Eric Blake
2015-04-27 16:18   ` Markus Armbruster
2015-04-05  4:07 ` [Qemu-devel] [PATCH v6 09/36] qapi: Clean up test coverage of simple unions Eric Blake
2015-04-05  4:07 ` [Qemu-devel] [PATCH v6 10/36] qapi: Forbid base without discriminator in unions Eric Blake
2015-04-27 17:36   ` Markus Armbruster
2015-04-05  4:07 ` [Qemu-devel] [PATCH v6 11/36] qapi: Tighten checking of unions Eric Blake
2015-04-27 18:15   ` Markus Armbruster
2015-04-27 18:32     ` Eric Blake
2015-04-29  2:51       ` Eric Blake
2015-04-05  4:07 ` [Qemu-devel] [PATCH v6 12/36] qapi: Prepare for catching more semantic parse errors Eric Blake
2015-04-05  4:07 ` [Qemu-devel] [PATCH v6 13/36] qapi: Segregate anonymous unions into alternates in generator Eric Blake
2015-04-05  4:07 ` [Qemu-devel] [PATCH v6 14/36] qapi: Rename anonymous union type in test Eric Blake
2015-04-05  4:07 ` [Qemu-devel] [PATCH v6 15/36] qapi: Document new 'alternate' meta-type Eric Blake
2015-04-28  8:27   ` Markus Armbruster
2015-04-05  4:07 ` [Qemu-devel] [PATCH v6 16/36] qapi: Use 'alternate' to replace anonymous union Eric Blake
2015-04-28  8:41   ` Markus Armbruster
2015-04-28 17:29     ` Eric Blake
2015-04-05  4:07 ` [Qemu-devel] [PATCH v6 17/36] qapi: Add some expr tests Eric Blake
2015-04-28 11:01   ` Markus Armbruster
2015-04-05  4:07 ` [Qemu-devel] [PATCH v6 18/36] qapi: Better error messages for bad expressions Eric Blake
2015-04-05  4:07 ` [Qemu-devel] [PATCH v6 19/36] qapi: Add tests of redefined expressions Eric Blake
2015-04-05  4:07 ` [Qemu-devel] [PATCH v6 20/36] qapi: Better error messages for duplicated expressions Eric Blake
2015-04-05  4:07 ` [Qemu-devel] [PATCH v6 21/36] qapi: Allow true, false and null in schema json Eric Blake
2015-04-05  4:07 ` [Qemu-devel] [PATCH v6 22/36] qapi: Unify type bypass and add tests Eric Blake
2015-04-05  4:07 ` [Qemu-devel] [PATCH v6 23/36] qapi: Add some type check tests Eric Blake
2015-04-05  4:07 ` [Qemu-devel] [PATCH v6 24/36] qapi: More rigourous checking of types Eric Blake
2015-04-28 11:30   ` Markus Armbruster
2015-04-05  4:07 ` [Qemu-devel] [PATCH v6 25/36] qapi: Require valid names Eric Blake
2015-04-28 11:46   ` Markus Armbruster
2015-04-05  4:07 ` [Qemu-devel] [PATCH v6 26/36] qapi: Whitelist commands that don't return dictionary Eric Blake
2015-04-05  4:07 ` [Qemu-devel] [PATCH v6 27/36] qapi: More rigorous checking for type safety bypass Eric Blake
2015-04-27 17:02   ` Eric Blake
2015-04-05  4:07 ` [Qemu-devel] [PATCH v6 28/36] qapi: Prefer 'struct' over 'type' in generator Eric Blake
2015-04-28 12:04   ` Markus Armbruster
2015-04-05  4:08 ` [Qemu-devel] [PATCH v6 29/36] qapi: Document 'struct' metatype Eric Blake
2015-04-28 12:12   ` Markus Armbruster
2015-04-05  4:08 ` [Qemu-devel] [PATCH v6 30/36] qapi: Use 'struct' instead of 'type' in schema Eric Blake
2015-04-28 12:23   ` Markus Armbruster
2015-04-05  4:08 ` [Qemu-devel] [PATCH v6 31/36] qapi: Merge UserDefTwo and UserDefNested in tests Eric Blake
2015-04-28 12:28   ` Markus Armbruster
2015-04-05  4:08 ` [Qemu-devel] [PATCH v6 32/36] qapi: Drop tests for inline nested structs Eric Blake
2015-04-28 13:00   ` Markus Armbruster
2015-04-28 17:29     ` Eric Blake
2015-04-05  4:08 ` [Qemu-devel] [PATCH v6 33/36] qapi: Drop inline nested struct in query-version Eric Blake
2015-04-05  4:08 ` [Qemu-devel] [PATCH v6 34/36] qapi: Drop inline nested structs in query-pci Eric Blake
2015-04-05  4:08 ` Eric Blake [this message]
2015-04-05  4:08 ` [Qemu-devel] [PATCH v6 36/36] qapi: Tweak doc references to QMP when QGA is also meant Eric Blake
2015-04-06 13:13 ` [Qemu-devel] [PATCH v6 00/36] drop qapi nested structs Eric Blake
2015-04-08  7:35   ` Alberto Garcia
2015-04-10 20:28 ` [Qemu-devel] [PATCH v6 37/36] qapi: Support (subset of) \u escapes in strings Eric Blake
2015-04-28 13:23   ` Markus Armbruster
2015-04-10 20:28 ` [Qemu-devel] [PATCH v6 38/36] qapi: Check for member name conflicts with a base class Eric Blake
2015-04-28 13:35   ` Markus Armbruster
2015-04-28 14:02 ` [Qemu-devel] [PATCH v6 00/36] drop qapi nested structs Markus Armbruster
2015-04-28 17:51   ` Eric Blake
2015-04-29  6:48     ` Markus Armbruster
2015-04-29 12:34       ` Eric Blake
2015-04-29 12:40         ` Luiz Capitulino

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=1428206887-7921-36-git-send-email-eblake@redhat.com \
    --to=eblake@redhat.com \
    --cc=armbru@redhat.com \
    --cc=berto@igalia.co \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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 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.