mirror of
https://gitlab.com/qemu-project/qemu
synced 2024-07-21 10:24:33 +00:00
qom: object: move unparenting to the child property's release callback
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. Reviewed-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
76a6e1cc7c
commit
bffc687d66
14
qom/object.c
14
qom/object.c
|
@ -387,19 +387,9 @@ static void object_property_del_child(Object *obj, Object *child, Error **errp)
|
||||||
|
|
||||||
void object_unparent(Object *obj)
|
void object_unparent(Object *obj)
|
||||||
{
|
{
|
||||||
if (!obj->parent) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
object_ref(obj);
|
|
||||||
if (obj->class->unparent) {
|
|
||||||
(obj->class->unparent)(obj);
|
|
||||||
}
|
|
||||||
if (obj->parent) {
|
if (obj->parent) {
|
||||||
object_property_del_child(obj->parent, obj, NULL);
|
object_property_del_child(obj->parent, obj, NULL);
|
||||||
obj->parent = NULL;
|
|
||||||
}
|
}
|
||||||
object_unref(obj);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void object_deinit(Object *obj, TypeImpl *type)
|
static void object_deinit(Object *obj, TypeImpl *type)
|
||||||
|
@ -1042,6 +1032,10 @@ static void object_finalize_child_property(Object *obj, const char *name,
|
||||||
{
|
{
|
||||||
Object *child = opaque;
|
Object *child = opaque;
|
||||||
|
|
||||||
|
if (child->class->unparent) {
|
||||||
|
(child->class->unparent)(child);
|
||||||
|
}
|
||||||
|
child->parent = NULL;
|
||||||
object_unref(child);
|
object_unref(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue