From nobody Tue Feb 10 19:23:04 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.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; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1770692318; cv=none; d=zohomail.com; s=zohoarc; b=lK9Fg7R2PX2GPa/xj/hiprtS2thSi3Zpvh8zWDI4+jrU15laHmWrxjL9qa0DWsw28YhjzZCShFT9PmE1g95KkNeKdUSS+MitPJrIgDcdDD0SQ+L8DURI7na1FqJvIucrQhOndJFve+aRSLwjMSpu4kKGdZFFT8Z7fzGFbBRNI3w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770692318; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=hfkL9dI1MHIXHMiiXgK+a5hpZLONGsXXvA6Mw42d1gE=; b=BI75VWetW0IrJ7dQshj3vAtqTaLbk1+/J9pStof3A93zbGWJ6aqWkoNDHIn8RAos6bY7nm0z+QPtQQUWuEAlcUpVaGQ3hOx64vsEkYuB1VS2+nOkXaVmplBQsvTgS/DwVV6ihTFo/RrnQbUJVWNRRnV4RjREpo0y6dz3w+5S1zk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.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; 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 1770692318689963.9804707159315; Mon, 9 Feb 2026 18:58:38 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vpdxR-00064t-PZ; Mon, 09 Feb 2026 21:58:33 -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 1vpdxQ-00063G-Hm for qemu-devel@nongnu.org; Mon, 09 Feb 2026 21:58:32 -0500 Received: from mgamail.intel.com ([198.175.65.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vpdxO-00046a-6J for qemu-devel@nongnu.org; Mon, 09 Feb 2026 21:58:32 -0500 Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2026 18:58:30 -0800 Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.39]) by orviesa008.jf.intel.com with ESMTP; 09 Feb 2026 18:58:24 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1770692310; x=1802228310; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=s/JlYnxjXvIrGB6oJxc/D12Kh0TiBPjCTqhRHSqsD3A=; b=G4qMGfIZIZp3jfSRQFS98glvRTFdBp8QmCdccNfMjpvF/H6jeWjUpeCX aRRrfNOZ0rmU1Ns0vuhoOuXr8djJPFTy6jxR4D8UCJLw9e2Ht4IHkRh+E 9PMkobyfauf9eQn7MdlZUY2IsXjDLJdNHAuZgL3MLdok0addHZ9hj1Uzq EyCQx5R4Dof9/qWpqxZkYehYRxwa+ldXI2qIym4bLJoUxU6UFVXy0IvNO yhc/5xiw3lxsBPq3mlT8yHpvXoQBTSsV7L0J0QZU44fX+BD65e0f4DHXy 23bp51+e8tPuxuPCJoU42iUOjaJuKa3Nlut3cJ8srYk2xsRlHA6W5Qjf1 A==; X-CSE-ConnectionGUID: +lwqZmhjTFuotFOWmovjEQ== X-CSE-MsgGUID: zulYyosESueEYcFGPlZ50A== X-IronPort-AV: E=McAfee;i="6800,10657,11696"; a="71854249" X-IronPort-AV: E=Sophos;i="6.21,283,1763452800"; d="scan'208";a="71854249" X-CSE-ConnectionGUID: ayAaCdiVSB2REoX++RGXJw== X-CSE-MsgGUID: XikgiVXbTQyXeA48f7Z3eQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,283,1763452800"; d="scan'208";a="211800457" From: Zhao Liu To: Paolo Bonzini , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Eduardo Habkost , Markus Armbruster , Thomas Huth , Igor Mammedov , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: Richard Henderson , Peter Maydell , "Michael S . Tsirkin" , BALATON Zoltan , Mark Cave-Ayland , Pierrick Bouvier , Zide Chen , Dapeng Mi , Zhao Liu , qemu-devel@nongnu.org, devel@lists.libvirt.org Subject: [PATCH v2 03/21] qom/object: factor out object_class_property_try_add() Date: Tue, 10 Feb 2026 11:23:30 +0800 Message-Id: <20260210032348.987549-4-zhao1.liu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260210032348.987549-1-zhao1.liu@intel.com> References: <20260210032348.987549-1-zhao1.liu@intel.com> 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=198.175.65.18; envelope-from=zhao1.liu@intel.com; helo=mgamail.intel.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: qemu development 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 @intel.com) X-ZM-MESSAGEID: 1770692320957158500 Content-Type: text/plain; charset="utf-8" Similar to object_property_try_add(), factor out object_class_property_try_add(). This allows adding more arguments to the core implementation without changing the signature of object_class_property_add(), avoiding the need to modify the extensive number of callers distributed throughout the code tree. While at it, add documentation for these functions. Signed-off-by: Zhao Liu --- include/qom/object.h | 56 ++++++++++++++++++++++++++++++++++++++++++++ qom/object.c | 34 ++++++++++++++++++++------- 2 files changed, 82 insertions(+), 8 deletions(-) diff --git a/include/qom/object.h b/include/qom/object.h index 05706d4d7e3a..060db136988b 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -1147,6 +1147,62 @@ ObjectProperty *object_property_add(Object *obj, con= st char *name, =20 void object_property_del(Object *obj, const char *name); =20 +/** + * object_class_property_try_add: + * @klass: the object class to add a property to + * @name: the name of the property. This can contain any character except= for + * a forward slash. In general, you should use hyphens '-' instead of + * underscores '_' when naming properties. + * @type: the type name of the property. This namespace is pretty loosely + * defined. Sub namespaces are constructed by using a prefix and then + * to angle brackets. For instance, the type 'virtio-net-pci' in the + * 'link' namespace would be 'link'. + * @get: The getter to be called to read a property. If this is NULL, then + * the property cannot be read. + * @set: the setter to be called to write a property. If this is NULL, + * then the property cannot be written. + * @release: called when the property is removed from the object. This is + * meant to allow a property to free its opaque upon object + * destruction. This may be NULL. + * @opaque: an opaque pointer to pass to the callbacks for the property + * @errp: pointer to error object + * + * Returns: The #ObjectProperty; this can be used to set the @resolve + * callback for child and link properties. + */ +ObjectProperty *object_class_property_try_add(ObjectClass *klass, const ch= ar *name, + const char *type, + ObjectPropertyAccessor *get, + ObjectPropertyAccessor *set, + ObjectPropertyRelease *relea= se, + void *opaque, Error **errp); + + +/** + * object_class_property_add: + * Same as object_class_property_try_add() with @errp hardcoded to + * &error_abort. + * + * @klass: the object class to add a property to + * @name: the name of the property. This can contain any character except= for + * a forward slash. In general, you should use hyphens '-' instead of + * underscores '_' when naming properties. + * @type: the type name of the property. This namespace is pretty loosely + * defined. Sub namespaces are constructed by using a prefix and then + * to angle brackets. For instance, the type 'virtio-net-pci' in the + * 'link' namespace would be 'link'. + * @get: The getter to be called to read a property. If this is NULL, then + * the property cannot be read. + * @set: the setter to be called to write a property. If this is NULL, + * then the property cannot be written. + * @release: called when the property is removed from the object. This is + * meant to allow a property to free its opaque upon object + * destruction. This may be NULL. + * @opaque: an opaque pointer to pass to the callbacks for the property + * + * Returns: The #ObjectProperty; this can be used to set the @resolve + * callback for child and link properties. + */ ObjectProperty *object_class_property_add(ObjectClass *klass, const char *= name, const char *type, ObjectPropertyAccessor *get, diff --git a/qom/object.c b/qom/object.c index f5801f4624c8..f101b48154d1 100644 --- a/qom/object.c +++ b/qom/object.c @@ -1310,17 +1310,22 @@ object_property_add(Object *obj, const char *name, = const char *type, } =20 ObjectProperty * -object_class_property_add(ObjectClass *klass, - const char *name, - const char *type, - ObjectPropertyAccessor *get, - ObjectPropertyAccessor *set, - ObjectPropertyRelease *release, - void *opaque) +object_class_property_try_add(ObjectClass *klass, + const char *name, + const char *type, + ObjectPropertyAccessor *get, + ObjectPropertyAccessor *set, + ObjectPropertyRelease *release, + void *opaque, Error **errp) { ObjectProperty *prop; =20 - assert(!object_class_property_find(klass, name)); + if (object_class_property_find(klass, name) !=3D NULL) { + error_setg(errp, "attempt to add duplicate property '%s'" + " to object class (type '%s')", + name, object_class_get_name(klass)); + return NULL; + } =20 prop =3D g_malloc0(sizeof(*prop)); =20 @@ -1337,6 +1342,19 @@ object_class_property_add(ObjectClass *klass, return prop; } =20 +ObjectProperty * +object_class_property_add(ObjectClass *klass, + const char *name, + const char *type, + ObjectPropertyAccessor *get, + ObjectPropertyAccessor *set, + ObjectPropertyRelease *release, + void *opaque) +{ + return object_class_property_try_add(klass, name, type, get, set, rele= ase, + opaque, &error_abort); +} + ObjectProperty *object_property_find(Object *obj, const char *name) { ObjectProperty *prop; --=20 2.34.1