From nobody Thu May 2 09:32:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 150711177584151.90745543801518; Wed, 4 Oct 2017 03:09:35 -0700 (PDT) Received: from localhost ([::1]:34043 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzgcO-0001QP-4N for importer@patchew.org; Wed, 04 Oct 2017 06:09:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40779) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzgb7-0000hZ-Jv for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:08:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dzgb3-0005t5-Lt for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:08:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:4253) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dzgb3-0005ss-Fa for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:08:09 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 94DD3C05567E; Wed, 4 Oct 2017 10:08:08 +0000 (UTC) Received: from dell-r430-03.lab.eng.brq.redhat.com (dell-r430-03.lab.eng.brq.redhat.com [10.34.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3EE4762677; Wed, 4 Oct 2017 10:08:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 94DD3C05567E Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=imammedo@redhat.com From: Igor Mammedov To: qemu-devel@nongnu.org Date: Wed, 4 Oct 2017 12:08:00 +0200 Message-Id: <1507111682-66171-2-git-send-email-imammedo@redhat.com> In-Reply-To: <1507111682-66171-1-git-send-email-imammedo@redhat.com> References: <1506935300-132598-2-git-send-email-imammedo@redhat.com> <1507111682-66171-1-git-send-email-imammedo@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 04 Oct 2017 10:08:08 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 1/3] qom: update doc comment for type_register[_static]() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, ehabkost@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" type_register()/type_register_static() functions in current impl. can't fail returning 0, also none of the users check for error so update doc comment to reflect current behaviour. Suggested-by: Eduardo Habkost Signed-off-by: Igor Mammedov Reviewed-by: Eduardo Habkost --- include/qom/object.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/qom/object.h b/include/qom/object.h index f3e5cff..76a5e3a 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -773,7 +773,7 @@ const char *object_get_typename(const Object *obj); * @info and all of the strings it points to should exist for the life time * that the type is registered. * - * Returns: 0 on failure, the new #Type on success. + * Returns: the new #Type. */ Type type_register_static(const TypeInfo *info); =20 @@ -784,7 +784,7 @@ Type type_register_static(const TypeInfo *info); * Unlike type_register_static(), this call does not require @info or its * string members to continue to exist after the call returns. * - * Returns: 0 on failure, the new #Type on success. + * Returns: the new #Type. */ Type type_register(const TypeInfo *info); =20 --=20 2.7.4 From nobody Thu May 2 09:32:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1507111880362878.7315395667634; Wed, 4 Oct 2017 03:11:20 -0700 (PDT) Received: from localhost ([::1]:34051 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzgdu-0002aC-5u for importer@patchew.org; Wed, 04 Oct 2017 06:11:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40764) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzgb5-0000gn-Ql for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:08:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dzgb4-0005u7-Tx for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:08:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56436) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dzgb4-0005tY-Nv for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:08:10 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DF26B4022E; Wed, 4 Oct 2017 10:08:09 +0000 (UTC) Received: from dell-r430-03.lab.eng.brq.redhat.com (dell-r430-03.lab.eng.brq.redhat.com [10.34.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id DDE4B61F3E; Wed, 4 Oct 2017 10:08:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com DF26B4022E Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=imammedo@redhat.com From: Igor Mammedov To: qemu-devel@nongnu.org Date: Wed, 4 Oct 2017 12:08:01 +0200 Message-Id: <1507111682-66171-3-git-send-email-imammedo@redhat.com> In-Reply-To: <1507111682-66171-1-git-send-email-imammedo@redhat.com> References: <1506935300-132598-2-git-send-email-imammedo@redhat.com> <1507111682-66171-1-git-send-email-imammedo@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 04 Oct 2017 10:08:10 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 2/3] qom: introduce type_register_static_array() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, ehabkost@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" it will help to remove code duplication of registration static types in places that have open coded loop to perform batch type registering. Signed-off-by: Igor Mammedov Reviewed-by: Eduardo Habkost Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/qom/object.h | 10 ++++++++++ qom/object.c | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/include/qom/object.h b/include/qom/object.h index 76a5e3a..ce25567 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -789,6 +789,16 @@ Type type_register_static(const TypeInfo *info); Type type_register(const TypeInfo *info); =20 /** + * type_register_static_array: + * @infos: The array of the new type #TypeInfo structures. + * @nr_infos: number of entries in @infos + * + * @infos and all of the strings it points to should exist for the life ti= me + * that the type is registered. + */ +void type_register_static_array(const TypeInfo *infos, int nr_infos); + +/** * object_class_dynamic_cast_assert: * @klass: The #ObjectClass to attempt to cast. * @typename: The QOM typename of the class to cast to. diff --git a/qom/object.c b/qom/object.c index 3e18537..f4c377a 100644 --- a/qom/object.c +++ b/qom/object.c @@ -151,6 +151,15 @@ TypeImpl *type_register_static(const TypeInfo *info) return type_register(info); } =20 +void type_register_static_array(const TypeInfo *infos, int nr_infos) +{ + int i; + + for (i =3D 0; i < nr_infos; i++) { + type_register_static(&infos[i]); + } +} + static TypeImpl *type_get_by_name(const char *name) { if (name =3D=3D NULL) { --=20 2.7.4 From nobody Thu May 2 09:32:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 150711188218223.24163355112546; Wed, 4 Oct 2017 03:11:22 -0700 (PDT) Received: from localhost ([::1]:34052 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzge0-0002eV-FT for importer@patchew.org; Wed, 04 Oct 2017 06:11:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40777) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzgb7-0000hK-83 for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:08:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dzgb6-0005vD-4Q for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:08:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57232) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dzgb5-0005uk-St for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:08:12 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0B6251E328; Wed, 4 Oct 2017 10:08:11 +0000 (UTC) Received: from dell-r430-03.lab.eng.brq.redhat.com (dell-r430-03.lab.eng.brq.redhat.com [10.34.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 338D262679; Wed, 4 Oct 2017 10:08:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0B6251E328 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=imammedo@redhat.com From: Igor Mammedov To: qemu-devel@nongnu.org Date: Wed, 4 Oct 2017 12:08:02 +0200 Message-Id: <1507111682-66171-4-git-send-email-imammedo@redhat.com> In-Reply-To: <1507111682-66171-1-git-send-email-imammedo@redhat.com> References: <1506935300-132598-2-git-send-email-imammedo@redhat.com> <1507111682-66171-1-git-send-email-imammedo@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 04 Oct 2017 10:08:11 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 3/3] qom: add helper macro DEFINE_TYPES() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, ehabkost@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" DEFINE_TYPES() will help to simplify following routine patterns: static void foo_register_types(void) { type_register_static(&foo1_type_info); type_register_static(&foo2_type_info); ... } type_init(foo_register_types) or static void foo_register_types(void) { int i; for (i =3D 0; i < ARRAY_SIZE(type_infos); i++) { type_register_static(&type_infos[i]); } } type_init(foo_register_types) with a single line DEFINE_TYPES(type_infos) where types have static definition which could be consolidated in a single array of TypeInfo structures. It saves us ~6-10LOC per use case and would help to replace imperative foo_register_types() there with declarative style of type registration. Signed-off-by: Igor Mammedov Reviewed-by: Eduardo Habkost Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/qom/object.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/include/qom/object.h b/include/qom/object.h index ce25567..a615066 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -79,6 +79,28 @@ typedef struct InterfaceInfo InterfaceInfo; * #TypeInfo describes information about the type including what it inheri= ts * from, the instance and class size, and constructor/destructor hooks. * + * Alternatively several static types could be registered using helper mac= ro + * DEFINE_TYPES() + * + * + * + * static const TypeInfo device_types_info[] =3D { + * { + * .name =3D TYPE_MY_DEVICE_A, + * .parent =3D TYPE_DEVICE, + * .instance_size =3D sizeof(MyDeviceA), + * }, + * { + * .name =3D TYPE_MY_DEVICE_B, + * .parent =3D TYPE_DEVICE, + * .instance_size =3D sizeof(MyDeviceB), + * }, + * }; + * + * DEFINE_TYPES(device_types_info) + * + * + * * Every type has an #ObjectClass associated with it. #ObjectClass deriva= tives * are instantiated dynamically but there is only ever one instance for any * given type. The #ObjectClass typically holds a table of function point= ers @@ -799,6 +821,20 @@ Type type_register(const TypeInfo *info); void type_register_static_array(const TypeInfo *infos, int nr_infos); =20 /** + * DEFINE_TYPES: + * @type_array: The array containing #TypeInfo structures to register + * + * @type_array should be static constant that exists for the life time + * that the type is registered. + */ +#define DEFINE_TYPES(type_array) = \ +static void do_qemu_init_ ## type_array(void) = \ +{ = \ + type_register_static_array(type_array, ARRAY_SIZE(type_array)); = \ +} = \ +type_init(do_qemu_init_ ## type_array) + +/** * object_class_dynamic_cast_assert: * @klass: The #ObjectClass to attempt to cast. * @typename: The QOM typename of the class to cast to. --=20 2.7.4