mirror of https://github.com/xqemu/xqemu.git
qom: object: Ignore refs/unrefs of NULL
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 <peter.crosthwaite@xilinx.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
c28322d10c
commit
8ffad850ef
10
qom/object.c
10
qom/object.c
|
@ -711,11 +711,17 @@ GSList *object_class_get_list(const char *implements_type,
|
||||||
|
|
||||||
void object_ref(Object *obj)
|
void object_ref(Object *obj)
|
||||||
{
|
{
|
||||||
|
if (!obj) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
atomic_inc(&obj->ref);
|
atomic_inc(&obj->ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
void object_unref(Object *obj)
|
void object_unref(Object *obj)
|
||||||
{
|
{
|
||||||
|
if (!obj) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
g_assert(obj->ref > 0);
|
g_assert(obj->ref > 0);
|
||||||
|
|
||||||
/* parent always holds a reference to its children */
|
/* parent always holds a reference to its children */
|
||||||
|
@ -1160,14 +1166,10 @@ static void object_set_link_property(Object *obj, Visitor *v, void *opaque,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (new_target) {
|
|
||||||
object_ref(new_target);
|
object_ref(new_target);
|
||||||
}
|
|
||||||
*child = 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)
|
static Object *object_resolve_link_property(Object *parent, void *opaque, const gchar *part)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue