qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [RFC PATCH 01/13] qom: object: Ignore refs/unrefs of NULL


From: Paolo Bonzini
Subject: [Qemu-devel] [RFC PATCH 01/13] qom: object: Ignore refs/unrefs of NULL
Date: Wed, 11 Jun 2014 14:19:24 +0200

From: Peter Crosthwaite <address@hidden>

Just do nothing if passed NULL for a ref or unref. This avoids
call sites that manage a combination of NULL or non-NULL pointers
having to add iffery around every ref and unref.

Signed-off-by: Peter Crosthwaite <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
 qom/object.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/qom/object.c b/qom/object.c
index e146ae5..3650a5b 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -709,11 +709,17 @@ GSList *object_class_get_list(const char *implements_type,
 
 void object_ref(Object *obj)
 {
+     if (!obj) {
+         return;
+     }
      atomic_inc(&obj->ref);
 }
 
 void object_unref(Object *obj)
 {
+    if (!obj) {
+        return;
+    }
     g_assert(obj->ref > 0);
 
     /* parent always holds a reference to its children */
@@ -1132,13 +1138,9 @@ static void object_set_link_property(Object *obj, 
Visitor *v, void *opaque,
         return;
     }
 
-    if (new_target) {
-        object_ref(new_target);
-    }
+    object_ref(new_target);
     *child = new_target;
-    if (old_target != NULL) {
-        object_unref(old_target);
-    }
+    object_unref(old_target);
 }
 
 static Object *object_resolve_link_property(Object *parent, void *opaque, 
const gchar *part)
-- 
1.8.3.1





reply via email to

[Prev in Thread] Current Thread [Next in Thread]