object: return self in object_ref()
authorMarc-André Lureau <marcandre.lureau@redhat.com>
Fri, 10 Jan 2020 15:30:31 +0000 (19:30 +0400)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 24 Jan 2020 19:59:14 +0000 (20:59 +0100)
This allow for simpler assignment with ref: foo = object_ref(bar)

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20200110153039.1379601-19-marcandre.lureau@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
include/qom/object.h
qom/object.c

index 5e2f60d4b07d956998052cb2e8573257b3e06ef2..18660fde1c75f44b33a41ad109cd324e3f8a680c 100644 (file)
@@ -1005,8 +1005,9 @@ 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.
+ * Returns: @obj
  */
-void object_ref(Object *obj);
+Object *object_ref(Object *obj);
 
 /**
  * object_unref:
index 66c4a5f1cb40d05bc42682d75d37b3c4f836588a..555c8b9d07e8fddb584c259c9e25909144ca83a0 100644 (file)
@@ -1107,12 +1107,13 @@ GSList *object_class_get_list_sorted(const char *implements_type,
                         object_class_cmp);
 }
 
-void object_ref(Object *obj)
+Object *object_ref(Object *obj)
 {
     if (!obj) {
-        return;
+        return NULL;
     }
     atomic_inc(&obj->ref);
+    return obj;
 }
 
 void object_unref(Object *obj)