qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Markus Armbruster <armbru@redhat.com>
Subject: [PULL 12/25] qapi-gen: mark coroutine QMP command functions as coroutine_fn
Date: Fri, 21 Apr 2023 11:33:03 +0200	[thread overview]
Message-ID: <20230421093316.17941-13-pbonzini@redhat.com> (raw)
In-Reply-To: <20230421093316.17941-1-pbonzini@redhat.com>

Coroutine commands have to be declared as coroutine_fn, but the
marker does not show up in the qapi-comands-* headers; likewise, the
marshaling function calls the command and therefore must be coroutine_fn.
Static analysis would want coroutine_fn to match between prototype and
declaration, because in principle coroutines might be compiled to a
completely different calling convention.  So we would like to add the
marker to the header.

Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 scripts/qapi/commands.py | 33 +++++++++++++++++++++------------
 1 file changed, 21 insertions(+), 12 deletions(-)

diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py
index 79c5e5c3a989..a079378d1b8d 100644
--- a/scripts/qapi/commands.py
+++ b/scripts/qapi/commands.py
@@ -41,11 +41,13 @@
 def gen_command_decl(name: str,
                      arg_type: Optional[QAPISchemaObjectType],
                      boxed: bool,
-                     ret_type: Optional[QAPISchemaType]) -> str:
+                     ret_type: Optional[QAPISchemaType],
+                     coroutine: bool) -> str:
     return mcgen('''
-%(c_type)s qmp_%(c_name)s(%(params)s);
+%(c_type)s %(coroutine_fn)sqmp_%(c_name)s(%(params)s);
 ''',
                  c_type=(ret_type and ret_type.c_type()) or 'void',
+                 coroutine_fn='coroutine_fn ' if coroutine else '',
                  c_name=c_name(name),
                  params=build_params(arg_type, boxed, 'Error **errp'))
 
@@ -157,16 +159,21 @@ def gen_marshal_output(ret_type: QAPISchemaType) -> str:
                  c_type=ret_type.c_type(), c_name=ret_type.c_name())
 
 
-def build_marshal_proto(name: str) -> str:
-    return ('void qmp_marshal_%s(QDict *args, QObject **ret, Error **errp)'
-            % c_name(name))
+def build_marshal_proto(name: str,
+                        coroutine: bool) -> str:
+    return ('void %(coroutine_fn)sqmp_marshal_%(c_name)s(%(params)s)' % {
+        'coroutine_fn': 'coroutine_fn ' if coroutine else '',
+        'c_name': c_name(name),
+        'params': 'QDict *args, QObject **ret, Error **errp',
+    })
 
 
-def gen_marshal_decl(name: str) -> str:
+def gen_marshal_decl(name: str,
+                     coroutine: bool) -> str:
     return mcgen('''
 %(proto)s;
 ''',
-                 proto=build_marshal_proto(name))
+                 proto=build_marshal_proto(name, coroutine))
 
 
 def gen_trace(name: str) -> str:
@@ -181,7 +188,8 @@ def gen_marshal(name: str,
                 arg_type: Optional[QAPISchemaObjectType],
                 boxed: bool,
                 ret_type: Optional[QAPISchemaType],
-                gen_tracing: bool) -> str:
+                gen_tracing: bool,
+                coroutine: bool) -> str:
     have_args = boxed or (arg_type and not arg_type.is_empty())
     if have_args:
         assert arg_type is not None
@@ -195,7 +203,7 @@ def gen_marshal(name: str,
     bool ok = false;
     Visitor *v;
 ''',
-                proto=build_marshal_proto(name))
+                proto=build_marshal_proto(name, coroutine))
 
     if ret_type:
         ret += mcgen('''
@@ -387,10 +395,11 @@ def visit_command(self,
                            self._genh, self._genc):
                 self._genc.add(gen_marshal_output(ret_type))
         with ifcontext(ifcond, self._genh, self._genc):
-            self._genh.add(gen_command_decl(name, arg_type, boxed, ret_type))
-            self._genh.add(gen_marshal_decl(name))
+            self._genh.add(gen_command_decl(name, arg_type, boxed,
+                                            ret_type, coroutine))
+            self._genh.add(gen_marshal_decl(name, coroutine))
             self._genc.add(gen_marshal(name, arg_type, boxed, ret_type,
-                                       self._gen_tracing))
+                                       self._gen_tracing, coroutine))
             if self._gen_tracing:
                 self._gen_trace_events.add(gen_trace(name))
         with self._temp_module('./init'):
-- 
2.40.0



  parent reply	other threads:[~2023-04-21  9:36 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-21  9:32 [PULL 00/25] First batch of misc patches for QEMU 8.1 Paolo Bonzini
2023-04-21  9:32 ` [PULL 01/25] mtest2make.py: teach suite name that are just "PROJECT" Paolo Bonzini
2023-04-21  9:32 ` [PULL 02/25] build-sys: prevent meson from downloading wrapped subprojects Paolo Bonzini
2023-04-21  9:32 ` [PULL 03/25] build-sys: add slirp.wrap Paolo Bonzini
2023-04-21  9:32 ` [PULL 04/25] nvme: remove constant argument to tracepoint Paolo Bonzini
2023-04-21  9:32 ` [PULL 05/25] vnc: avoid underflow when accessing user-provided address Paolo Bonzini
2023-04-21  9:32 ` [PULL 06/25] tests: bios-tables-test: replace memset with initializer Paolo Bonzini
2023-04-21  9:32 ` [PULL 07/25] configure: Avoid -Werror=maybe-uninitialized Paolo Bonzini
2023-04-21  9:32 ` [PULL 08/25] target/i386: Avoid unreachable variable declaration in mmu_translate() Paolo Bonzini
2023-04-21  9:33 ` [PULL 09/25] lasi: fix RTC migration Paolo Bonzini
2023-04-21  9:33 ` [PULL 10/25] coverity: update COMPONENTS.md Paolo Bonzini
2023-04-21  9:33 ` [PULL 11/25] target/mips: tcg: detect out-of-bounds accesses to cpu_gpr and cpu_gpr_hi Paolo Bonzini
2023-04-21  9:33 ` Paolo Bonzini [this message]
2023-04-21  9:33 ` [PULL 13/25] io: mark mixed functions that can suspend Paolo Bonzini
2023-04-21  9:33 ` [PULL 14/25] migration: " Paolo Bonzini
2023-04-21  9:33 ` [PULL 15/25] monitor: " Paolo Bonzini
2023-04-21  9:33 ` [PULL 16/25] target/i386: Change wrong XFRM value in SGX CPUID leaf Paolo Bonzini
2023-04-21  9:33 ` [PULL 17/25] block-backend: remove qatomic_mb_read() Paolo Bonzini
2023-04-21  9:33 ` [PULL 18/25] postcopy-ram: do not use qatomic_mb_read Paolo Bonzini
2023-04-21  9:33 ` [PULL 19/25] qemu-coroutine: remove qatomic_mb_read() Paolo Bonzini
2023-04-21  9:33 ` [PULL 20/25] docs: explain effect of smp_read_barrier_depends() on modern architectures Paolo Bonzini
2023-04-21  9:33 ` [PULL 21/25] nbd: a BlockExport always has a BlockBackend Paolo Bonzini
2023-04-21  9:33 ` [PULL 22/25] coverity: unify Fedora dockerfiles Paolo Bonzini
2023-04-21  9:33 ` [PULL 23/25] configure: Honour cross-prefix when finding ObjC compiler Paolo Bonzini
2023-04-21  9:33 ` [PULL 24/25] tests: libvirt-ci: Update to commit '2fa24dce8bc' Paolo Bonzini
2023-04-21  9:33 ` [PULL 25/25] tests: lcitool: Switch to OpenSUSE Leap 15.4 Paolo Bonzini
2023-04-22  7:31 ` [PULL 00/25] First batch of misc patches for QEMU 8.1 Richard Henderson

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=20230421093316.17941-13-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=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).