From nobody Sun May 19 09:23:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1595528132; cv=none; d=zohomail.com; s=zohoarc; b=QJ7MK8Xv4T9j9pNmAW4Z0R0xsTjlcE118NR3wbN4BDPHSMVOOklVMm5pEH8Af491a2kt9mNbtiVFgC2YhXy3rgZvaFhCmOov7J5aY9/1gE59B+M4J5subm3RP0o5Bvf0talv8Q8Vd4Z19NxGBa03py5U83XCVrbij+upwXp7kIY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595528132; h=Content-Type: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=kDXwO5gPlivIb5XB4hL1oqWbFOuIH4X6en9/lBXkT5c=; b=G1anPovbyJsnuY+F2VXj7oedX8pap3T9a0X4W1Nbs2jcCOxybhwCTnSYzma/n4YG1zEeKDbVADfSWX2TVWGEIomozgXUuCduhGTuT4JuSQ1Sj/o+dtEB9+T9DNOI+J6oHAuZcLjapPFdZx2H/EpwzbjCfbn0AyD1iPx8YZrVst0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 15955281326114.3626883249961566; Thu, 23 Jul 2020 11:15:32 -0700 (PDT) Received: from localhost ([::1]:55416 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jyfkh-0007Dp-Am for importer@patchew.org; Thu, 23 Jul 2020 14:15:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50422) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jyfjZ-00068n-VP for qemu-devel@nongnu.org; Thu, 23 Jul 2020 14:14:21 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:43208 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jyfjX-0007hd-9P for qemu-devel@nongnu.org; Thu, 23 Jul 2020 14:14:21 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-57-vK7cqvjJNVeEQ1C95jrBLQ-1; Thu, 23 Jul 2020 14:14:16 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 659B51932481 for ; Thu, 23 Jul 2020 18:14:15 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.36.110.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id D366D1009940; Thu, 23 Jul 2020 18:14:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595528058; 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: in-reply-to:in-reply-to:references:references; bh=kDXwO5gPlivIb5XB4hL1oqWbFOuIH4X6en9/lBXkT5c=; b=UTg7YHsh197boz4cm1Hl+q65wqZL2BIqYr0sNg8N7lQ0EYYjkErs0/bDALCG/RxLZmTs5t k0n4T8TlkI+qY9zv9w5ma39ehEpzselMbJtvyX5If/iKHFlI+XkGS8D5AGDrPyJNo34FpN qGO+7cMhSgvbo/nlYqzyb2XEoDcSJUQ= X-MC-Unique: vK7cqvjJNVeEQ1C95jrBLQ-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH 1/4] qom: make object_ref/unref use a void * instead of Object *. Date: Thu, 23 Jul 2020 19:14:07 +0100 Message-Id: <20200723181410.3145233-2-berrange@redhat.com> In-Reply-To: <20200723181410.3145233-1-berrange@redhat.com> References: <20200723181410.3145233-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=berrange@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" 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=207.211.31.120; envelope-from=berrange@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/22 22:13:02 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, 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_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) The object_ref/unref methods are intended for use with any subclass of the base Object. Using "Object *" in the signature is not adding any meaningful level of type safety, since callers simply use "OBJECT(ptr)" and this expands to an unchecked cast "(Object *)". By using "void *" we enable the object_unref() method to be used to provide support for g_autoptr() with any subclass. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Eric Blake --- include/qom/object.h | 4 ++-- qom/object.c | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/qom/object.h b/include/qom/object.h index 0f3a60617c..1f8aa2d48e 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -1035,7 +1035,7 @@ GSList *object_class_get_list_sorted(const char *impl= ements_type, * as its reference count is greater than zero. * Returns: @obj */ -Object *object_ref(Object *obj); +Object *object_ref(void *obj); =20 /** * object_unref: @@ -1044,7 +1044,7 @@ Object *object_ref(Object *obj); * Decrease the reference count of a object. A object cannot be freed as = long * as its reference count is greater than zero. */ -void object_unref(Object *obj); +void object_unref(void *obj); =20 /** * object_property_try_add: diff --git a/qom/object.c b/qom/object.c index 00fdf89b3b..b1822a2ef4 100644 --- a/qom/object.c +++ b/qom/object.c @@ -1124,8 +1124,9 @@ GSList *object_class_get_list_sorted(const char *impl= ements_type, object_class_cmp); } =20 -Object *object_ref(Object *obj) +Object *object_ref(void *objptr) { + Object *obj =3D OBJECT(objptr); if (!obj) { return NULL; } @@ -1133,8 +1134,9 @@ Object *object_ref(Object *obj) return obj; } =20 -void object_unref(Object *obj) +void object_unref(void *objptr) { + Object *obj =3D OBJECT(objptr); if (!obj) { return; } --=20 2.26.2 From nobody Sun May 19 09:23:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1595528288; cv=none; d=zohomail.com; s=zohoarc; b=cvHm+eNZFBVIC6JONypioukV455/qjjSfuYTWX9dw9feo8Xh2dOdjm1kav1S/XasgTnQwEYSF6EONIhJI4C+DQ/OUTg1/igWZeKPILnx6SNAzVq0IjlVAkTVRhGjvPl6q/ibU7RZxjoR2lvtN1lJzsPTlnmJbaQ3rEqdrm+/qWs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595528288; h=Content-Type: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=MMeXJYEYs4xFb2lV+Tt3NTqziFQLicpm6iTABaQKlsY=; b=AQ4oU0zUFb2EYN57qo4ajiYVUaj5Mb/g+wFSWSbFDg07qAlCshfCExXpR26+40Ks3tp8tsN60D5PfOmzawNUMkYQoBG9dhm5kcg2+TOF5bdE/SLacitxJ8epOSyhLwiSlMLBSbRCMJfjmCOMYc5FvkI7uSFDg1R0c8p617S51HY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1595528288215331.0865360571829; Thu, 23 Jul 2020 11:18:08 -0700 (PDT) Received: from localhost ([::1]:34082 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jyfnC-0001fG-TM for importer@patchew.org; Thu, 23 Jul 2020 14:18:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50484) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jyfjj-0006Kw-5g for qemu-devel@nongnu.org; Thu, 23 Jul 2020 14:14:31 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:34565 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jyfjg-0007kG-MC for qemu-devel@nongnu.org; Thu, 23 Jul 2020 14:14:30 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-137-LBHR2A-4MW-E2QmqeB_WXQ-1; Thu, 23 Jul 2020 14:14:18 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5F5DF80183C for ; Thu, 23 Jul 2020 18:14:17 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.36.110.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id C6DCF1009940; Thu, 23 Jul 2020 18:14:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595528067; 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: in-reply-to:in-reply-to:references:references; bh=MMeXJYEYs4xFb2lV+Tt3NTqziFQLicpm6iTABaQKlsY=; b=ZLmGtowZl/feiJJHsleZILfJW0a058kd9ByL7ZcMqXtEmdgKrnT8UDzgpOnFv7jX7+dZpu 6NPNmN/t358Z7DhSXCCCHsvkpA03wJe88CoN5ZjSiFmdBwKBuIfAk67b/LHUNm2UbrY8MR rh7tva43rI6iBXiynWWBj62jxvG0Mg8= X-MC-Unique: LBHR2A-4MW-E2QmqeB_WXQ-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH 2/4] qom: provide convenient macros for declaring and defining types Date: Thu, 23 Jul 2020 19:14:08 +0100 Message-Id: <20200723181410.3145233-3-berrange@redhat.com> In-Reply-To: <20200723181410.3145233-1-berrange@redhat.com> References: <20200723181410.3145233-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" 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=207.211.31.120; envelope-from=berrange@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/22 22:13:02 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, 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_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) When creating new QOM types, there is a lot of boilerplate code that must be repeated using a standard pattern. This is tedious to write and liable to suffer from subtle inconsistencies. Thus it would benefit from some simple automation. QOM was loosely inspired by GLib's GObject, and indeed GObject suffers from the same burden of boilerplate code, but has long provided a set of macros to eliminate this burden in the source implementation. More recently it has also provided a set of macros to eliminate this burden in the header declaration. In GLib there are the G_DECLARE_* and G_DEFINE_* family of macros for the header declaration and source implementation respectively: https://developer.gnome.org/gobject/stable/chapter-gobject.html https://developer.gnome.org/gobject/stable/howto-gobject.html This patch takes inspiration from GObject to provide the equivalent functionality for QOM. In the header file, instead of: typedef struct MyDevice MyDevice; typedef struct MyDeviceClass MyDeviceClass; G_DEFINE_AUTOPTR_CLEANUP_FUNC(MyDeviceClass, object_unref) #define MY_DEVICE_GET_CLASS(void *obj) \ OBJECT_GET_CLASS(MyDeviceClass, obj, TYPE_MY_DEVICE) #define MY_DEVICE_CLASS(void *klass) \ OBJECT_CLASS_CHECK(MyDeviceClass, klass, TYPE_MY_DEVICE) #define MY_DEVICE(void *obj) OBJECT_CHECK(MyDevice, obj, TYPE_MY_DEVICE) struct MyDeviceClass { DeviceClass parent_class; }; We now have OBJECT_DECLARE_SIMPLE_TYPE(MyDevice, my_device, MY_DEVICE, DEVICE) In cases where the class needs some virtual methods, it can be left to be implemented manually using OBJECT_DECLARE_TYPE(MyDevice, my_device, MY_DEVICE) Note that these macros are including support for g_autoptr() for the object types, which is something previously only supported for variables declared as the base Object * type. Meanwhile in the source file, instead of: static void my_device_finalize(Object *obj); static void my_device_class_init(ObjectClass *oc, void *data); static void my_device_init(Object *obj); static const TypeInfo my_device_info =3D { .parent =3D TYPE_DEVICE, .name =3D TYPE_MY_DEVICE, .instance_size =3D sizeof(MyDevice), .instance_init =3D my_device_init, .instance_finalize =3D my_device_finalize, .class_size =3D sizeof(MyDeviceClass), .class_init =3D my_device_class_init, }; static void my_device_register_types(void) { type_register_static(&my_device_info); } type_init(my_device_register_types); We now have OBJECT_DEFINE_TYPE(MyDevice, my_device, MY_DEVICE, DEVICE) Or, if a class needs to implement interfaces: OBJECT_DEFINE_TYPE_WITH_INTERFACES(MyDevice, my_device, MY_DEVICE, DEVI= CE, { TYPE_USER_CREATABLE }, { NULL }) Or, if a class needs to be abstract OBJECT_DEFINE_ABSTRACT_TYPE(MyDevice, my_device, MY_DEVICE, DEVICE) IOW, in both cases the maintainer now only has to think about the interesting part of the code which implements useful functionality and avoids much of the boilerplate. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Eric Blake --- include/qom/object.h | 277 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 277 insertions(+) diff --git a/include/qom/object.h b/include/qom/object.h index 1f8aa2d48e..be64421089 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -304,6 +304,119 @@ typedef struct InterfaceInfo InterfaceInfo; * * The first example of such a QOM method was #CPUClass.reset, * another example is #DeviceClass.realize. + * + * # Standard type declaration and definition macros # + * + * A lot of the code outlined above follows a standard pattern and naming + * convention. To reduce the amount of boilerplate code that needs to be + * written for a new type there are two sets of macros to generate the + * common parts in a standard format. + * + * A type is declared using the OBJECT_DECLARE macro family. In types + * which do not require any virtual functions in the class, the + * OBJECT_DECLARE_SIMPLE_TYPE macro is suitable, and is commonly placed + * in the header file: + * + * + * Declaring a simple type + * + * OBJECT_DECLARE_SIMPLE_TYPE(MyDevice, my_device, MY_DEVICE, DEVICE) + * + * + * + * This is equivalent to the following: + * + * + * Expansion from declaring a simple type + * + * typedef struct MyDevice MyDevice; + * typedef struct MyDeviceClass MyDeviceClass; + * + * G_DEFINE_AUTOPTR_CLEANUP_FUNC(MyDeviceClass, object_unref) + * + * #define MY_DEVICE_GET_CLASS(void *obj) \ + * OBJECT_GET_CLASS(MyDeviceClass, obj, TYPE_MY_DEVICE) + * #define MY_DEVICE_CLASS(void *klass) \ + * OBJECT_CLASS_CHECK(MyDeviceClass, klass, TYPE_MY_DEVICE) + * #define MY_DEVICE(void *obj) + * OBJECT_CHECK(MyDevice, obj, TYPE_MY_DEVICE) + * + * struct MyDeviceClass { + * DeviceClass parent_class; + * }; + * + * + * + * The 'struct MyDevice' needs to be declared separately. + * If the type requires virtual functions to be declared in the class + * struct, then the alternative OBJECT_DECLARE_TYPE() macro can be + * used. This does the same as OBJECT_DECLARE_SIMPLE_TYPE(), but without + * the 'struct MyDeviceClass' definition. + * + * To implement the type, the OBJECT_DEFINE macro family is available. + * In the simple case the OBJECT_DEFINE_TYPE macro is suitable: + * + * + * Defining a simple type + * + * OBJECT_DEFINE_TYPE(MyDevice, my_device, MY_DEVICE, DEVICE) + * + * + * + * This is equivalent to the following: + * + * + * Expansion from defining a simple type + * + * static void my_device_finalize(Object *obj); + * static void my_device_class_init(ObjectClass *oc, void *data); + * static void my_device_init(Object *obj); + * + * static const TypeInfo my_device_info =3D { + * .parent =3D TYPE_DEVICE, + * .name =3D TYPE_MY_DEVICE, + * .instance_size =3D sizeof(MyDevice), + * .instance_init =3D my_device_init, + * .instance_finalize =3D my_device_finalize, + * .class_size =3D sizeof(MyDeviceClass), + * .class_init =3D my_device_class_init, + * }; + * + * static void + * my_device_register_types(void) + * { + * type_register_static(&my_device_info); + * } + * type_init(my_device_register_types); + * + * + * + * This is sufficient to get the type registered with the type + * system, and the three standard methods now need to be implemented + * along with any other logic required for the type. + * + * If the type needs to implement one or more interfaces, then the + * OBJECT_DEFINE_TYPE_WITH_INTERFACES() macro can be used instead. + * This accepts an array of interface type names. + * + * + * Defining a simple type implementing interfaces + * + * OBJECT_DEFINE_TYPE_WITH_INTERFACES(MyDevice, my_device, + * MY_DEVICE, DEVICE, + * { TYPE_USER_CREATABLE }, { NULL = }) + * + * + * + * If the type is not intended to be instantiated, then then + * the OBJECT_DEFINE_ABSTRACT_TYPE() macro can be used instead: + * + * + * Defining a simple type + * + * OBJECT_DEFINE_ABSTRACT_TYPE(MyDevice, my_device, MY_DEVICE, DEVICE) + * + * */ =20 =20 @@ -440,6 +553,170 @@ struct Object Object *parent; }; =20 +/** + * OBJECT_DECLARE_TYPE: + * @ModuleObjName: the object name with initial capitalization + * @module_obj_name: the object name in lowercase with underscore separato= rs + * @MODULE_OBJ_NAME: the object name in uppercase with underscore separato= rs + * + * This macro is typically used in a header file, and will: + * + * - create the typedefs for the object and class structs + * - register the type for use with g_autoptr + * - provide three standard type cast functions + * + * The object struct and class struct need to be declared manually. + */ +#define OBJECT_DECLARE_TYPE(ModuleObjName, module_obj_name, MODULE_OBJ_NAM= E) \ + typedef struct ModuleObjName ModuleObjName; \ + typedef struct ModuleObjName##Class ModuleObjName##Class; \ + \ + G_DEFINE_AUTOPTR_CLEANUP_FUNC(ModuleObjName##Class, object_unref) \ + \ + static inline G_GNUC_UNUSED ModuleObjName##Class * \ + MODULE_OBJ_NAME##_GET_CLASS(void *obj) \ + { return OBJECT_GET_CLASS(ModuleObjName##Class, obj, \ + TYPE_##MODULE_OBJ_NAME); } \ + \ + static inline G_GNUC_UNUSED ModuleObjName##Class * \ + MODULE_OBJ_NAME##_CLASS(void *klass) \ + { return OBJECT_CLASS_CHECK(ModuleObjName##Class, klass, \ + TYPE_##MODULE_OBJ_NAME); } \ + \ + static inline G_GNUC_UNUSED ModuleObjName * \ + MODULE_OBJ_NAME(void *obj) \ + { return OBJECT_CHECK(ModuleObjName, obj, \ + TYPE_##MODULE_OBJ_NAME); } + +/** + * OBJECT_DECLARE_SIMPLE_TYPE: + * @ModuleObjName: the object name with initial caps + * @module_obj_name: the object name in lowercase with underscore separato= rs + * @MODULE_OBJ_NAME: the object name in uppercase with underscore separato= rs + * @ParentModuleObjName: the parent object name with initial caps + * + * This does the same as OBJECT_DECLARE_TYPE(), but also declares + * the class struct, thus only the object struct needs to be declare + * manually. + * + * This macro should be used unless the class struct needs to have + * virtual methods declared. + */ +#define OBJECT_DECLARE_SIMPLE_TYPE(ModuleObjName, module_obj_name, \ + MODULE_OBJ_NAME, ParentModuleObjName) \ + OBJECT_DECLARE_TYPE(ModuleObjName, module_obj_name, MODULE_OBJ_NAME) \ + struct ModuleObjName##Class { ParentModuleObjName##Class parent_class;= }; + + +/** + * OBJECT_DEFINE_TYPE_EXTENDED: + * @ModuleObjName: the object name with initial caps + * @module_obj_name: the object name in lowercase with underscore separato= rs + * @MODULE_OBJ_NAME: the object name in uppercase with underscore separato= rs + * @PARENT_MODULE_OBJ_NAME: the parent object name in uppercase with under= score + * separators + * @ABSTRACT: boolean flag to indicate whether the object can be instantia= ted + * @...: list of initializers for "InterfaceInfo" to declare implemented i= nterfaces + * + * This macro is typically used in a source file, and will: + * + * - declare prototypes for _finalize, _class_init and _init methods + * - declare the TypeInfo struct instance + * - provide the constructor to register the type + * + * After using this macro, implementations of the _finalize, _class_init, + * and _init methods need to be written. Any of these can be zero-line + * no-op impls if no special logic is required for a given type. + * + * This macro should rarely be used, instead one of the more specialized + * macros is usually a better choice. + */ +#define OBJECT_DEFINE_TYPE_EXTENDED(ModuleObjName, module_obj_name, \ + MODULE_OBJ_NAME, PARENT_MODULE_OBJ_NAM= E, \ + ABSTRACT, ...) \ + static void \ + module_obj_name##_finalize(Object *obj); \ + static void \ + module_obj_name##_class_init(ObjectClass *oc, void *data); \ + static void \ + module_obj_name##_init(Object *obj); \ + \ + static const TypeInfo module_obj_name##_info =3D { \ + .parent =3D TYPE_##PARENT_MODULE_OBJ_NAME, \ + .name =3D TYPE_##MODULE_OBJ_NAME, \ + .instance_size =3D sizeof(ModuleObjName), \ + .instance_init =3D module_obj_name##_init, \ + .instance_finalize =3D module_obj_name##_finalize, \ + .class_size =3D sizeof(ModuleObjName##Class), \ + .class_init =3D module_obj_name##_class_init, \ + .abstract =3D ABSTRACT, \ + .interfaces =3D (InterfaceInfo[]) { __VA_ARGS__ } , \ + }; \ + \ + static void \ + module_obj_name##_register_types(void) \ + { \ + type_register_static(&module_obj_name##_info); \ + } \ + type_init(module_obj_name##_register_types); + +/** + * OBJECT_DEFINE_TYPE: + * @ModuleObjName: the object name with initial caps + * @module_obj_name: the object name in lowercase with underscore separato= rs + * @MODULE_OBJ_NAME: the object name in uppercase with underscore separato= rs + * @PARENT_MODULE_OBJ_NAME: the parent object name in uppercase with under= score + * separators + * + * This is a specialization of OBJECT_DEFINE_TYPE_EXTENDED, which is suita= ble + * for the common case of a non-abstract type, without any interfaces. + */ +#define OBJECT_DEFINE_TYPE(ModuleObjName, module_obj_name, MODULE_OBJ_NAME= , \ + PARENT_MODULE_OBJ_NAME) \ + OBJECT_DEFINE_TYPE_EXTENDED(ModuleObjName, module_obj_name, \ + MODULE_OBJ_NAME, PARENT_MODULE_OBJ_NAME, \ + false, { NULL }) + +/** + * OBJECT_DEFINE_TYPE_WITH_INTERFACES: + * @ModuleObjName: the object name with initial caps + * @module_obj_name: the object name in lowercase with underscore separato= rs + * @MODULE_OBJ_NAME: the object name in uppercase with underscore separato= rs + * @PARENT_MODULE_OBJ_NAME: the parent object name in uppercase with under= score + * separators + * @...: list of initializers for "InterfaceInfo" to declare implemented i= nterfaces + * + * This is a specialization of OBJECT_DEFINE_TYPE_EXTENDED, which is suita= ble + * for the common case of a non-abstract type, with one or more implemented + * interfaces. + * + * Note when passing the list of interfaces, be sure to include the final + * NULL entry, e.g. { TYPE_USER_CREATABLE }, { NULL } + */ +#define OBJECT_DEFINE_TYPE_WITH_INTERFACES(ModuleObjName, module_obj_name,= \ + MODULE_OBJ_NAME, \ + PARENT_MODULE_OBJ_NAME, ...) \ + OBJECT_DEFINE_TYPE_EXTENDED(ModuleObjName, module_obj_name, \ + MODULE_OBJ_NAME, PARENT_MODULE_OBJ_NAME, \ + false, __VA_ARGS__) + +/** + * OBJECT_DEFINE_ABSTRACT_TYPE: + * @ModuleObjName: the object name with initial caps + * @module_obj_name: the object name in lowercase with underscore separato= rs + * @MODULE_OBJ_NAME: the object name in uppercase with underscore separato= rs + * @PARENT_MODULE_OBJ_NAME: the parent object name in uppercase with under= score + * separators + * + * This is a specialization of OBJECT_DEFINE_TYPE_EXTENDED, which is suita= ble + * for defining an abstract type, without any interfaces. + */ +#define OBJECT_DEFINE_ABSTRACT_TYPE(ModuleObjName, module_obj_name, \ + MODULE_OBJ_NAME, PARENT_MODULE_OBJ_NAM= E) \ + OBJECT_DEFINE_TYPE_EXTENDED(ModuleObjName, module_obj_name, \ + MODULE_OBJ_NAME, PARENT_MODULE_OBJ_NAME, \ + true, { NULL }) + /** * TypeInfo: * @name: The name of the type. --=20 2.26.2 From nobody Sun May 19 09:23:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1595528143; cv=none; d=zohomail.com; s=zohoarc; b=Fboubj8mZAwcNxt9/lV61z+oQqGuSyj7QdwFghl2NoXMjU59fvSz0qeRFMP7GnQxaL7volSpfKOmeenwhz5NSJ7eJsqL1b5mF8a03Z5kqluNMIyjBgU133c35fiXv28+NJHjf9csECnfPOC2mOiY2UcogTgL5CYvmyvlgyZbfzk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595528143; h=Content-Type: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=r8YenZwUa/923Ixjz3e6MRLXtghP6xqYYJAJRatjZUc=; b=BYxZhNJoeS0JA2HybcFZjoVJ5Y1NX2JGfr/MXGqBY+IN9I7wG4rupkID0Vrq7zPfHhcpS3hhrfK/GkaOUeww2jLQQYoLInczBZ+/dcF1Li9pduCr7JEdO2QGtyDX6uQDU0ycpR5QhrEiYSbjLvsAAD6Qpb1538mps+hppSE+v+g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1595528143569125.41294942198874; Thu, 23 Jul 2020 11:15:43 -0700 (PDT) Received: from localhost ([::1]:55958 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jyfks-0007R0-B4 for importer@patchew.org; Thu, 23 Jul 2020 14:15:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50450) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jyfje-0006CD-57 for qemu-devel@nongnu.org; Thu, 23 Jul 2020 14:14:26 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:58974 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jyfjc-0007j6-BG for qemu-devel@nongnu.org; Thu, 23 Jul 2020 14:14:25 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-4-AN-cAQmTOZ6DsXyaUiEfCA-1; Thu, 23 Jul 2020 14:14:21 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6C0B58017FB for ; Thu, 23 Jul 2020 18:14:20 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.36.110.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id AC56A1009940; Thu, 23 Jul 2020 18:14:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595528063; 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: in-reply-to:in-reply-to:references:references; bh=r8YenZwUa/923Ixjz3e6MRLXtghP6xqYYJAJRatjZUc=; b=bspntXprBiFA5v7NngdXHF1WkE+aUYs+tTCY+Job/yeztfv6JVL6bBwX4HiUIEMwThdQIi juN+nsz+CMNSG/HqS3ETrRlSIJwNEpoUiQTfeINKa4p56wyZqh2zWWsxm1gqNYN46PDj1d tIBC3BuBFOCzmpHBKIn/DjRlWt8dDcs= X-MC-Unique: AN-cAQmTOZ6DsXyaUiEfCA-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH 3/4] crypto: use QOM macros for declaration/definition of secret types Date: Thu, 23 Jul 2020 19:14:09 +0100 Message-Id: <20200723181410.3145233-4-berrange@redhat.com> In-Reply-To: <20200723181410.3145233-1-berrange@redhat.com> References: <20200723181410.3145233-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=berrange@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" 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=205.139.110.120; envelope-from=berrange@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/23 06:04:25 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -40 X-Spam_score: -4.1 X-Spam_bar: ---- X-Spam_report: (-4.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, 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=-1, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) This introduces the use of the OBJECT_DEFINE and OBJECT_DECLARE macro families in the secret types, in order to eliminate boilerplate code. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Eric Blake --- crypto/secret.c | 24 ++++-------------------- crypto/secret_common.c | 32 +++++++++----------------------- crypto/secret_keyring.c | 28 +++++++++------------------- include/crypto/secret.h | 11 ++--------- include/crypto/secret_common.h | 13 ++----------- include/crypto/secret_keyring.h | 18 ++---------------- 6 files changed, 28 insertions(+), 98 deletions(-) diff --git a/crypto/secret.c b/crypto/secret.c index 281cb81f0f..55b406f79e 100644 --- a/crypto/secret.c +++ b/crypto/secret.c @@ -25,6 +25,9 @@ #include "qemu/module.h" #include "trace.h" =20 +OBJECT_DEFINE_TYPE_WITH_INTERFACES(QCryptoSecret, qcrypto_secret, + QCRYPTO_SECRET, QCRYPTO_SECRET_COMMON, + { TYPE_USER_CREATABLE }, { NULL }) =20 static void qcrypto_secret_load_data(QCryptoSecretCommon *sec_common, @@ -140,26 +143,7 @@ qcrypto_secret_class_init(ObjectClass *oc, void *data) qcrypto_secret_prop_set_file); } =20 - -static const TypeInfo qcrypto_secret_info =3D { - .parent =3D TYPE_QCRYPTO_SECRET_COMMON, - .name =3D TYPE_QCRYPTO_SECRET, - .instance_size =3D sizeof(QCryptoSecret), - .instance_finalize =3D qcrypto_secret_finalize, - .class_size =3D sizeof(QCryptoSecretClass), - .class_init =3D qcrypto_secret_class_init, - .interfaces =3D (InterfaceInfo[]) { - { TYPE_USER_CREATABLE }, - { } - } -}; - - static void -qcrypto_secret_register_types(void) +qcrypto_secret_init(Object *obj) { - type_register_static(&qcrypto_secret_info); } - - -type_init(qcrypto_secret_register_types); diff --git a/crypto/secret_common.c b/crypto/secret_common.c index b03d530867..9a054b90b5 100644 --- a/crypto/secret_common.c +++ b/crypto/secret_common.c @@ -28,6 +28,9 @@ #include "trace.h" =20 =20 +OBJECT_DEFINE_ABSTRACT_TYPE(QCryptoSecretCommon, qcrypto_secret_common, + QCRYPTO_SECRET_COMMON, OBJECT) + static void qcrypto_secret_decrypt(QCryptoSecretCommon *secret, const uint8_t *input, size_t inputlen, @@ -269,7 +272,7 @@ qcrypto_secret_prop_get_keyid(Object *obj, =20 =20 static void -qcrypto_secret_finalize(Object *obj) +qcrypto_secret_common_finalize(Object *obj) { QCryptoSecretCommon *secret =3D QCRYPTO_SECRET_COMMON(obj); =20 @@ -279,7 +282,7 @@ qcrypto_secret_finalize(Object *obj) } =20 static void -qcrypto_secret_class_init(ObjectClass *oc, void *data) +qcrypto_secret_common_class_init(ObjectClass *oc, void *data) { object_class_property_add_bool(oc, "loaded", qcrypto_secret_prop_get_loaded, @@ -297,6 +300,10 @@ qcrypto_secret_class_init(ObjectClass *oc, void *data) qcrypto_secret_prop_set_iv); } =20 +static void +qcrypto_secret_common_init(Object *obj) +{ +} =20 int qcrypto_secret_lookup(const char *secretid, uint8_t **data, @@ -380,24 +387,3 @@ char *qcrypto_secret_lookup_as_base64(const char *secr= etid, g_free(data); return ret; } - - -static const TypeInfo qcrypto_secret_info =3D { - .parent =3D TYPE_OBJECT, - .name =3D TYPE_QCRYPTO_SECRET_COMMON, - .instance_size =3D sizeof(QCryptoSecretCommon), - .instance_finalize =3D qcrypto_secret_finalize, - .class_size =3D sizeof(QCryptoSecretCommonClass), - .class_init =3D qcrypto_secret_class_init, - .abstract =3D true, -}; - - -static void -qcrypto_secret_register_types(void) -{ - type_register_static(&qcrypto_secret_info); -} - - -type_init(qcrypto_secret_register_types); diff --git a/crypto/secret_keyring.c b/crypto/secret_keyring.c index 8bfc58ebf4..463aefe5dc 100644 --- a/crypto/secret_keyring.c +++ b/crypto/secret_keyring.c @@ -26,6 +26,9 @@ #include "trace.h" #include "crypto/secret_keyring.h" =20 +OBJECT_DEFINE_TYPE_WITH_INTERFACES(QCryptoSecretKeyring, qcrypto_secret_ke= yring, + QCRYPTO_SECRET_KEYRING, QCRYPTO_SECRET_= COMMON, + { TYPE_USER_CREATABLE }, { NULL }) =20 static inline long keyctl_read(int32_t key, uint8_t *buffer, size_t buflen) @@ -109,6 +112,11 @@ qcrypto_secret_keyring_complete(UserCreatable *uc, Err= or **errp) } =20 =20 +static void +qcrypto_secret_keyring_finalize(Object *obj) +{ +} + static void qcrypto_secret_keyring_class_init(ObjectClass *oc, void *data) { @@ -124,25 +132,7 @@ qcrypto_secret_keyring_class_init(ObjectClass *oc, voi= d *data) NULL, NULL); } =20 - -static const TypeInfo qcrypto_secret_info =3D { - .parent =3D TYPE_QCRYPTO_SECRET_COMMON, - .name =3D TYPE_QCRYPTO_SECRET_KEYRING, - .instance_size =3D sizeof(QCryptoSecretKeyring), - .class_size =3D sizeof(QCryptoSecretKeyringClass), - .class_init =3D qcrypto_secret_keyring_class_init, - .interfaces =3D (InterfaceInfo[]) { - { TYPE_USER_CREATABLE }, - { } - } -}; - - static void -qcrypto_secret_register_types(void) +qcrypto_secret_keyring_init(Object *obj) { - type_register_static(&qcrypto_secret_info); } - - -type_init(qcrypto_secret_register_types); diff --git a/include/crypto/secret.h b/include/crypto/secret.h index 2deb461d2f..4eb4e5ffef 100644 --- a/include/crypto/secret.h +++ b/include/crypto/secret.h @@ -26,11 +26,9 @@ #include "crypto/secret_common.h" =20 #define TYPE_QCRYPTO_SECRET "secret" -#define QCRYPTO_SECRET(obj) \ - OBJECT_CHECK(QCryptoSecret, (obj), TYPE_QCRYPTO_SECRET) =20 -typedef struct QCryptoSecret QCryptoSecret; -typedef struct QCryptoSecretClass QCryptoSecretClass; +OBJECT_DECLARE_SIMPLE_TYPE(QCryptoSecret, qcrypto_secret, + QCRYPTO_SECRET, QCryptoSecretCommon) =20 /** * QCryptoSecret: @@ -125,9 +123,4 @@ struct QCryptoSecret { char *file; }; =20 - -struct QCryptoSecretClass { - QCryptoSecretCommonClass parent_class; -}; - #endif /* QCRYPTO_SECRET_H */ diff --git a/include/crypto/secret_common.h b/include/crypto/secret_common.h index 980c02ab71..999a6b4651 100644 --- a/include/crypto/secret_common.h +++ b/include/crypto/secret_common.h @@ -25,17 +25,8 @@ #include "qom/object.h" =20 #define TYPE_QCRYPTO_SECRET_COMMON "secret_common" -#define QCRYPTO_SECRET_COMMON(obj) \ - OBJECT_CHECK(QCryptoSecretCommon, (obj), TYPE_QCRYPTO_SECRET_COMMON) -#define QCRYPTO_SECRET_COMMON_CLASS(class) \ - OBJECT_CLASS_CHECK(QCryptoSecretCommonClass, \ - (class), TYPE_QCRYPTO_SECRET_COMMON) -#define QCRYPTO_SECRET_COMMON_GET_CLASS(obj) \ - OBJECT_GET_CLASS(QCryptoSecretCommonClass, \ - (obj), TYPE_QCRYPTO_SECRET_COMMON) - -typedef struct QCryptoSecretCommon QCryptoSecretCommon; -typedef struct QCryptoSecretCommonClass QCryptoSecretCommonClass; +OBJECT_DECLARE_TYPE(QCryptoSecretCommon, qcrypto_secret_common, + QCRYPTO_SECRET_COMMON) =20 struct QCryptoSecretCommon { Object parent_obj; diff --git a/include/crypto/secret_keyring.h b/include/crypto/secret_keyrin= g.h index 9f371ad251..4470306853 100644 --- a/include/crypto/secret_keyring.h +++ b/include/crypto/secret_keyring.h @@ -26,18 +26,8 @@ #include "crypto/secret_common.h" =20 #define TYPE_QCRYPTO_SECRET_KEYRING "secret_keyring" -#define QCRYPTO_SECRET_KEYRING(obj) \ - OBJECT_CHECK(QCryptoSecretKeyring, (obj), \ - TYPE_QCRYPTO_SECRET_KEYRING) -#define QCRYPTO_SECRET_KEYRING_CLASS(class) \ - OBJECT_CLASS_CHECK(QCryptoSecretKeyringClass, \ - (class), TYPE_QCRYPTO_SECRET_KEYRING) -#define QCRYPTO_SECRET_KEYRING_GET_CLASS(class) \ - OBJECT_GET_CLASS(QCryptoSecretKeyringClass, \ - (class), TYPE_QCRYPTO_SECRET_KEYRING) - -typedef struct QCryptoSecretKeyring QCryptoSecretKeyring; -typedef struct QCryptoSecretKeyringClass QCryptoSecretKeyringClass; +OBJECT_DECLARE_SIMPLE_TYPE(QCryptoSecretKeyring, qcrypto_secret_keyring, + QCRYPTO_SECRET_KEYRING, QCryptoSecretCommon) =20 typedef struct QCryptoSecretKeyring { QCryptoSecretCommon parent; @@ -45,8 +35,4 @@ typedef struct QCryptoSecretKeyring { } QCryptoSecretKeyring; =20 =20 -typedef struct QCryptoSecretKeyringClass { - QCryptoSecretCommonClass parent; -} QCryptoSecretKeyringClass; - #endif /* QCRYPTO_SECRET_KEYRING_H */ --=20 2.26.2 From nobody Sun May 19 09:23:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1595528146; cv=none; d=zohomail.com; s=zohoarc; b=VRX13nPbnX80sgLMIewIUSvZw2gWLzOFaoiUrip2PPNo9+sQOKE8Ud5j8PeQHh4IkKLY/Y13iIXeTi8TYsOiZapGMKGJV8q6CPEBw1Qr1n4IBU1ur56/uMThgiVkDnGDgpUWWbgDWqfh8P4EncG0ey+kQaOO3yTyLMPadM+V8lo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595528146; h=Content-Type: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=s/9W4aKIzNmcUYxEK12c4NQy4bbOENp8nQF3Nb267To=; b=NetlUhw2HmVY/7oncj+7GGLjb49YS4FyQvEDISnbKYJ5BN2FKE4kMUtKI/P7qoc9KZG4bFfw6pSnvHOSEzePm+BUuFuewtZmNus2FBKzFAIOoXBGKQGwlzJ9xKP1wU//Gxr50ZGBC+zg2gh6GBe2OgKUJrohmRsZ3uxoZ8Qcy24= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1595528146337143.02357037568754; Thu, 23 Jul 2020 11:15:46 -0700 (PDT) Received: from localhost ([::1]:56222 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jyfkv-0007Y7-1z for importer@patchew.org; Thu, 23 Jul 2020 14:15:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50468) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jyfjf-0006Ef-W2 for qemu-devel@nongnu.org; Thu, 23 Jul 2020 14:14:28 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:41638 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jyfjd-0007jy-W5 for qemu-devel@nongnu.org; Thu, 23 Jul 2020 14:14:27 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-286-bXS_s7ETNgyjDp6O84WpFg-1; Thu, 23 Jul 2020 14:14:23 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 583E9100AA26 for ; Thu, 23 Jul 2020 18:14:22 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.36.110.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id B45F01009940; Thu, 23 Jul 2020 18:14:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595528065; 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: in-reply-to:in-reply-to:references:references; bh=s/9W4aKIzNmcUYxEK12c4NQy4bbOENp8nQF3Nb267To=; b=WvnyAbXABj9/dpTk7HmCNNhUBjSgylmjX6Er/gmMFe3o+0TFEiSL6bo/A0n4HXn0RpW6LP LmyrKIYPQrz7zbirc5Xa4iTNsKdr18DKUNaerPTZwKnD/M8veslX5rxQB9Dot6TetR9Yc1 RWf5pau7uYaXC3RHw5tQ7yJLqweqpbs= X-MC-Unique: bXS_s7ETNgyjDp6O84WpFg-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH 4/4] crypto: use QOM macros for declaration/definition of TLS creds types Date: Thu, 23 Jul 2020 19:14:10 +0100 Message-Id: <20200723181410.3145233-5-berrange@redhat.com> In-Reply-To: <20200723181410.3145233-1-berrange@redhat.com> References: <20200723181410.3145233-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" 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=205.139.110.61; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/23 02:33:29 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -40 X-Spam_score: -4.1 X-Spam_bar: ---- X-Spam_report: (-4.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, 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=-1, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) This introduces the use of the OBJECT_DEFINE and OBJECT_DECLARE macro families in the TLS creds types, in order to eliminate boilerplate code. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Eric Blake --- crypto/tlscreds.c | 25 +++---------------------- crypto/tlscredsanon.c | 23 ++++------------------- crypto/tlscredspsk.c | 25 +++++-------------------- crypto/tlscredsx509.c | 29 ++++------------------------- include/crypto/tlscreds.h | 13 ++----------- include/crypto/tlscredsanon.h | 14 ++------------ include/crypto/tlscredspsk.h | 13 ++----------- include/crypto/tlscredsx509.h | 13 ++----------- 8 files changed, 24 insertions(+), 131 deletions(-) diff --git a/crypto/tlscreds.c b/crypto/tlscreds.c index b68735f06f..c238ff7d4b 100644 --- a/crypto/tlscreds.c +++ b/crypto/tlscreds.c @@ -24,6 +24,9 @@ #include "tlscredspriv.h" #include "trace.h" =20 +OBJECT_DEFINE_ABSTRACT_TYPE(QCryptoTLSCreds, qcrypto_tls_creds, + QCRYPTO_TLS_CREDS, OBJECT) + #define DH_BITS 2048 =20 #ifdef CONFIG_GNUTLS @@ -258,25 +261,3 @@ qcrypto_tls_creds_finalize(Object *obj) g_free(creds->dir); g_free(creds->priority); } - - -static const TypeInfo qcrypto_tls_creds_info =3D { - .parent =3D TYPE_OBJECT, - .name =3D TYPE_QCRYPTO_TLS_CREDS, - .instance_size =3D sizeof(QCryptoTLSCreds), - .instance_init =3D qcrypto_tls_creds_init, - .instance_finalize =3D qcrypto_tls_creds_finalize, - .class_init =3D qcrypto_tls_creds_class_init, - .class_size =3D sizeof(QCryptoTLSCredsClass), - .abstract =3D true, -}; - - -static void -qcrypto_tls_creds_register_types(void) -{ - type_register_static(&qcrypto_tls_creds_info); -} - - -type_init(qcrypto_tls_creds_register_types); diff --git a/crypto/tlscredsanon.c b/crypto/tlscredsanon.c index 30275b6847..dc1b77e37c 100644 --- a/crypto/tlscredsanon.c +++ b/crypto/tlscredsanon.c @@ -26,6 +26,9 @@ #include "qom/object_interfaces.h" #include "trace.h" =20 +OBJECT_DEFINE_TYPE_WITH_INTERFACES(QCryptoTLSCredsAnon, qcrypto_tls_creds_= anon, + QCRYPTO_TLS_CREDS_ANON, QCRYPTO_TLS_CRE= DS, + { TYPE_USER_CREATABLE }, { NULL }) =20 #ifdef CONFIG_GNUTLS =20 @@ -191,25 +194,7 @@ qcrypto_tls_creds_anon_class_init(ObjectClass *oc, voi= d *data) } =20 =20 -static const TypeInfo qcrypto_tls_creds_anon_info =3D { - .parent =3D TYPE_QCRYPTO_TLS_CREDS, - .name =3D TYPE_QCRYPTO_TLS_CREDS_ANON, - .instance_size =3D sizeof(QCryptoTLSCredsAnon), - .instance_finalize =3D qcrypto_tls_creds_anon_finalize, - .class_size =3D sizeof(QCryptoTLSCredsAnonClass), - .class_init =3D qcrypto_tls_creds_anon_class_init, - .interfaces =3D (InterfaceInfo[]) { - { TYPE_USER_CREATABLE }, - { } - } -}; - - static void -qcrypto_tls_creds_anon_register_types(void) +qcrypto_tls_creds_anon_init(Object *obj) { - type_register_static(&qcrypto_tls_creds_anon_info); } - - -type_init(qcrypto_tls_creds_anon_register_types); diff --git a/crypto/tlscredspsk.c b/crypto/tlscredspsk.c index e26807b899..0c66be3647 100644 --- a/crypto/tlscredspsk.c +++ b/crypto/tlscredspsk.c @@ -27,6 +27,10 @@ #include "trace.h" =20 =20 +OBJECT_DEFINE_TYPE_WITH_INTERFACES(QCryptoTLSCredsPSK, qcrypto_tls_creds_p= sk, + QCRYPTO_TLS_CREDS_PSK, QCRYPTO_TLS_CRED= S, + { TYPE_USER_CREATABLE }, { NULL }) + #ifdef CONFIG_GNUTLS =20 static int @@ -281,26 +285,7 @@ qcrypto_tls_creds_psk_class_init(ObjectClass *oc, void= *data) qcrypto_tls_creds_psk_prop_set_username); } =20 - -static const TypeInfo qcrypto_tls_creds_psk_info =3D { - .parent =3D TYPE_QCRYPTO_TLS_CREDS, - .name =3D TYPE_QCRYPTO_TLS_CREDS_PSK, - .instance_size =3D sizeof(QCryptoTLSCredsPSK), - .instance_finalize =3D qcrypto_tls_creds_psk_finalize, - .class_size =3D sizeof(QCryptoTLSCredsPSKClass), - .class_init =3D qcrypto_tls_creds_psk_class_init, - .interfaces =3D (InterfaceInfo[]) { - { TYPE_USER_CREATABLE }, - { } - } -}; - - static void -qcrypto_tls_creds_psk_register_types(void) +qcrypto_tls_creds_psk_init(Object *obj) { - type_register_static(&qcrypto_tls_creds_psk_info); } - - -type_init(qcrypto_tls_creds_psk_register_types); diff --git a/crypto/tlscredsx509.c b/crypto/tlscredsx509.c index dd7267ccdb..a39555e5e6 100644 --- a/crypto/tlscredsx509.c +++ b/crypto/tlscredsx509.c @@ -28,6 +28,10 @@ #include "trace.h" =20 =20 +OBJECT_DEFINE_TYPE_WITH_INTERFACES(QCryptoTLSCredsX509, qcrypto_tls_creds_= x509, + QCRYPTO_TLS_CREDS_X509, QCRYPTO_TLS_CRE= DS, + { TYPE_USER_CREATABLE }, { NULL }) + #ifdef CONFIG_GNUTLS =20 #include @@ -814,28 +818,3 @@ qcrypto_tls_creds_x509_class_init(ObjectClass *oc, voi= d *data) qcrypto_tls_creds_x509_prop_get_password= id, qcrypto_tls_creds_x509_prop_set_password= id); } - - -static const TypeInfo qcrypto_tls_creds_x509_info =3D { - .parent =3D TYPE_QCRYPTO_TLS_CREDS, - .name =3D TYPE_QCRYPTO_TLS_CREDS_X509, - .instance_size =3D sizeof(QCryptoTLSCredsX509), - .instance_init =3D qcrypto_tls_creds_x509_init, - .instance_finalize =3D qcrypto_tls_creds_x509_finalize, - .class_size =3D sizeof(QCryptoTLSCredsX509Class), - .class_init =3D qcrypto_tls_creds_x509_class_init, - .interfaces =3D (InterfaceInfo[]) { - { TYPE_USER_CREATABLE }, - { } - } -}; - - -static void -qcrypto_tls_creds_x509_register_types(void) -{ - type_register_static(&qcrypto_tls_creds_x509_info); -} - - -type_init(qcrypto_tls_creds_x509_register_types); diff --git a/include/crypto/tlscreds.h b/include/crypto/tlscreds.h index fd7a284aa2..e9b9b8c20a 100644 --- a/include/crypto/tlscreds.h +++ b/include/crypto/tlscreds.h @@ -29,11 +29,8 @@ #endif =20 #define TYPE_QCRYPTO_TLS_CREDS "tls-creds" -#define QCRYPTO_TLS_CREDS(obj) \ - OBJECT_CHECK(QCryptoTLSCreds, (obj), TYPE_QCRYPTO_TLS_CREDS) - -typedef struct QCryptoTLSCreds QCryptoTLSCreds; -typedef struct QCryptoTLSCredsClass QCryptoTLSCredsClass; +OBJECT_DECLARE_SIMPLE_TYPE(QCryptoTLSCreds, qcrypto_tls_creds, + QCRYPTO_TLS_CREDS, Object) =20 #define QCRYPTO_TLS_CREDS_DH_PARAMS "dh-params.pem" =20 @@ -58,10 +55,4 @@ struct QCryptoTLSCreds { char *priority; }; =20 - -struct QCryptoTLSCredsClass { - ObjectClass parent_class; -}; - - #endif /* QCRYPTO_TLSCREDS_H */ diff --git a/include/crypto/tlscredsanon.h b/include/crypto/tlscredsanon.h index 9e9a5ce1a8..e366132b6b 100644 --- a/include/crypto/tlscredsanon.h +++ b/include/crypto/tlscredsanon.h @@ -24,12 +24,8 @@ #include "crypto/tlscreds.h" =20 #define TYPE_QCRYPTO_TLS_CREDS_ANON "tls-creds-anon" -#define QCRYPTO_TLS_CREDS_ANON(obj) \ - OBJECT_CHECK(QCryptoTLSCredsAnon, (obj), TYPE_QCRYPTO_TLS_CREDS_ANON) - - -typedef struct QCryptoTLSCredsAnon QCryptoTLSCredsAnon; -typedef struct QCryptoTLSCredsAnonClass QCryptoTLSCredsAnonClass; +OBJECT_DECLARE_SIMPLE_TYPE(QCryptoTLSCredsAnon, qcrypto_tls_creds_anon, + QCRYPTO_TLS_CREDS_ANON, QCryptoTLSCreds) =20 /** * QCryptoTLSCredsAnon: @@ -102,10 +98,4 @@ struct QCryptoTLSCredsAnon { #endif }; =20 - -struct QCryptoTLSCredsAnonClass { - QCryptoTLSCredsClass parent_class; -}; - - #endif /* QCRYPTO_TLSCREDSANON_H */ diff --git a/include/crypto/tlscredspsk.h b/include/crypto/tlscredspsk.h index 907035a29b..0754c6c2d5 100644 --- a/include/crypto/tlscredspsk.h +++ b/include/crypto/tlscredspsk.h @@ -24,11 +24,8 @@ #include "crypto/tlscreds.h" =20 #define TYPE_QCRYPTO_TLS_CREDS_PSK "tls-creds-psk" -#define QCRYPTO_TLS_CREDS_PSK(obj) \ - OBJECT_CHECK(QCryptoTLSCredsPSK, (obj), TYPE_QCRYPTO_TLS_CREDS_PSK) - -typedef struct QCryptoTLSCredsPSK QCryptoTLSCredsPSK; -typedef struct QCryptoTLSCredsPSKClass QCryptoTLSCredsPSKClass; +OBJECT_DECLARE_SIMPLE_TYPE(QCryptoTLSCredsPSK, qcrypto_tls_creds_psk, + QCRYPTO_TLS_CREDS_PSK, QCryptoTLSCreds) =20 #define QCRYPTO_TLS_CREDS_PSKFILE "keys.psk" =20 @@ -97,10 +94,4 @@ struct QCryptoTLSCredsPSK { #endif }; =20 - -struct QCryptoTLSCredsPSKClass { - QCryptoTLSCredsClass parent_class; -}; - - #endif /* QCRYPTO_TLSCREDSPSK_H */ diff --git a/include/crypto/tlscredsx509.h b/include/crypto/tlscredsx509.h index e1542e5c8c..307b169710 100644 --- a/include/crypto/tlscredsx509.h +++ b/include/crypto/tlscredsx509.h @@ -24,11 +24,8 @@ #include "crypto/tlscreds.h" =20 #define TYPE_QCRYPTO_TLS_CREDS_X509 "tls-creds-x509" -#define QCRYPTO_TLS_CREDS_X509(obj) \ - OBJECT_CHECK(QCryptoTLSCredsX509, (obj), TYPE_QCRYPTO_TLS_CREDS_X509) - -typedef struct QCryptoTLSCredsX509 QCryptoTLSCredsX509; -typedef struct QCryptoTLSCredsX509Class QCryptoTLSCredsX509Class; +OBJECT_DECLARE_SIMPLE_TYPE(QCryptoTLSCredsX509, qcrypto_tls_creds_x509, + QCRYPTO_TLS_CREDS_X509, QCryptoTLSCreds) =20 #define QCRYPTO_TLS_CREDS_X509_CA_CERT "ca-cert.pem" #define QCRYPTO_TLS_CREDS_X509_CA_CRL "ca-crl.pem" @@ -104,10 +101,4 @@ struct QCryptoTLSCredsX509 { char *passwordid; }; =20 - -struct QCryptoTLSCredsX509Class { - QCryptoTLSCredsClass parent_class; -}; - - #endif /* QCRYPTO_TLSCREDSX509_H */ --=20 2.26.2