@@ -242,6 +242,8 @@ struct ObjectClass
GSList *interfaces;
};
+typedef void (ObjectReleaseFunc)(Object *obj);
+
/**
* Object:
*
@@ -264,6 +266,7 @@ struct Object
QTAILQ_HEAD(, ObjectProperty) properties;
uint32_t ref;
Object *parent;
+ ObjectReleaseFunc *release;
};
/**
@@ -464,6 +467,8 @@ Object *object_new_with_type(Type type);
*/
void object_delete(Object *obj);
+void object_set_release_func(Object *obj, ObjectReleaseFunc *func);
+
/**
* object_initialize_with_type:
* @obj: A pointer to the memory to be used for the object.
@@ -384,6 +384,20 @@ void object_finalize(void *data)
object_property_del_all(obj);
g_assert(obj->ref == 0);
+
+ if (obj->release) {
+ obj->release(obj);
+ }
+}
+
+void object_set_release_func(Object *obj, ObjectReleaseFunc *func)
+{
+ obj->release = func;
+}
+
+static void object_release_func(Object *obj)
+{
+ g_free(obj);
}
Object *object_new_with_type(Type type)
@@ -395,6 +409,7 @@ Object *object_new_with_type(Type type)
obj = g_malloc(type->instance_size);
object_initialize_with_type(obj, type);
+ object_set_release_func(obj, object_release_func);
object_ref(obj);
return obj;
@@ -412,7 +427,6 @@ void object_delete(Object *obj)
object_unparent(obj);
g_assert(obj->ref == 1);
object_unref(obj);
- g_free(obj);
}
Object *object_dynamic_cast(Object *obj, const char *typename)
Now object_delete() simply has the semantics of unref'ing an object and unparenting it. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> --- include/qemu/object.h | 5 +++++ qom/object.c | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 1 deletions(-)