From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 39CAB606A32F for ; Mon, 2 Nov 2026 05:50:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=CmOAScZo Received: from list by lists.xenproject.org with outflank-mailman.1467435.1676755 (Exim 4.92) (envelope-from ) id 1xNkw9-0002ta-SF; Mon, 02 Nov 2026 05:50:29 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 1467435.1676755; Mon, 02 Nov 2026 05:50:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xNkw9-0002rd-IR; Mon, 02 Nov 2026 05:50:29 +0000 Received: by outflank-mailman (input) for mailman id 1467435; Sun, 01 Nov 2026 20:11:19 +0000 Received: from mx.expurgate.net ([194.145.224.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xNbtf-0001pY-QL for xen-devel@lists.xenproject.org; Sun, 01 Nov 2026 20:11:19 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xNbtf-007BcK-7B for xen-devel@lists.xenproject.org; Sun, 01 Nov 2026 21:11:19 +0100 Received: from [10.42.69.6] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6ae79cd0-8faa-0a2a0a5109dd-0a2a4506857a-10 for ; Sun, 01 Nov 2026 21:11:19 +0100 Received: from [170.10.129.124] (helo=us-smtp-delivery-124.mimecast.com) by tlsNG-16d1c6.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6ae79ce5-195a-0a2a45060019-aa0a817c7b9b-3 for ; Sun, 01 Nov 2026 21:11:18 +0100 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-501-dbNBgUI3NkO7qJoX7yVMQQ-1; Sun, 01 Nov 2026 15:11:14 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 23A951800619; Sun, 1 Nov 2026 20:11:09 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.44.22.2]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D6A2730002CB; Sun, 1 Nov 2026 20:11:06 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 5DB5421E6A04; Sun, 01 Nov 2026 21:11:04 +0100 (CET) Resent-To: pasic@linux.ibm.com, 17746591750@163.com, rathc@linux.ibm.com, alistair@alistair23.me, stefanb@linux.vnet.ibm.com, graf@amazon.com, xen-devel@lists.xenproject.org, FangSheng.Huang@amd.com, michael.roth@amd.com, jamin_lin@aspeedtech.com, kane_chen@aspeedtech.com, palmer@dabbelt.com, rbolshakov@ddn.com, foss@defmacro.it, sebastian.huber@embedded-brains.de, fam@euphon.net, jiaxun.yang@flygoat.com, lizhijian@fujitsu.com, atar4qemu@gmail.com, edgar.iglesias@gmail.com, jasowangio@gmail.com, liwei1518@gmail.com, npiggin@gmail.com, zhangckid@gmail.com, titusr@google.com, wuhaotsh@google.com, arei.gonglei@huawei.com, berto@igalia.com, mark.cave-ayland@ilande.co.uk, junjie.cao@intel.com, zhao1.liu@intel.com, its@irrelevant.dk, clg@kaod.org, conor@kernel.org, david@kernel.org, jic23@kernel.org, kbusch@kernel.org, mchehab+huawei@kernel.org, sstabellini@kernel.org, peter.maydell@linaro.org, richard.henderson@linaro.org, zhiwei_liu@linux.alibaba.com, zhenwei.pi@linux.dev, adityag@linux.ibm.com, alifm@linux.ibm.com, amachhiw@linux.ibm.com, borntraeger@linux.ibm.com, brueckner@linux.ibm.com, farman@linux.ibm.com, harshpb@linux.ibm.com, iii@linux.ibm.com, jjherne@linux.ibm.com, milesg@linux.ibm.com, mjrosato@linux.ibm.com, luc@lmichel.fr, lixianglai@loongson.cn, maobibo@loongson.cn, pbarbuda@microsoft.com, yoshinori.sato@nifty.com, qemu-arm@nongnu.org, qemu-block@nongnu.org, qemu-devel@nongnu.org, qemu-ppc@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org, john.levon@nutanix.com, thanos.makatos@nutanix.com, kfting@nuvoton.com, den@openvz.org, elena.ufimtseva@oracle.com, jag.raman@oracle.com, daniel.barboza@oss.qualcomm.com, philmd@oss.qualcomm.com, pierrick.bouvier@oss.qualcomm.com, phil@philjordan.eu, tangtao1634@phytium.com.cn, chao.liu@processmission.com, jiri@resnulli.us, sam@rfc1149.net, anisa.su@samsung.com, alex@shazbot.org, farosas@suse.de, mohamed@unpredictable.fr, kvm@vger.kernel.org, linux-cxl@vger.kernel.org, alistair.francis@wdc.com, anthony@xenproject.org Resent-From: Markus Armbruster Resent-Date: Sun, 01 Nov 2026 21:11:04 +0100 Resent-Message-ID: <87ik2g1fdz.fsf@pond.sub.org> X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Post: List-Help: List-Subscribe: , Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=mimecast20190719 header.d=redhat.com header.i="@redhat.com" header.h="From:Subject:Date:Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding:Resent-To:Resent-From:Resent-Message-ID:In-Reply-To:References" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793563877; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-to: resent-from:resent-message-id:in-reply-to:in-reply-to: references:references; bh=d7M241dr+M0CEAKHzbbpskGbE8+ty5Q2vQiKfnyhvII=; b=CmOAScZoFkiohsaiM3dNqKC/lS8iXnZfC8yOT+ABVq6g3lhMICiXfFRjVY3yfUT5KTCu1W KJpZW2amuRHpIFuPYSsLI3ztqP0tqRkkzx5R9FntwRgBHIs5RCrkXt8SxiWBOW2Te3IPJQ 6d7S25MvREGHtcFi6V0veNDFc+RfsaM= X-MC-Unique: dbNBgUI3NkO7qJoX7yVMQQ-1 X-Mimecast-MFC-AGG-ID: dbNBgUI3NkO7qJoX7yVMQQ_1793563870 From: Markus Armbruster To: =?utf-8?Q?Marc-Andr=C3=A9?= Lureau Cc: qemu-devel@nongnu.org, Michael Roth , John Snow , Peter Maydell , Mauro Carvalho Chehab , Pierrick Bouvier , Paolo Bonzini , Daniel P. =?utf-8?Q?Berrang=C3=A9?= , Kostiantyn Kostiuk , Eric Blake , David Hildenbrand , Igor Mammedov , "Edgar E. Iglesias" , Jason Wang , Marcelo Tosatti , kvm@vger.kernel.org, Alberto Garcia , Kevin Wolf , Hanna Reitz , Philippe =?utf-8?Q?Mathieu-Daud=C3=A9?= , Zhao Liu , Jonathan Cameron , Junjie Cao , Anisa Su , Elena Ufimtseva , Jagannathan Raman , John Levon , Thanos Makatos , =?utf-8?Q?C=C3=A9dric?= Le Goater , Cornelia Huck , Eric Farman , Matthew Rosato , Richard Henderson , Ilya Leoshkevich , qemu-block@nongnu.org, linux-cxl@vger.kernel.org, qemu-s390x@nongnu.org, "Michael S. Tsirkin" , Sergio Lopez , qemu-arm@nongnu.org, Palmer Dabbelt , Alistair Francis , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , Chao Liu , qemu-riscv@nongnu.org, Song Gao <17746591750@163.com>, Bibo Mao , Xianglai Li , Jiaxun Yang , Pedro Barbuda , Mohamed Mediouni , Nicholas Piggin , Harsh Prateek Bora , Amit Machhiwal , qemu-ppc@nongnu.org, Zhang Chen , Li Zhijian , Alistair Francis , Alexander Graf , "Gonglei (Arei)" , zhenwei pi , Ani Sinha , Luc Michel , =?utf-8?Q?C=C3=A9dric?= Le Goater , Jamin Lin , Kane Chen , Samuel Tardieu , "Denis V. Lunev" , FangSheng Huang , Tyrone Ting , Hao Wu , Keith Busch , Klaus Jensen , Jesper Devantier , Aditya Gupta , Glenn Miles , Conor Dooley , Sebastian Huber , Halil Pasic , Christian Borntraeger , Jason Herne , Titus Rwantare , Stefano Stabellini , Anthony PERARD , Peter Xu , Chinmay Rath , Hendrik Brueckner , xen-devel@lists.xenproject.org, Roman Bolshakov , Phil Dennis-Jordan , Fam Zheng , Farhan Ali , Alex Williamson , Tao Tang , Stefan Berger , Fabiano Rosas , Mark Cave-Ayland , Artyom Tarasenko , Yoshinori Sato , Jiri Pirko , Eric Auger , Laurent Vivier Subject: Re: [PATCH v7 17/65] qom: add object_{class_}property_add_qapi_enum In-Reply-To: <20261020-qom-qapi-v7-17-431a86b02b58@redhat.com> (=?utf-8?Q?=22Marc-Andr=C3=A9?= Lureau"'s message of "Tue, 20 Oct 2026 14:45:34 +0400") References: <20261020-qom-qapi-v7-0-431a86b02b58@redhat.com> <20261020-qom-qapi-v7-17-431a86b02b58@redhat.com> Date: Fri, 30 Oct 2026 11:02:00 +0100 Message-ID: <871p97a4mf.fsf@pond.sub.org> User-Agent: Gnus/5.13 (Gnus v5.13) X-Archived-By: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-MFC-PROC-ID: qrbBaIqulz2eq8rXwVCrDM1gcXcsL_8U4Fm_aBEFxv8_1793563870 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-16d1c6/1793563879-1EAC277B-AB7FFFF6/0/0 X-purgate-type: clean X-purgate-size: 4497 X-Spam-Status: No, score=-17.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS,UNPARSEABLE_RELAY,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Marc-Andr=C3=A9 Lureau writes: > Signed-off-by: Markus Armbruster > Signed-off-by: Marc-Andr=C3=A9 Lureau > --- > include/qom/object.h | 74 ++++++++++++++++++++++++++++++++++++++++++ > qom/object.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++= +++--- > 2 files changed, 159 insertions(+), 5 deletions(-) > > diff --git a/include/qom/object.h b/include/qom/object.h > index eb61d8842b80..e04be4caed57 100644 > --- a/include/qom/object.h > +++ b/include/qom/object.h > @@ -2027,6 +2027,80 @@ ObjectProperty *object_class_property_add_enum(Obj= ectClass *klass, > int (*get)(Object *, Error **), > void (*set)(Object *, int, Error **)= ); > =20 > +/** > + * struct QapiEnumProp: Descriptor for a property backed by a QAPI enum = type > + * > + * Binds a QOM object property to a QAPI enum, providing automatic > + * string<->int conversion through QAPI visitors and optional > + * default-value initialization during object instance init. > + * > + * Use the QAPI_ENUM_PROP() macro to construct instances inline. > + * > + * @name: property name exposed on the QOM object > + * @description: human-readable description (shown in ``-device help``, = etc.) > + * @default_value: initial enum value applied via @set during instance i= nit, > + * or -1 (the QAPI_ENUM_PROP default) to skip initializa= tion > + * @qapi_type: pointer to the generated QAPITypeInfo for the enum > + * (provides the string<->int lookup table) > + * @get: getter that returns the current enum value as int, or -1 on err= or > + * @set: setter that receives the enum value as int; %NULL for read-only= props > + */ > +typedef struct QapiEnumProp { > + const char *name; > + const char *description; > + const int default_value; > + const QAPITypeInfo *qapi_type; > + int (*get)(Object *, Error **); > + void (*set)(Object *, int, Error **); > +} QapiEnumProp; > + > +#define QAPI_ENUM_PROP(...) ({ = \ > + static const QapiEnumProp _prop =3D { = \ > + .default_value =3D -1, __VA_ARGS__ = \ > + }; = \ > + &_prop; }) This is a cute and reasonably well-known macro trick for optional keyword arguments in C. The example [*] below specifies all arguments. What happens when we omit any? They default to zero via default initializaion, except for .default_value, which defaults to -1. Trap for developers: some arguments aren't actually optional! If you forget to specify @name or @qapi_type, the code compiles, but crashes at run time. Not a fan. > + > +/** > + * object_property_add_qapi_enum: > + * @obj: the object to add a property to > + * @prop: property descriptor > + * > + * Add an enum property with QAPI type association. > + * > + * Returns: The newly added property on success, or %NULL on failure. > + */ > +ObjectProperty * > +object_property_add_qapi_enum(Object *obj, const QapiEnumProp *prop); > + > +/** > + * object_class_property_add_qapi_enum: > + * @klass: the class object to add a property to > + * @prop: property descriptor > + * > + * Add an enum property with QAPI type association. > + * > + * Use the QAPI_ENUM_PROP() macro to construct the property descriptor > + * inline. If .default_value is not set, the property is not initialized > + * (default_value is -1). Otherwise, the setter is called with > + * default_value during object instance init. > + * > + * Example:: [*] > + * > + * object_class_property_add_qapi_enum(oc, QAPI_ENUM_PROP( > + * .name =3D "policy", > + * .description =3D "Set the NUMA policy", > + * .default_value =3D HOST_MEM_POLICY_DEFAULT, > + * .qapi_type =3D &HostMemPolicy_type_info, > + * .get =3D my_get_policy, > + * .set =3D my_set_policy, > + * )); > + * > + * Returns: The newly added property on success, or %NULL on failure. > + */ > +ObjectProperty * > +object_class_property_add_qapi_enum(ObjectClass *klass, > + const QapiEnumProp *prop); > + > /** > * object_property_add_qapi: > * @obj: the object to add a property to [...]