qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL for-2.7 09/15] qapi-event: Simplify visit of non-implicit data
Date: Tue, 19 Jul 2016 13:39:31 +0200	[thread overview]
Message-ID: <1468928377-20384-10-git-send-email-armbru@redhat.com> (raw)
In-Reply-To: <1468928377-20384-1-git-send-email-armbru@redhat.com>

From: Eric Blake <eblake@redhat.com>

Commit 7ce106a9 documented why we don't generated a visit_type_FOO()
for implicit types; and therefore events with an anonymous type for
'data' have to open-code a visit.  Note that the open-coded visit in
qapi-event.c is slightly different from what is done in
qapi-visit.c for normal types, in part because we don't have to
check for *obj being NULL or free things on error.  But where the
type is not implicit, it is nicer to reuse the normal visit instead
of open-coding a duplicate.

At the moment, the only event with a non-implicit 'data' is in the
testsuite, where test-qapi-event.c changes as follows:

|@@ -155,6 +155,7 @@ void qapi_event_send___org_qemu_x_event(
|     __org_qemu_x_Struct param = {
|         __org_qemu_x_member1, (char *)__org_qemu_x_member2, has_q_wchar_t, q_wchar_t
|     };
|+    __org_qemu_x_Struct *arg = &param;
|
|     emit = qmp_event_get_func_emit();
|     if (!emit) {
|@@ -164,16 +165,7 @@ void qapi_event_send___org_qemu_x_event(
|     qmp = qmp_event_build_dict("__ORG.QEMU_X-EVENT");
|
|     v = qmp_output_visitor_new(&obj);
|-
|-    visit_start_struct(v, "__ORG.QEMU_X-EVENT", NULL, 0, &err);
|-    if (err) {
|-        goto out;
|-    }
|-    visit_type___org_qemu_x_Struct_members(v, &param, &err);
|-    if (!err) {
|-    if (!err) {
|-        visit_check_struct(v, &err);
|-    }
|-    visit_end_struct(v, NULL);
|+    visit_type___org_qemu_x_Struct(v, "__ORG.QEMU_X-EVENT", &arg, &err);
|     if (err) {
|         goto out;
|     }

Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1468468228-27827-8-git-send-email-eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 scripts/qapi-event.py | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/scripts/qapi-event.py b/scripts/qapi-event.py
index 09c0a2a..b9c6b6e 100644
--- a/scripts/qapi-event.py
+++ b/scripts/qapi-event.py
@@ -49,6 +49,11 @@ def gen_param_var(typ):
 
     };
 ''')
+    if not typ.is_implicit():
+        ret += mcgen('''
+    %(c_name)s *arg = &param;
+''',
+                     c_name=typ.c_name())
     return ret
 
 
@@ -91,6 +96,14 @@ def gen_event_send(name, arg_type):
     if arg_type and not arg_type.is_empty():
         ret += mcgen('''
     v = qmp_output_visitor_new(&obj);
+''')
+        if not arg_type.is_implicit():
+            ret += mcgen('''
+    visit_type_%(c_name)s(v, "%(name)s", &arg, &err);
+''',
+                         name=name, c_name=arg_type.c_name())
+        else:
+            ret += mcgen('''
 
     visit_start_struct(v, "%(name)s", NULL, 0, &err);
     if (err) {
@@ -101,14 +114,16 @@ def gen_event_send(name, arg_type):
         visit_check_struct(v, &err);
     }
     visit_end_struct(v, NULL);
+''',
+                         name=name, c_name=arg_type.c_name())
+        ret += mcgen('''
     if (err) {
         goto out;
     }
 
     visit_complete(v, &obj);
     qdict_put_obj(qmp, "data", obj);
-''',
-                     name=name, c_name=arg_type.c_name())
+''')
 
     ret += mcgen('''
     emit(%(c_enum)s, qmp, &err);
-- 
2.5.5

  parent reply	other threads:[~2016-07-19 11:39 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-19 11:39 [Qemu-devel] [PULL for-2.7 00/15] QAPI patches for 2016-07-19 Markus Armbruster
2016-07-19 11:39 ` [Qemu-devel] [PULL for-2.7 01/15] qapi: change QmpOutputVisitor to QSLIST Markus Armbruster
2016-07-19 11:39 ` [Qemu-devel] [PULL for-2.7 02/15] qapi: change QmpInputVisitor " Markus Armbruster
2016-07-19 11:39 ` [Qemu-devel] [PULL for-2.7 03/15] net: use Netdev instead of NetClientOptions in client init Markus Armbruster
2016-07-19 11:39 ` [Qemu-devel] [PULL for-2.7 04/15] qapi: Require all branches of flat union enum to be covered Markus Armbruster
2016-07-19 11:39 ` [Qemu-devel] [PULL for-2.7 05/15] qapi: Special case c_name() for empty type Markus Armbruster
2016-07-19 11:39 ` [Qemu-devel] [PULL for-2.7 06/15] qapi: Hide tag_name data member of variants Markus Armbruster
2016-07-19 11:39 ` [Qemu-devel] [PULL for-2.7 07/15] qapi: Add type.is_empty() helper Markus Armbruster
2016-07-19 11:39 ` [Qemu-devel] [PULL for-2.7 08/15] qapi: Drop useless gen_err_check() Markus Armbruster
2016-07-19 11:39 ` Markus Armbruster [this message]
2016-07-19 11:39 ` [Qemu-devel] [PULL for-2.7 10/15] qapi: Plumb in 'boxed' to qapi generator lower levels Markus Armbruster
2016-07-19 11:39 ` [Qemu-devel] [PULL for-2.7 11/15] qapi: Implement boxed types for commands/events Markus Armbruster
2016-07-19 11:39 ` [Qemu-devel] [PULL for-2.7 12/15] block: Simplify block_set_io_throttle Markus Armbruster
2016-07-19 11:39 ` [Qemu-devel] [PULL for-2.7 13/15] block: Simplify drive-mirror Markus Armbruster
2016-07-19 11:39 ` [Qemu-devel] [PULL for-2.7 14/15] qapi: Change Netdev into a flat union Markus Armbruster
2016-07-19 17:22   ` [Qemu-devel] [PATCH 14/15] fixup! " Eric Blake
2016-07-19 11:39 ` [Qemu-devel] [PULL for-2.7 15/15] net: Use correct type for bool flag Markus Armbruster
2016-07-19 16:56 ` [Qemu-devel] [PULL for-2.7 00/15] QAPI patches for 2016-07-19 Peter Maydell
2016-07-19 17:05   ` Eric Blake
2016-07-19 17:06   ` Peter Maydell

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=1468928377-20384-10-git-send-email-armbru@redhat.com \
    --to=armbru@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 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).