diff mbox series

[PULL,14/17] qom: Remove ParentClassType argument from OBJECT_DECLARE_SIMPLE_TYPE

Message ID 20200918204714.27276-15-ehabkost@redhat.com
State New
Headers show
Series QOM queue, 2020-09-18 | expand

Commit Message

Eduardo Habkost Sept. 18, 2020, 8:47 p.m. UTC
The requirement to specify the parent class type makes the macro
harder to use and easy to misuse (silent bugs can be introduced
if the wrong struct type is specified).

Simplify the macro by just not declaring any class struct,
allowing us to remove the class_size field from the TypeInfo
variables for those types.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20200916182519.415636-3-ehabkost@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 include/authz/list.h                |  2 +-
 include/authz/listfile.h            |  2 +-
 include/authz/pamacct.h             |  2 +-
 include/authz/simple.h              |  2 +-
 include/crypto/secret_keyring.h     |  2 +-
 include/io/dns-resolver.h           |  2 +-
 include/io/net-listener.h           |  2 +-
 include/qom/object.h                | 16 ++++++++--------
 include/sysemu/vhost-user-backend.h |  2 +-
 authz/list.c                        |  1 -
 authz/listfile.c                    |  1 -
 authz/pamacct.c                     |  1 -
 authz/simple.c                      |  1 -
 backends/dbus-vmstate.c             |  3 +--
 backends/vhost-user.c               |  1 -
 crypto/secret_keyring.c             |  1 -
 io/dns-resolver.c                   |  1 -
 io/net-listener.c                   |  1 -
 ui/input-barrier.c                  |  3 +--
 ui/input-linux.c                    |  3 +--
 20 files changed, 19 insertions(+), 30 deletions(-)
diff mbox series

Patch

diff --git a/include/authz/list.h b/include/authz/list.h
index 5676bb375c..c5eda0f1bf 100644
--- a/include/authz/list.h
+++ b/include/authz/list.h
@@ -28,7 +28,7 @@ 
 #define TYPE_QAUTHZ_LIST "authz-list"
 
 OBJECT_DECLARE_SIMPLE_TYPE(QAuthZList, qauthz_list,
-                           QAUTHZ_LIST, QAuthZClass)
+                           QAUTHZ_LIST)
 
 
 
diff --git a/include/authz/listfile.h b/include/authz/listfile.h
index b491227bbe..83d78cfa50 100644
--- a/include/authz/listfile.h
+++ b/include/authz/listfile.h
@@ -28,7 +28,7 @@ 
 #define TYPE_QAUTHZ_LIST_FILE "authz-list-file"
 
 OBJECT_DECLARE_SIMPLE_TYPE(QAuthZListFile, qauthz_list_file,
-                           QAUTHZ_LIST_FILE, QAuthZClass)
+                           QAUTHZ_LIST_FILE)
 
 
 
diff --git a/include/authz/pamacct.h b/include/authz/pamacct.h
index 7804853ddf..18087cee20 100644
--- a/include/authz/pamacct.h
+++ b/include/authz/pamacct.h
@@ -28,7 +28,7 @@ 
 #define TYPE_QAUTHZ_PAM "authz-pam"
 
 OBJECT_DECLARE_SIMPLE_TYPE(QAuthZPAM, qauthz_pam,
-                           QAUTHZ_PAM, QAuthZClass)
+                           QAUTHZ_PAM)
 
 
 
diff --git a/include/authz/simple.h b/include/authz/simple.h
index 346fcb0c6c..d3ed05b36f 100644
--- a/include/authz/simple.h
+++ b/include/authz/simple.h
@@ -27,7 +27,7 @@ 
 #define TYPE_QAUTHZ_SIMPLE "authz-simple"
 
 OBJECT_DECLARE_SIMPLE_TYPE(QAuthZSimple, qauthz_simple,
-                           QAUTHZ_SIMPLE, QAuthZClass)
+                           QAUTHZ_SIMPLE)
 
 
 
diff --git a/include/crypto/secret_keyring.h b/include/crypto/secret_keyring.h
index 73d2a8f501..803f3fc28b 100644
--- a/include/crypto/secret_keyring.h
+++ b/include/crypto/secret_keyring.h
@@ -27,7 +27,7 @@ 
 
 #define TYPE_QCRYPTO_SECRET_KEYRING "secret_keyring"
 OBJECT_DECLARE_SIMPLE_TYPE(QCryptoSecretKeyring, qcrypto_secret_keyring,
-                           QCRYPTO_SECRET_KEYRING, QCryptoSecretCommonClass)
+                           QCRYPTO_SECRET_KEYRING)
 
 
 struct QCryptoSecretKeyring {
diff --git a/include/io/dns-resolver.h b/include/io/dns-resolver.h
index e248fba5bd..9d14a8d98f 100644
--- a/include/io/dns-resolver.h
+++ b/include/io/dns-resolver.h
@@ -27,7 +27,7 @@ 
 
 #define TYPE_QIO_DNS_RESOLVER "qio-dns-resolver"
 OBJECT_DECLARE_SIMPLE_TYPE(QIODNSResolver, qio_dns_resolver,
-                           QIO_DNS_RESOLVER, ObjectClass)
+                           QIO_DNS_RESOLVER)
 
 
 /**
diff --git a/include/io/net-listener.h b/include/io/net-listener.h
index 60fad29ff4..8145962fbb 100644
--- a/include/io/net-listener.h
+++ b/include/io/net-listener.h
@@ -26,7 +26,7 @@ 
 
 #define TYPE_QIO_NET_LISTENER "qio-net-listener"
 OBJECT_DECLARE_SIMPLE_TYPE(QIONetListener, qio_net_listener,
-                           QIO_NET_LISTENER, ObjectClass)
+                           QIO_NET_LISTENER)
 
 
 typedef void (*QIONetListenerClientFunc)(QIONetListener *listener,
diff --git a/include/qom/object.h b/include/qom/object.h
index 405a2c67b0..d5814bd11d 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -639,19 +639,19 @@  struct Object
  * @InstanceType: instance struct name
  * @module_obj_name: the object name in lowercase with underscore separators
  * @MODULE_OBJ_NAME: the object name in uppercase with underscore separators
- * @ParentClassType: class struct name of parent type
  *
- * 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 does the same as OBJECT_DECLARE_TYPE(), but with no class struct
+ * declared.
  *
  * This macro should be used unless the class struct needs to have
  * virtual methods declared.
  */
-#define OBJECT_DECLARE_SIMPLE_TYPE(InstanceType, module_obj_name, \
-                                   MODULE_OBJ_NAME, ParentClassType) \
-    OBJECT_DECLARE_TYPE(InstanceType, InstanceType##Class, module_obj_name, MODULE_OBJ_NAME) \
-    struct InstanceType##Class { ParentClassType parent_class; };
+#define OBJECT_DECLARE_SIMPLE_TYPE(InstanceType, module_obj_name, MODULE_OBJ_NAME) \
+    typedef struct InstanceType InstanceType; \
+    \
+    G_DEFINE_AUTOPTR_CLEANUP_FUNC(InstanceType, object_unref) \
+    \
+    DECLARE_INSTANCE_CHECKER(InstanceType, MODULE_OBJ_NAME, TYPE_##MODULE_OBJ_NAME)
 
 
 /**
diff --git a/include/sysemu/vhost-user-backend.h b/include/sysemu/vhost-user-backend.h
index 23205edeb8..41d5ff43bd 100644
--- a/include/sysemu/vhost-user-backend.h
+++ b/include/sysemu/vhost-user-backend.h
@@ -23,7 +23,7 @@ 
 
 #define TYPE_VHOST_USER_BACKEND "vhost-user-backend"
 OBJECT_DECLARE_SIMPLE_TYPE(VhostUserBackend, vhost_user_backend,
-                           VHOST_USER_BACKEND, ObjectClass)
+                           VHOST_USER_BACKEND)
 
 
 
diff --git a/authz/list.c b/authz/list.c
index 8e904bfc93..28b990931a 100644
--- a/authz/list.c
+++ b/authz/list.c
@@ -252,7 +252,6 @@  static const TypeInfo qauthz_list_info = {
     .name = TYPE_QAUTHZ_LIST,
     .instance_size = sizeof(QAuthZList),
     .instance_finalize = qauthz_list_finalize,
-    .class_size = sizeof(QAuthZListClass),
     .class_init = qauthz_list_class_init,
     .interfaces = (InterfaceInfo[]) {
         { TYPE_USER_CREATABLE },
diff --git a/authz/listfile.c b/authz/listfile.c
index 666df872ad..cd6163aa40 100644
--- a/authz/listfile.c
+++ b/authz/listfile.c
@@ -263,7 +263,6 @@  static const TypeInfo qauthz_list_file_info = {
     .instance_init = qauthz_list_file_init,
     .instance_size = sizeof(QAuthZListFile),
     .instance_finalize = qauthz_list_file_finalize,
-    .class_size = sizeof(QAuthZListFileClass),
     .class_init = qauthz_list_file_class_init,
     .interfaces = (InterfaceInfo[]) {
         { TYPE_USER_CREATABLE },
diff --git a/authz/pamacct.c b/authz/pamacct.c
index 3c6be43916..c91593bbd8 100644
--- a/authz/pamacct.c
+++ b/authz/pamacct.c
@@ -129,7 +129,6 @@  static const TypeInfo qauthz_pam_info = {
     .name = TYPE_QAUTHZ_PAM,
     .instance_size = sizeof(QAuthZPAM),
     .instance_finalize = qauthz_pam_finalize,
-    .class_size = sizeof(QAuthZPAMClass),
     .class_init = qauthz_pam_class_init,
     .interfaces = (InterfaceInfo[]) {
         { TYPE_USER_CREATABLE },
diff --git a/authz/simple.c b/authz/simple.c
index 84954b80a5..ee061e980d 100644
--- a/authz/simple.c
+++ b/authz/simple.c
@@ -96,7 +96,6 @@  static const TypeInfo qauthz_simple_info = {
     .name = TYPE_QAUTHZ_SIMPLE,
     .instance_size = sizeof(QAuthZSimple),
     .instance_finalize = qauthz_simple_finalize,
-    .class_size = sizeof(QAuthZSimpleClass),
     .class_init = qauthz_simple_class_init,
     .interfaces = (InterfaceInfo[]) {
         { TYPE_USER_CREATABLE },
diff --git a/backends/dbus-vmstate.c b/backends/dbus-vmstate.c
index a13461edea..5bffbc4906 100644
--- a/backends/dbus-vmstate.c
+++ b/backends/dbus-vmstate.c
@@ -24,7 +24,7 @@ 
 
 #define TYPE_DBUS_VMSTATE "dbus-vmstate"
 OBJECT_DECLARE_SIMPLE_TYPE(DBusVMState, dbus_vmstate,
-                           DBUS_VMSTATE, ObjectClass)
+                           DBUS_VMSTATE)
 
 
 struct DBusVMState {
@@ -483,7 +483,6 @@  static const TypeInfo dbus_vmstate_info = {
     .parent = TYPE_OBJECT,
     .instance_size = sizeof(DBusVMState),
     .instance_finalize = dbus_vmstate_finalize,
-    .class_size = sizeof(DBusVMStateClass),
     .class_init = dbus_vmstate_class_init,
     .interfaces = (InterfaceInfo[]) {
         { TYPE_USER_CREATABLE },
diff --git a/backends/vhost-user.c b/backends/vhost-user.c
index 9e6e198546..ae8362d721 100644
--- a/backends/vhost-user.c
+++ b/backends/vhost-user.c
@@ -197,7 +197,6 @@  static const TypeInfo vhost_user_backend_info = {
     .instance_size = sizeof(VhostUserBackend),
     .instance_init = vhost_user_backend_init,
     .instance_finalize = vhost_user_backend_finalize,
-    .class_size = sizeof(VhostUserBackendClass),
 };
 
 static void register_types(void)
diff --git a/crypto/secret_keyring.c b/crypto/secret_keyring.c
index 8bfc58ebf4..10d8bc48a0 100644
--- a/crypto/secret_keyring.c
+++ b/crypto/secret_keyring.c
@@ -129,7 +129,6 @@  static const TypeInfo qcrypto_secret_info = {
     .parent = TYPE_QCRYPTO_SECRET_COMMON,
     .name = TYPE_QCRYPTO_SECRET_KEYRING,
     .instance_size = sizeof(QCryptoSecretKeyring),
-    .class_size = sizeof(QCryptoSecretKeyringClass),
     .class_init = qcrypto_secret_keyring_class_init,
     .interfaces = (InterfaceInfo[]) {
         { TYPE_USER_CREATABLE },
diff --git a/io/dns-resolver.c b/io/dns-resolver.c
index 6ebe2a5650..b55d8cc3fe 100644
--- a/io/dns-resolver.c
+++ b/io/dns-resolver.c
@@ -267,7 +267,6 @@  static const TypeInfo qio_dns_resolver_info = {
     .parent = TYPE_OBJECT,
     .name = TYPE_QIO_DNS_RESOLVER,
     .instance_size = sizeof(QIODNSResolver),
-    .class_size = sizeof(QIODNSResolverClass),
 };
 
 
diff --git a/io/net-listener.c b/io/net-listener.c
index 5d8a226872..46c2643d00 100644
--- a/io/net-listener.c
+++ b/io/net-listener.c
@@ -307,7 +307,6 @@  static const TypeInfo qio_net_listener_info = {
     .name = TYPE_QIO_NET_LISTENER,
     .instance_size = sizeof(QIONetListener),
     .instance_finalize = qio_net_listener_finalize,
-    .class_size = sizeof(QIONetListenerClass),
 };
 
 
diff --git a/ui/input-barrier.c b/ui/input-barrier.c
index 87543a3399..b76697be93 100644
--- a/ui/input-barrier.c
+++ b/ui/input-barrier.c
@@ -21,7 +21,7 @@ 
 
 #define TYPE_INPUT_BARRIER "input-barrier"
 OBJECT_DECLARE_SIMPLE_TYPE(InputBarrier, input_barrier,
-                           INPUT_BARRIER, ObjectClass)
+                           INPUT_BARRIER)
 
 
 #define MAX_HELLO_LENGTH 1024
@@ -723,7 +723,6 @@  static void input_barrier_class_init(ObjectClass *oc, void *data)
 static const TypeInfo input_barrier_info = {
     .name = TYPE_INPUT_BARRIER,
     .parent = TYPE_OBJECT,
-    .class_size = sizeof(InputBarrierClass),
     .class_init = input_barrier_class_init,
     .instance_size = sizeof(InputBarrier),
     .instance_init = input_barrier_instance_init,
diff --git a/ui/input-linux.c b/ui/input-linux.c
index 5d501c8360..f02557b012 100644
--- a/ui/input-linux.c
+++ b/ui/input-linux.c
@@ -32,7 +32,7 @@  static bool linux_is_button(unsigned int lnx)
 
 #define TYPE_INPUT_LINUX "input-linux"
 OBJECT_DECLARE_SIMPLE_TYPE(InputLinux, input_linux,
-                           INPUT_LINUX, ObjectClass)
+                           INPUT_LINUX)
 
 
 struct InputLinux {
@@ -514,7 +514,6 @@  static void input_linux_class_init(ObjectClass *oc, void *data)
 static const TypeInfo input_linux_info = {
     .name = TYPE_INPUT_LINUX,
     .parent = TYPE_OBJECT,
-    .class_size = sizeof(InputLinuxClass),
     .class_init = input_linux_class_init,
     .instance_size = sizeof(InputLinux),
     .instance_init = input_linux_instance_init,