[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 57/74] qom: DECLARE_*_CHECKERS macros
From: |
Eduardo Habkost |
Subject: |
[PATCH v3 57/74] qom: DECLARE_*_CHECKERS macros |
Date: |
Tue, 25 Aug 2020 15:20:53 -0400 |
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 v2 -> v3: none
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
- [PATCH v3 49/74] swim: Rename struct SWIM to Swim, (continued)
- [PATCH v3 49/74] swim: Rename struct SWIM to Swim, Eduardo Habkost, 2020/08/25
- [PATCH v3 51/74] arm: Fix typo in AARCH64_CPU_GET_CLASS definition, Eduardo Habkost, 2020/08/25
- [PATCH v3 54/74] qom: make object_ref/unref use a void * instead of Object *., Eduardo Habkost, 2020/08/25
- [PATCH v3 52/74] rx: Rename QOM type check macros, Eduardo Habkost, 2020/08/25
- [PATCH v3 56/74] qom: Allow class type name to be specified in OBJECT_DECLARE*, Eduardo Habkost, 2020/08/25
- [PATCH v3 53/74] rx: Move typedef RXCPU to cpu-qom.h, Eduardo Habkost, 2020/08/25
- [PATCH v3 57/74] qom: DECLARE_*_CHECKERS macros,
Eduardo Habkost <=
- [PATCH v3 55/74] qom: provide convenient macros for declaring and defining types, Eduardo Habkost, 2020/08/25
- [PATCH v3 61/74] [automated] Delete duplicate QOM typedefs, Eduardo Habkost, 2020/08/25
- [PATCH v3 58/74] qom: Make type checker functions accept const pointers, Eduardo Habkost, 2020/08/25
- [PATCH v3 59/74] qom: TYPE_INFO macro, Eduardo Habkost, 2020/08/25
- [PATCH v3 60/74] codeconverter: script for automating QOM code cleanups, Eduardo Habkost, 2020/08/25
- [PATCH v3 63/74] [automated] Use TYPE_INFO macro (pass 2), Eduardo Habkost, 2020/08/25
- [PATCH v3 62/74] [automated] Use TYPE_INFO macro, Eduardo Habkost, 2020/08/25
- [PATCH v3 65/74] [automated] Move QOM typedefs and add missing includes (pass 2), Eduardo Habkost, 2020/08/25