diff mbox series

[v3,59/74] qom: TYPE_INFO macro

Message ID 20200825192110.3528606-60-ehabkost@redhat.com
State Superseded
Headers show
Series [v3,01/74] e1000: Rename QOM class cast macros | expand

Commit Message

Eduardo Habkost Aug. 25, 2020, 7:20 p.m. UTC
Provide a TYPE_INFO macro that can be used to register a TypeInfo
struct declaratively.  This will allow QOM type registration to
be 100% declarative.

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 | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/include/qom/object.h b/include/qom/object.h
index 3626ae3c65..3c8fe1b603 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -653,6 +653,14 @@  struct Object
     struct InstanceType##Class { ParentClassType parent_class; };
 
 
+#define TYPE_INFO(type_info_var) \
+    static void \
+    register_type_info_##type_info_var(void) \
+    { \
+        type_register_static(&type_info_var); \
+    } \
+    type_init(register_type_info_##type_info_var);
+
 /**
  * OBJECT_DEFINE_TYPE_EXTENDED:
  * @ModuleObjName: the object name with initial caps
@@ -698,12 +706,7 @@  struct Object
         .interfaces = (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);
+    TYPE_INFO(module_obj_name##_info)
 
 /**
  * OBJECT_DEFINE_TYPE: