From nobody Mon Nov 25 05:22:19 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1717492393905168.9085674703624; Tue, 4 Jun 2024 02:13:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sEQDM-0005ln-Ug; Tue, 04 Jun 2024 05:12:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sEQDL-0005la-GK; Tue, 04 Jun 2024 05:12:19 -0400 Received: from proxmox-new.maurer-it.com ([94.136.29.106]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sEQDJ-0001eN-BG; Tue, 04 Jun 2024 05:12:19 -0400 Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id D030A42A29; Tue, 4 Jun 2024 11:12:13 +0200 (CEST) From: Fiona Ebner To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, crosa@redhat.com, jsnow@redhat.com, hreitz@redhat.com, kwolf@redhat.com Subject: [RFC PATCH] block-coroutine-wrapper: support generating wrappers for functions without arguments Date: Tue, 4 Jun 2024 11:12:08 +0200 Message-Id: <20240604091208.39677-1-f.ebner@proxmox.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=94.136.29.106; envelope-from=f.ebner@proxmox.com; helo=proxmox-new.maurer-it.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1717492395522100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Fiona Ebner --- An alternative would be to detect whether the argument list is 'void' in FuncDecl's __init__, assign the empty list to self.args there and special case based on that in the rest of the code. Not super happy about the introduction of the 'void_value' parameter, but the different callers seem to make something like it necessary. Could be avoided if there were a nice way to map a format which contains no other keys besides '{name}' to the empty list if the argument's 'name' is 'None'. At least until there is a format that contains both '{name}' and another key which would require special handling again. The generated code unfortunately does contain a few extra blank lines. Avoiding that would require turning some of the (currently static) formatting surrounding gen_block() dynamic based upon whether the argument list is 'void'. Happy about any feedback/suggestions! scripts/block-coroutine-wrapper.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/scripts/block-coroutine-wrapper.py b/scripts/block-coroutine-w= rapper.py index dbbde99e39..533f6dbe12 100644 --- a/scripts/block-coroutine-wrapper.py +++ b/scripts/block-coroutine-wrapper.py @@ -54,6 +54,11 @@ class ParamDecl: r')') =20 def __init__(self, param_decl: str) -> None: + if param_decl.strip() =3D=3D 'void': + self.decl =3D 'void' + self.type =3D 'void' + self.name =3D None + return m =3D self.param_re.match(param_decl.strip()) if m is None: raise ValueError(f'Wrong parameter declaration: "{param_decl}"= ') @@ -114,10 +119,14 @@ def gen_ctx(self, prefix: str =3D '') -> str: else: return 'qemu_get_aio_context()' =20 - def gen_list(self, format: str) -> str: + def gen_list(self, format: str, void_value=3D'') -> str: + if len(self.args) =3D=3D 1 and self.args[0].type =3D=3D 'void': + return void_value return ', '.join(format.format_map(arg.__dict__) for arg in self.a= rgs) =20 def gen_block(self, format: str) -> str: + if len(self.args) =3D=3D 1 and self.args[0].type =3D=3D 'void': + return '' return '\n'.join(format.format_map(arg.__dict__) for arg in self.a= rgs) =20 =20 @@ -158,7 +167,7 @@ def create_mixed_wrapper(func: FuncDecl) -> str: graph_assume_lock =3D 'assume_graph_lock();' if func.graph_rdlock else= '' =20 return f"""\ -{func.return_type} {func.name}({ func.gen_list('{decl}') }) +{func.return_type} {func.name}({ func.gen_list('{decl}', 'void') }) {{ if (qemu_in_coroutine()) {{ {graph_assume_lock} @@ -186,7 +195,7 @@ def create_co_wrapper(func: FuncDecl) -> str: name =3D func.target_name struct_name =3D func.struct_name return f"""\ -{func.return_type} {func.name}({ func.gen_list('{decl}') }) +{func.return_type} {func.name}({ func.gen_list('{decl}', 'void') }) {{ {struct_name} s =3D {{ .poll_state.ctx =3D qemu_get_current_aio_context(), @@ -284,7 +293,7 @@ def gen_no_co_wrapper(func: FuncDecl) -> str: aio_co_wake(s->co); }} =20 -{func.return_type} coroutine_fn {func.name}({ func.gen_list('{decl}') }) +{func.return_type} coroutine_fn {func.name}({ func.gen_list('{decl}', 'voi= d') }) {{ {struct_name} s =3D {{ .co =3D qemu_coroutine_self(), --=20 2.39.2