qom: make object_ref/unref use a void * instead of Object *.
authorDaniel P. Berrangé <berrange@redhat.com>
Mon, 31 Aug 2020 21:07:23 +0000 (17:07 -0400)
committerwanchao-xu <wanchao.xu@samsung.com>
Tue, 9 Jan 2024 11:48:53 +0000 (19:48 +0800)
Git-commit: c5a61e5a3c68144a421117916aef04f2c0fab84b
References: bsc#1184574

The object_ref/unref methods are intended for use with any subclass of
the base Object. Using "Object *" in the signature is not adding any
meaningful level of type safety, since callers simply use "OBJECT(ptr)"
and this expands to an unchecked cast "(Object *)".

By using "void *" we enable the object_unref() method to be used to
provide support for g_autoptr() with any subclass.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Message-Id: <20200723181410.3145233-2-berrange@redhat.com>
Message-Id: <20200831210740.126168-2-ehabkost@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Lin Ma <lma@suse.com>
include/qom/object.h
qom/object.c

index 128d00c77fd6597c4b70bd5f124f57ba3b4b37e2..d1e4c2e11524fd3d26520331c3d6cea5b0086742 100644 (file)
@@ -974,7 +974,7 @@ GSList *object_class_get_list_sorted(const char *implements_type,
  * Increase the reference count of a object.  A object cannot be freed as long
  * as its reference count is greater than zero.
  */
-void object_ref(Object *obj);
+void object_ref(void *obj);
 
 /**
  * object_unref:
@@ -983,7 +983,7 @@ void object_ref(Object *obj);
  * Decrease the reference count of a object.  A object cannot be freed as long
  * as its reference count is greater than zero.
  */
-void object_unref(Object *obj);
+void object_unref(void *obj);
 
 /**
  * object_property_add:
index d51b57fba11e335b9dab056327ef939f66f7bb42..6bff8782dcff40588f2191dadcb0f6435f82c6a9 100644 (file)
@@ -1054,16 +1054,18 @@ GSList *object_class_get_list_sorted(const char *implements_type,
                         object_class_cmp);
 }
 
-void object_ref(Object *obj)
+void object_ref(void *objptr)
 {
+    Object *obj = OBJECT(objptr);
     if (!obj) {
         return;
     }
     atomic_inc(&obj->ref);
 }
 
-void object_unref(Object *obj)
+void object_unref(void *objptr)
 {
+    Object *obj = OBJECT(objptr);
     if (!obj) {
         return;
     }