From nobody Thu Apr 18 03:02:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1669204075; cv=none; d=zohomail.com; s=zohoarc; b=LCDZowMix9kMTh4JUGgyloBtNL5kW6Y3IH73JP3iqsujWxiggFJ1tX5KzOyt5StXb90pLXxkMekeTcHzJotSETmonEcAsQDDBMIQrw4FdqGQaVTM8hpaQuN+9SPi6gpavOFxUUh6B0MLERqz+vRYXvbuHqRE6jFLrgmGnnbqRS8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669204075; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=wc7F4F4/2eKWKkHzMVSzkX8KJJEXGLmJREPh3O0wVgY=; b=FyRveNyyt/KO4fhoSPSS7Z/ARpaX8e7AeNxiJImiGyOW7lxXI3twPFyoCudIPIYd1WXhkXoRog17RBwe11PqN1ySz2V0Mpc4nkr624s0O5sZIuBU7KFkmoqFFSVKXJXA4mtJO5Tl7AoIzdz2Rbguq8r13OfkbxbGKMFaxDNwf5M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1669204075396908.6164835755307; Wed, 23 Nov 2022 03:47:55 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oxo9P-0002lD-Ia; Wed, 23 Nov 2022 06:42:47 -0500 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 1oxo9K-0002gc-Ly for qemu-devel@nongnu.org; Wed, 23 Nov 2022 06:42:42 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oxo9H-000636-MG for qemu-devel@nongnu.org; Wed, 23 Nov 2022 06:42:42 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-628-unyjsTpJP_OIML3oehwD1A-1; Wed, 23 Nov 2022 06:42:35 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2F531802D32; Wed, 23 Nov 2022 11:42:35 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id CD7F6C2C8C5; Wed, 23 Nov 2022 11:42:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669203759; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wc7F4F4/2eKWKkHzMVSzkX8KJJEXGLmJREPh3O0wVgY=; b=b6JCyJ3kCejpmNEcHcxoOoXsqgKD4QsrYNUzwwTiT2br487fblABLdonXNTqPQlrj+EQO6 n7qfgXoF24EaDNDwG4yaiGdVoOJvtzH8gboDd4ZcUAnPJLQfbVTw5behPhkHL2MRXDaMlY g0X0iWObo8vMj3MSjMPcpAVcTid+b/M= X-MC-Unique: unyjsTpJP_OIML3oehwD1A-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Cc: Kevin Wolf , Hanna Reitz , John Snow , Vladimir Sementsov-Ogievskiy , Eric Blake , Fam Zheng , Stefan Hajnoczi , "Denis V. Lunev" , Stefan Weil , Jeff Cody , Cleber Rosa , qemu-devel@nongnu.org, Emanuele Giuseppe Esposito Subject: [PATCH v5 13/15] block-coroutine-wrapper.py: support also basic return types Date: Wed, 23 Nov 2022 06:42:25 -0500 Message-Id: <20221123114227.85757-14-eesposit@redhat.com> In-Reply-To: <20221123114227.85757-1-eesposit@redhat.com> References: <20221123114227.85757-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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=170.10.133.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_FILL_THIS_FORM_SHORT=0.01 autolearn=unavailable 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-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1669204076841100001 Content-Type: text/plain; charset="utf-8" Extend the regex to cover also return type, pointers included. This implies that the value returned by the function cannot be a simple "int" anymore, but the custom return type. Therefore remove poll_state->ret and instead use a per-function custom "ret" field. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Kevin Wolf --- block/block-gen.h | 5 +---- scripts/block-coroutine-wrapper.py | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/block/block-gen.h b/block/block-gen.h index 08d977f493..89b7daaa1f 100644 --- a/block/block-gen.h +++ b/block/block-gen.h @@ -32,18 +32,15 @@ typedef struct BdrvPollCo { AioContext *ctx; bool in_progress; - int ret; Coroutine *co; /* Keep pointer here for debugging */ } BdrvPollCo; =20 -static inline int bdrv_poll_co(BdrvPollCo *s) +static inline void bdrv_poll_co(BdrvPollCo *s) { assert(!qemu_in_coroutine()); =20 aio_co_enter(s->ctx, s->co); AIO_WAIT_WHILE(s->ctx, s->in_progress); - - return s->ret; } =20 #endif /* BLOCK_BLOCK_GEN_H */ diff --git a/scripts/block-coroutine-wrapper.py b/scripts/block-coroutine-w= rapper.py index 1d552cb734..ef19b71c2a 100644 --- a/scripts/block-coroutine-wrapper.py +++ b/scripts/block-coroutine-wrapper.py @@ -95,7 +95,8 @@ def gen_block(self, format: str) -> str: =20 =20 # Match wrappers declared with a generated_co_wrapper mark -func_decl_re =3D re.compile(r'^int\s*generated_co_wrapper' +func_decl_re =3D re.compile(r'^(?P[a-zA-Z][a-zA-Z0-9_]* [*]?)' + r'\s*generated_co_wrapper' r'(?P(_[a-z][a-z0-9_]*)?)\s*' r'(?P[a-z][a-z0-9_]*)' r'\((?P[^)]*)\);$', re.MULTILINE) @@ -103,7 +104,7 @@ def gen_block(self, format: str) -> str: =20 def func_decl_iter(text: str) -> Iterator: for m in func_decl_re.finditer(text): - yield FuncDecl(return_type=3D'int', + yield FuncDecl(return_type=3Dm.group('return_type'), name=3Dm.group('wrapper_name'), args=3Dm.group('args'), variant=3Dm.group('variant')) @@ -124,7 +125,7 @@ def create_g_c_w(func: FuncDecl) -> str: name =3D func.co_name struct_name =3D func.struct_name return f"""\ -int {func.name}({ func.gen_list('{decl}') }) +{func.return_type} {func.name}({ func.gen_list('{decl}') }) {{ if (qemu_in_coroutine()) {{ return {name}({ func.gen_list('{name}') }); @@ -138,7 +139,8 @@ def create_g_c_w(func: FuncDecl) -> str: =20 s.poll_state.co =3D qemu_coroutine_create({name}_entry, &s); =20 - return bdrv_poll_co(&s.poll_state); + bdrv_poll_co(&s.poll_state); + return s.ret; }} }}""" =20 @@ -148,7 +150,7 @@ def create_coroutine_only(func: FuncDecl) -> str: name =3D func.co_name struct_name =3D func.struct_name return f"""\ -int {func.name}({ func.gen_list('{decl}') }) +{func.return_type} {func.name}({ func.gen_list('{decl}') }) {{ {struct_name} s =3D {{ .poll_state.ctx =3D {func.ctx}, @@ -160,13 +162,13 @@ def create_coroutine_only(func: FuncDecl) -> str: =20 s.poll_state.co =3D qemu_coroutine_create({name}_entry, &s); =20 - return bdrv_poll_co(&s.poll_state); + bdrv_poll_co(&s.poll_state); + return s.ret; }}""" =20 =20 def gen_wrapper(func: FuncDecl) -> str: assert not '_co_' in func.name - assert func.return_type =3D=3D 'int' =20 name =3D func.co_name struct_name =3D func.struct_name @@ -182,6 +184,7 @@ def gen_wrapper(func: FuncDecl) -> str: =20 typedef struct {struct_name} {{ BdrvPollCo poll_state; + {func.return_type} ret; { func.gen_block(' {decl};') } }} {struct_name}; =20 @@ -189,7 +192,7 @@ def gen_wrapper(func: FuncDecl) -> str: {{ {struct_name} *s =3D opaque; =20 - s->poll_state.ret =3D {name}({ func.gen_list('s->{name}') }); + s->ret =3D {name}({ func.gen_list('s->{name}') }); s->poll_state.in_progress =3D false; =20 aio_wait_kick(); --=20 2.31.1