File qom-make-object_ref-unref-use-a-void-ins.patch of Package qemu.20375

From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= <berrange@redhat.com>
Date: Mon, 31 Aug 2020 17:07:23 -0400
Subject: qom: make object_ref/unref use a void * instead of Object *.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

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 | 4 ++--
 qom/object.c         | 6 ++++--
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/include/qom/object.h b/include/qom/object.h
index 128d00c77fd6597c4b70bd5f124f..d1e4c2e11524fd3d26520331c3d6 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -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:
diff --git a/qom/object.c b/qom/object.c
index d51b57fba11e335b9dab056327ef..6bff8782dcff40588f2191dadcb0 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -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;
     }
openSUSE Build Service is sponsored by