qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [RFC PATCH 03/13] qom: move unparenting to the child proper


From: Paolo Bonzini
Subject: [Qemu-devel] [RFC PATCH 03/13] qom: move unparenting to the child property's release callback
Date: Wed, 11 Jun 2014 14:19:26 +0200

This ensures that the unparent callback is called automatically
when the parent object is finalized.

Note that there's no need to keep a reference neither in
object_unparent nor in object_finalize_child_property.  The
reference held by the child property itself will do.

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

diff --git a/qom/object.c b/qom/object.c
index 01087e5..69a95d6 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -386,19 +386,9 @@ static void object_property_del_child(Object *obj, Object 
*child, Error **errp)
 
 void object_unparent(Object *obj)
 {
-    if (!obj->parent) {
-        return;
-    }
-
-    object_ref(obj);
-    if (obj->class->unparent) {
-        (obj->class->unparent)(obj);
-    }
     if (obj->parent) {
         object_property_del_child(obj->parent, obj, NULL);
-        obj->parent = NULL;
     }
-    object_unref(obj);
 }
 
 static void object_deinit(Object *obj, TypeImpl *type)
@@ -1017,6 +1007,10 @@ static void object_finalize_child_property(Object *obj, 
const char *name,
 {
     Object *child = opaque;
 
+    if (child->class->unparent) {
+        (child->class->unparent)(child);
+    }
+    child->parent = NULL;
     object_unref(child);
 }
 
-- 
1.8.3.1





reply via email to

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