All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: armbru@redhat.com, Michael Roth <mdroth@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH v8 04/16] qapi: Add type.is_empty() helper
Date: Sat,  2 Jul 2016 20:58:37 -0600	[thread overview]
Message-ID: <1467514729-29366-5-git-send-email-eblake@redhat.com> (raw)
In-Reply-To: <1467514729-29366-1-git-send-email-eblake@redhat.com>

In the near future, we want to lift our artificial restriction of
no variants at the top level of an event, at which point the
currently open-coded check for empty members will become
insufficient.  Factor it out into a new helper method is_empty()
now, and future-proof it by checking variants, too, along with an
assert that it is not used prior to the completion of .check().
Update places that were checking for (non-)empty .members to use
the new helper.

All of the current callers assert that there are no variants (either
directly, or by qapi.py asserting that base types have no variants),
so this is not a semantic change.

No change to generated code.

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

---
v8: commit message tweaks, also fix qapi-commands.py to use it
v7: rebase to latest
[Previously posted as part of "easier unboxed visits/qapi implicit types"]
v2: no change
v1: add some asserts
[Previously posted as part of "qapi cleanup subset E"]
v9: improve commit message
v8: no change
v7: rebase to context change
v6: new patch
---
 scripts/qapi.py          | 4 ++++
 scripts/qapi-commands.py | 6 +++---
 scripts/qapi-event.py    | 6 +++---
 scripts/qapi-types.py    | 2 +-
 4 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/scripts/qapi.py b/scripts/qapi.py
index 47be1c8..a99a74a 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -999,6 +999,10 @@ class QAPISchemaObjectType(QAPISchemaType):
         # _def_predefineds()
         return self.name.startswith('q_')

+    def is_empty(self):
+        assert self.members is not None
+        return not self.members and not self.variants
+
     def c_name(self):
         return QAPISchemaType.c_name(self)

diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py
index 34b6a3a..c93470c 100644
--- a/scripts/qapi-commands.py
+++ b/scripts/qapi-commands.py
@@ -107,7 +107,7 @@ def gen_marshal(name, arg_type, ret_type):
 ''',
                      c_type=ret_type.c_type())

-    if arg_type and arg_type.members:
+    if arg_type and not arg_type.is_empty():
         ret += mcgen('''
     Visitor *v;
     %(c_name)s arg = {0};
@@ -137,7 +137,7 @@ def gen_marshal(name, arg_type, ret_type):
     ret += gen_call(name, arg_type, ret_type)

     # 'goto out' produced above for arg_type, and by gen_call() for ret_type
-    if (arg_type and arg_type.members) or ret_type:
+    if (arg_type and not arg_type.is_empty()) or ret_type:
         ret += mcgen('''

 out:
@@ -145,7 +145,7 @@ out:
     ret += mcgen('''
     error_propagate(errp, err);
 ''')
-    if arg_type and arg_type.members:
+    if arg_type and not arg_type.is_empty():
         ret += mcgen('''
     visit_free(v);
     v = qapi_dealloc_visitor_new();
diff --git a/scripts/qapi-event.py b/scripts/qapi-event.py
index 9c88627..09c0a2a 100644
--- a/scripts/qapi-event.py
+++ b/scripts/qapi-event.py
@@ -69,7 +69,7 @@ def gen_event_send(name, arg_type):
 ''',
                 proto=gen_event_send_proto(name, arg_type))

-    if arg_type and arg_type.members:
+    if arg_type and not arg_type.is_empty():
         ret += mcgen('''
     QObject *obj;
     Visitor *v;
@@ -88,7 +88,7 @@ def gen_event_send(name, arg_type):
 ''',
                  name=name)

-    if arg_type and arg_type.members:
+    if arg_type and not arg_type.is_empty():
         ret += mcgen('''
     v = qmp_output_visitor_new(&obj);

@@ -116,7 +116,7 @@ def gen_event_send(name, arg_type):
 ''',
                  c_enum=c_enum_const(event_enum_name, name))

-    if arg_type and arg_type.members:
+    if arg_type and not arg_type.is_empty():
         ret += mcgen('''
 out:
     visit_free(v);
diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
index 5ace2cf..dabc42e 100644
--- a/scripts/qapi-types.py
+++ b/scripts/qapi-types.py
@@ -91,7 +91,7 @@ struct %(c_name)s {
     # potential issues with attempting to malloc space for zero-length
     # structs in C, and also incompatibility with C++ (where an empty
     # struct is size 1).
-    if not (base and base.members) and not members and not variants:
+    if (not base or base.is_empty()) and not members and not variants:
         ret += mcgen('''
     char qapi_dummy_for_empty_struct;
 ''')
-- 
2.5.5

  parent reply	other threads:[~2016-07-03  2:59 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-03  2:58 [Qemu-devel] [PATCH for-2.7 v8 00/16] qapi netdev_add introspection (post-introspection cleanups subset F) Eric Blake
2016-07-03  2:58 ` [Qemu-devel] [PATCH v8 01/16] net: use Netdev instead of NetClientOptions in client init Eric Blake
2016-07-03  2:58 ` [Qemu-devel] [PATCH v8 02/16] qapi: Require all branches of flat union enum to be covered Eric Blake
2016-07-03  2:58 ` [Qemu-devel] [PATCH v8 03/16] qapi: Hide tag_name data member of variants Eric Blake
2016-07-03  2:58 ` Eric Blake [this message]
2016-07-03  2:58 ` [Qemu-devel] [PATCH v8 05/16] qapi: Drop useless gen_err_check() Eric Blake
2016-07-03  2:58 ` [Qemu-devel] [PATCH v8 06/16] qapi-event: Simplify visit of non-implicit data Eric Blake
2016-07-03  2:58 ` [Qemu-devel] [PATCH v8 07/16] qapi: Plumb in 'box' to qapi generator lower levels Eric Blake
2016-07-03  2:58 ` [Qemu-devel] [PATCH v8 08/16] qapi: Implement boxed types for commands/events Eric Blake
2016-07-07 10:52   ` Markus Armbruster
2016-07-07 16:02     ` Eric Blake
2016-07-08  7:06       ` Markus Armbruster
2016-07-03  2:58 ` [Qemu-devel] [PATCH v8 09/16] block: Simplify block_set_io_throttle Eric Blake
2016-07-03  2:58 ` [Qemu-devel] [PATCH v8 10/16] block: Simplify drive-mirror Eric Blake
2016-07-05 20:27   ` [Qemu-devel] [Qemu-block] " John Snow
2016-07-05 22:16     ` Eric Blake
2016-07-05 22:17       ` John Snow
2016-07-03  2:58 ` [Qemu-devel] [PATCH v8 11/16] qapi-event: Reduce chance of collision with event data Eric Blake
2016-07-07 11:37   ` Markus Armbruster
2016-07-13 21:05     ` Eric Blake
2016-07-03  2:58 ` [Qemu-arm] [PATCH v8 12/16] qapi: Change Netdev into a flat union Eric Blake
2016-07-03  2:58   ` Eric Blake
2016-07-03  2:58   ` [Qemu-devel] " Eric Blake
2016-07-03  2:58 ` [Qemu-devel] [PATCH v8 13/16] net: Use correct type for bool flag Eric Blake
2016-07-03  2:58 ` [Qemu-devel] [PATCH v8 14/16] net: Complete qapi-fication of netdev_add Eric Blake
2016-07-07 12:57   ` Markus Armbruster
2016-07-03  2:58 ` [Qemu-devel] [PATCH v8 15/16] qapi: Allow anonymous branch types in flat union Eric Blake
2016-07-03  2:58 ` [Qemu-devel] [PATCH v8 16/16] schema: Drop pointless empty type CpuInfoOther Eric Blake
2016-07-07 13:40 ` [Qemu-devel] [PATCH for-2.7 v8 00/16] qapi netdev_add introspection (post-introspection cleanups subset F) Markus Armbruster

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=1467514729-29366-5-git-send-email-eblake@redhat.com \
    --to=eblake@redhat.com \
    --cc=armbru@redhat.com \
    --cc=mdroth@linux.vnet.ibm.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.