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 v4 04/18] qom: DECLARE_*_CHECKERS macros
Date: Mon, 31 Aug 2020 17:07:26 -0400 [thread overview]
Message-ID: <20200831210740.126168-5-ehabkost@redhat.com> (raw)
In-Reply-To: <20200831210740.126168-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 v3 -> v4: none
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
next prev parent reply other threads:[~2020-08-31 21:12 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-31 21:07 [PATCH v4 00/18] qom: Automated conversion of type checking boilerplate Eduardo Habkost
2020-08-31 21:07 ` [PATCH v4 01/18] qom: make object_ref/unref use a void * instead of Object * Eduardo Habkost
2020-08-31 21:07 ` [PATCH v4 02/18] qom: provide convenient macros for declaring and defining types Eduardo Habkost
2020-08-31 21:07 ` [PATCH v4 03/18] qom: Allow class type name to be specified in OBJECT_DECLARE* Eduardo Habkost
2020-08-31 21:07 ` Eduardo Habkost [this message]
2020-08-31 21:07 ` [PATCH v4 05/18] qom: Make type checker functions accept const pointers Eduardo Habkost
2020-08-31 21:07 ` [PATCH v4 06/18] codeconverter: script for automating QOM code cleanups Eduardo Habkost
2020-08-31 21:07 ` [PATCH v4 07/18] [automated] Delete duplicate QOM typedefs Eduardo Habkost
2020-08-31 21:07 ` [PATCH v4 08/18] [automated] Move QOM typedefs and add missing includes Eduardo Habkost
2020-08-31 21:07 ` [PATCH v4 09/18] [automated] Move QOM typedefs and add missing includes (pass 2) Eduardo Habkost
2020-08-31 21:07 ` [PATCH v4 10/18] [automated] Move QOM typedefs and add missing includes (pass 3) Eduardo Habkost
2020-08-31 21:07 ` [PATCH v4 11/18] [automated] Use DECLARE_*CHECKER* macros Eduardo Habkost
2020-08-31 21:07 ` [PATCH v4 12/18] [automated] Use DECLARE_*CHECKER* macros (pass 2) Eduardo Habkost
2020-08-31 21:07 ` [PATCH v4 13/18] [automated] Use DECLARE_*CHECKER* macros (pass 3) Eduardo Habkost
2020-08-31 21:07 ` [PATCH v4 14/18] [semi-automated] Use DECLARE_*CHECKER* when possible (--force mode) Eduardo Habkost
2020-08-31 21:07 ` [PATCH v4 15/18] [automated] Use OBJECT_DECLARE_TYPE where possible Eduardo Habkost
2020-08-31 21:07 ` [PATCH v4 16/18] [automated] Use OBJECT_DECLARE_TYPE where possible (pass 2) Eduardo Habkost
2020-08-31 21:07 ` [PATCH v4 17/18] [automated] Use OBJECT_DECLARE_TYPE where possible (pass 3) Eduardo Habkost
2020-08-31 21:07 ` [PATCH v4 18/18] [automated] Use OBJECT_DECLARE_SIMPLE_TYPE when possible Eduardo Habkost
2020-09-02 16:57 ` [PATCH v4 00/18] qom: Automated conversion of type checking boilerplate Eduardo Habkost
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=20200831210740.126168-5-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).