[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH] qom: if @instance_size==0, assign size of object to
From: |
Igor Mitsyanko |
Subject: |
[Qemu-devel] [PATCH] qom: if @instance_size==0, assign size of object to parent object size |
Date: |
Tue, 28 Feb 2012 11:18:30 +0400 |
QOM documentation states that for objects of type with @instance_size == 0 size
will be assigned to match parent object's size. But currently this feauture is
not implemented and qemu asserts during creation of object with zero
instance_size.
This patch adjusts actual behaviour in accordance with documentation.
Signed-off-by: Igor Mitsyanko <address@hidden>
---
qom/object.c | 15 +++++++++++++++
1 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/qom/object.c b/qom/object.c
index aa037d2..3cc2849 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -275,10 +275,24 @@ void object_initialize_with_type(void *data, TypeImpl
*type)
object_init_with_type(obj, type);
}
+static size_t object_get_instance_size(TypeImpl *ti)
+{
+ if (ti->instance_size) {
+ return ti->instance_size;
+ }
+
+ if (type_has_parent(ti)) {
+ return object_get_instance_size(type_get_parent(ti));
+ }
+
+ return 0;
+}
+
void object_initialize(void *data, const char *typename)
{
TypeImpl *type = type_get_by_name(typename);
+ type->instance_size = object_get_instance_size(type);
object_initialize_with_type(data, type);
}
@@ -357,6 +371,7 @@ Object *object_new_with_type(Type type)
g_assert(type != NULL);
+ type->instance_size = object_get_instance_size(type);
obj = g_malloc(type->instance_size);
object_initialize_with_type(obj, type);
object_ref(obj);
--
1.7.4.1
- [Qemu-devel] [PATCH] qom: if @instance_size==0, assign size of object to parent object size,
Igor Mitsyanko <=