qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eduardo Habkost <ehabkost@redhat.com>
To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	"Daniel P. Berrange" <berrange@redhat.com>
Subject: [PATCH v2 46/58] qom: DECLARE_*_CHECKERS macros
Date: Wed, 19 Aug 2020 20:12:24 -0400	[thread overview]
Message-ID: <20200820001236.1284548-47-ehabkost@redhat.com> (raw)
In-Reply-To: <20200820001236.1284548-1-ehabkost@redhat.com>

Sometimes the typedefs are buried inside another header, but
we want to benefit from the automatic definition of type cast
functions.  Introduce macros that will let type checkers be
defined when typedefs are already available.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Changes v1 -> v2: none
---
 include/qom/object.h | 72 +++++++++++++++++++++++++++++++++++---------
 1 file changed, 58 insertions(+), 14 deletions(-)

diff --git a/include/qom/object.h b/include/qom/object.h
index 500e7dfa99..4cd84998c2 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -553,6 +553,62 @@ struct Object
     Object *parent;
 };
 
+/**
+ * DECLARE_INSTANCE_CHECKER:
+ * @InstanceType: instance struct name
+ * @OBJ_NAME: the object name in uppercase with underscore separators
+ * @TYPENAME: type name
+ *
+ * Direct usage of this macro should be avoided, and the complete
+ * OBJECT_DECLARE_TYPE macro is recommended instead.
+ *
+ * This macro will provide the three standard type cast functions for a
+ * QOM type.
+ */
+#define DECLARE_INSTANCE_CHECKER(InstanceType, OBJ_NAME, TYPENAME) \
+    static inline G_GNUC_UNUSED InstanceType * \
+    OBJ_NAME(void *obj) \
+    { return OBJECT_CHECK(InstanceType, obj, TYPENAME); }
+
+/**
+ * DECLARE_CLASS_CHECKERS:
+ * @ClassType: class struct name
+ * @OBJ_NAME: the object name in uppercase with underscore separators
+ * @TYPENAME: type name
+ *
+ * Direct usage of this macro should be avoided, and the complete
+ * OBJECT_DECLARE_TYPE macro is recommended instead.
+ *
+ * This macro will provide the three standard type cast functions for a
+ * QOM type.
+ */
+#define DECLARE_CLASS_CHECKERS(ClassType, OBJ_NAME, TYPENAME) \
+    static inline G_GNUC_UNUSED ClassType * \
+    OBJ_NAME##_GET_CLASS(void *obj) \
+    { return OBJECT_GET_CLASS(ClassType, obj, TYPENAME); } \
+    \
+    static inline G_GNUC_UNUSED ClassType * \
+    OBJ_NAME##_CLASS(void *klass) \
+    { return OBJECT_CLASS_CHECK(ClassType, klass, TYPENAME); }
+
+/**
+ * DECLARE_OBJ_CHECKERS:
+ * @InstanceType: instance struct name
+ * @ClassType: class struct name
+ * @OBJ_NAME: the object name in uppercase with underscore separators
+ * @TYPENAME: type name
+ *
+ * Direct usage of this macro should be avoided, and the complete
+ * OBJECT_DECLARE_TYPE macro is recommended instead.
+ *
+ * This macro will provide the three standard type cast functions for a
+ * QOM type.
+ */
+#define DECLARE_OBJ_CHECKERS(InstanceType, ClassType, OBJ_NAME, TYPENAME) \
+    DECLARE_INSTANCE_CHECKER(InstanceType, OBJ_NAME, TYPENAME) \
+    \
+    DECLARE_CLASS_CHECKERS(ClassType, OBJ_NAME, TYPENAME)
+
 /**
  * OBJECT_DECLARE_TYPE:
  * @InstanceType: instance struct name
@@ -574,20 +630,8 @@ struct Object
     \
     G_DEFINE_AUTOPTR_CLEANUP_FUNC(InstanceType, object_unref) \
     \
-    static inline G_GNUC_UNUSED ClassType * \
-    MODULE_OBJ_NAME##_GET_CLASS(void *obj) \
-    { return OBJECT_GET_CLASS(ClassType, obj, \
-                              TYPE_##MODULE_OBJ_NAME); } \
-    \
-    static inline G_GNUC_UNUSED ClassType * \
-    MODULE_OBJ_NAME##_CLASS(void *klass) \
-    { return OBJECT_CLASS_CHECK(ClassType, klass, \
-                                TYPE_##MODULE_OBJ_NAME); } \
-    \
-    static inline G_GNUC_UNUSED InstanceType * \
-    MODULE_OBJ_NAME(void *obj) \
-    { return OBJECT_CHECK(InstanceType, obj, \
-                          TYPE_##MODULE_OBJ_NAME); }
+    DECLARE_OBJ_CHECKERS(InstanceType, ClassType, \
+                         MODULE_OBJ_NAME, TYPE_##MODULE_OBJ_NAME)
 
 /**
  * OBJECT_DECLARE_SIMPLE_TYPE:
-- 
2.26.2



  parent reply	other threads:[~2020-08-20  0:31 UTC|newest]

Thread overview: 112+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-20  0:11 [PATCH v2 00/58] qom: Automated conversion of type checking boilerplate Eduardo Habkost
2020-08-20  0:11 ` [PATCH v2 01/58] e1000: Rename QOM class cast macros Eduardo Habkost
2020-08-20  0:11 ` [PATCH v2 02/58] megasas: " Eduardo Habkost
2020-08-20  0:11 ` [PATCH v2 03/58] vmw_pvscsi: " Eduardo Habkost
2020-08-20  0:11 ` [PATCH v2 04/58] pl110: Rename pl110_version enum values Eduardo Habkost
2020-08-20 13:11   ` Philippe Mathieu-Daudé
2020-08-25 11:05   ` Daniel P. Berrangé
2020-08-20  0:11 ` [PATCH v2 05/58] allwinner-h3: Rename memmap enum constants Eduardo Habkost
2020-08-21 19:42   ` Niek Linnenbank
2020-08-25 11:07   ` Daniel P. Berrangé
2020-08-20  0:11 ` [PATCH v2 06/58] aspeed_soc: Rename memmap/irqmap " Eduardo Habkost
2020-08-20  6:41   ` Cédric Le Goater
2020-08-25 11:08   ` Daniel P. Berrangé
2020-08-20  0:11 ` [PATCH v2 07/58] opentitan: Rename memmap " Eduardo Habkost
2020-08-25 11:09   ` Daniel P. Berrangé
2020-08-20  0:11 ` [PATCH v2 08/58] sifive_e: " Eduardo Habkost
2020-08-25 11:10   ` Daniel P. Berrangé
2020-08-20  0:11 ` [PATCH v2 09/58] sifive_u: " Eduardo Habkost
2020-08-25 11:10   ` Daniel P. Berrangé
2020-08-20  0:11 ` [PATCH v2 10/58] aspeed_timer: Fix ASPEED_TIMER macro definition Eduardo Habkost
2020-08-20  6:42   ` Cédric Le Goater
2020-08-20  0:11 ` [PATCH v2 11/58] versatile: Fix typo in PCI_VPB_HOST definition Eduardo Habkost
2020-08-20  0:11 ` [PATCH v2 12/58] virtio-ccw: Fix definition of VIRTIO_CCW_BUS_GET_CLASS Eduardo Habkost
2020-08-21 18:19   ` David Hildenbrand
2020-08-20  0:11 ` [PATCH v2 13/58] hvf: Add missing include Eduardo Habkost
2020-08-20  0:11 ` [PATCH v2 14/58] hcd-dwc2: Rename USB_*CLASS macros for consistency Eduardo Habkost
2020-08-20  0:11 ` [PATCH v2 15/58] tulip: Move TulipState typedef to header Eduardo Habkost
2020-08-20  0:11 ` [PATCH v2 16/58] throttle-groups: Move ThrottleGroup " Eduardo Habkost
2020-08-20  0:11 ` [PATCH v2 17/58] pci: Move PCIBusClass typedef to pci.h Eduardo Habkost
2020-08-20  0:11 ` [PATCH v2 18/58] i8254: Move PITCommonState/PITCommonClass typedefs to i8254.h Eduardo Habkost
2020-08-20  0:11 ` [PATCH v2 19/58] hvf: Move HVFState typedef to hvf.h Eduardo Habkost
2020-08-21 11:17   ` Roman Bolshakov
2020-08-21 11:23   ` Roman Bolshakov
2020-08-25 11:35     ` Eduardo Habkost
2020-08-20  0:11 ` [PATCH v2 20/58] mcf_fec: Move mcf_fec_state typedef to header Eduardo Habkost
2020-08-27  8:09   ` Thomas Huth
2020-08-20  0:11 ` [PATCH v2 21/58] s390_flic: Move KVMS390FLICState " Eduardo Habkost
2020-08-20  0:12 ` [PATCH v2 22/58] can_emu: Delete macros for non-existing typedef Eduardo Habkost
2020-08-20  0:12 ` [PATCH v2 23/58] nubus: Delete unused NUBUS_BRIDGE macro Eduardo Habkost
2020-08-20 15:05   ` Laurent Vivier
2020-08-20  0:12 ` [PATCH v2 24/58] platform-bus: Delete macros for non-existing typedef Eduardo Habkost
2020-08-20  0:12 ` [PATCH v2 25/58] armsse: Rename QOM macros to avoid conflicts Eduardo Habkost
2020-08-25 11:12   ` Daniel P. Berrangé
2020-08-20  0:12 ` [PATCH v2 26/58] xen-legacy-backend: Add missing typedef XenLegacyDevice Eduardo Habkost
2020-08-20 15:34   ` Anthony PERARD via
2020-08-25 11:12   ` Daniel P. Berrangé
2020-08-20  0:12 ` [PATCH v2 27/58] spapr: Move typedef SpaprMachineState to spapr.h Eduardo Habkost
2020-08-25 11:13   ` Daniel P. Berrangé
2020-08-20  0:12 ` [PATCH v2 28/58] s390x: Move typedef SCLPEventFacility to event-facility.h Eduardo Habkost
2020-08-20  7:03   ` Cornelia Huck
2020-08-25 11:13   ` Daniel P. Berrangé
2020-08-20  0:12 ` [PATCH v2 29/58] vhost-user-gpu: Move QOM macro to header Eduardo Habkost
2020-08-20  5:39   ` Gerd Hoffmann
2020-08-25 11:15   ` Daniel P. Berrangé
2020-08-20  0:12 ` [PATCH v2 30/58] ahci: Move QOM macros " Eduardo Habkost
2020-08-25 11:15   ` Daniel P. Berrangé
2020-08-20  0:12 ` [PATCH v2 31/58] i8257: Move QOM macro " Eduardo Habkost
2020-08-25 11:16   ` Daniel P. Berrangé
2020-08-20  0:12 ` [PATCH v2 32/58] ahci: " Eduardo Habkost
2020-08-25 11:16   ` Daniel P. Berrangé
2020-08-20  0:12 ` [PATCH v2 33/58] pckbd: " Eduardo Habkost
2020-08-25 11:16   ` Daniel P. Berrangé
2020-08-20  0:12 ` [PATCH v2 34/58] vmbus: Move QOM macros to vmbus.h Eduardo Habkost
2020-08-25 11:17   ` Daniel P. Berrangé
2020-08-20  0:12 ` [PATCH v2 35/58] virtio-serial-bus: Move QOM macros to header Eduardo Habkost
2020-08-25 11:17   ` Daniel P. Berrangé
2020-08-20  0:12 ` [PATCH v2 36/58] piix: " Eduardo Habkost
2020-08-20 13:13   ` Philippe Mathieu-Daudé
2020-08-25 11:18   ` Daniel P. Berrangé
2020-08-20  0:12 ` [PATCH v2 37/58] auxbus: " Eduardo Habkost
2020-08-25 11:18   ` Daniel P. Berrangé
2020-08-20  0:12 ` [PATCH v2 38/58] rocker: " Eduardo Habkost
2020-08-25 11:19   ` Daniel P. Berrangé
2020-08-20  0:12 ` [PATCH v2 39/58] pxa2xx: " Eduardo Habkost
2020-08-25 11:19   ` Daniel P. Berrangé
2020-08-20  0:12 ` [PATCH v2 40/58] mptsas: " Eduardo Habkost
2020-08-25 11:20   ` Daniel P. Berrangé
2020-08-20  0:12 ` [PATCH v2 41/58] kvm: Move QOM macros to kvm.h Eduardo Habkost
2020-08-25 11:20   ` Daniel P. Berrangé
2020-08-20  0:12 ` [PATCH v2 42/58] vfio/pci: Move QOM macros to header Eduardo Habkost
2020-08-20 13:14   ` Philippe Mathieu-Daudé
2020-08-20 13:14   ` Philippe Mathieu-Daudé
2020-08-25 11:20   ` Daniel P. Berrangé
2020-08-20  0:12 ` [PATCH v2 43/58] qom: make object_ref/unref use a void * instead of Object * Eduardo Habkost
2020-08-20  0:12 ` [PATCH v2 44/58] qom: provide convenient macros for declaring and defining types Eduardo Habkost
2020-08-20 17:45   ` Eduardo Habkost
2020-08-20 17:57     ` Daniel P. Berrangé
2020-08-20 18:48       ` Eduardo Habkost
2020-08-20 18:40     ` Laurent Vivier
2020-08-20  0:12 ` [PATCH v2 45/58] qom: Allow class type name to be specified in OBJECT_DECLARE* Eduardo Habkost
2020-08-20  0:12 ` Eduardo Habkost [this message]
2020-08-20  0:12 ` [PATCH v2 47/58] qom: Make type checker functions accept const pointers Eduardo Habkost
2020-08-20  0:12 ` [PATCH v2 48/58] qom: TYPE_INFO macro Eduardo Habkost
2020-08-20  0:12 ` [PATCH v2 49/58] codeconverter: script for automating QOM code cleanups Eduardo Habkost
2020-08-20  0:12 ` [PATCH v2 50/58] [automated] Delete duplicate QOM typedefs Eduardo Habkost
2020-08-20  0:12 ` [PATCH v2 51/58] [automated] Use TYPE_INFO macro Eduardo Habkost
2020-08-20  0:12 ` [PATCH v2 52/58] [automated] Move QOM typedefs and add missing includes Eduardo Habkost
2020-08-25 11:26   ` Daniel P. Berrangé
2020-08-20  0:12 ` [PATCH v2 53/58] [automated] Use DECLARE_*CHECKER* macros Eduardo Habkost
2020-08-25 11:35   ` Daniel P. Berrangé
2020-08-20  0:12 ` [PATCH v2 54/58] [semi-automated] Use DECLARE_*CHECKER* when possible (--force mode) Eduardo Habkost
2020-08-25 11:43   ` Daniel P. Berrangé
2020-08-20  0:12 ` [PATCH v2 55/58] [automated] Use OBJECT_DECLARE_TYPE where possible Eduardo Habkost
2020-08-25 11:47   ` Daniel P. Berrangé
2020-08-20  0:12 ` [PATCH v2 56/58] [automated] Use OBJECT_DECLARE_SIMPLE_TYPE when possible Eduardo Habkost
2020-08-25 11:49   ` Daniel P. Berrangé
2020-08-20  0:12 ` [PATCH v2 57/58] crypto: use QOM macros for declaration/definition of secret types Eduardo Habkost
2020-08-20  0:12 ` [PATCH v2 58/58] crypto: use QOM macros for declaration/definition of TLS creds types Eduardo Habkost
2020-08-20  0:18 ` [PATCH v2 00/58] qom: Automated conversion of type checking boilerplate Eduardo Habkost
2020-08-20  0:55 ` no-reply
2020-08-20  1:00 ` no-reply
2020-08-20  1:09 ` no-reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200820001236.1284548-47-ehabkost@redhat.com \
    --to=ehabkost@redhat.com \
    --cc=berrange@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).