diff options
author | Igor Mitsyanko <i.mitsyanko@samsung.com> | 2012-02-28 15:57:10 +0400 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2012-03-14 15:30:38 -0500 |
commit | aca59af612840772f18598363b65a25bf02bb569 (patch) | |
tree | 1a0c14611c1eb9451a31331bec2a9836b3f6171e /qom/object.c | |
parent | 9512e4a9edef2d9b59eb10a03184cd90a34f62d5 (diff) |
qom: if @instance_size==0, assign size of object to parent object size
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.
Set appropriate value for type instance_size during type_class_init() call.
object_initialize_with_type() must call type_class_init() before asserting
type->instance_size, and object_new_with_type() must call type_class_init() before
object allocation.
Signed-off-by: Igor Mitsyanko <i.mitsyanko@samsung.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'qom/object.c')
-rw-r--r-- | qom/object.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/qom/object.c b/qom/object.c index 39cbcb9b7..0f8749505 100644 --- a/qom/object.c +++ b/qom/object.c @@ -177,6 +177,19 @@ static size_t type_class_get_size(TypeImpl *ti) return sizeof(ObjectClass); } +static size_t type_object_get_size(TypeImpl *ti) +{ + if (ti->instance_size) { + return ti->instance_size; + } + + if (type_has_parent(ti)) { + return type_object_get_size(type_get_parent(ti)); + } + + return 0; +} + static void type_class_interface_init(TypeImpl *ti, InterfaceImpl *iface) { TypeInfo info = { @@ -203,6 +216,7 @@ static void type_class_init(TypeImpl *ti) } ti->class_size = type_class_get_size(ti); + ti->instance_size = type_object_get_size(ti); ti->class = g_malloc0(ti->class_size); ti->class->type = ti; @@ -264,9 +278,9 @@ void object_initialize_with_type(void *data, TypeImpl *type) Object *obj = data; g_assert(type != NULL); - g_assert(type->instance_size >= sizeof(Object)); - type_class_init(type); + + g_assert(type->instance_size >= sizeof(Object)); g_assert(type->abstract == false); memset(obj, 0, type->instance_size); @@ -353,6 +367,7 @@ Object *object_new_with_type(Type type) Object *obj; g_assert(type != NULL); + type_class_init(type); obj = g_malloc(type->instance_size); object_initialize_with_type(obj, type); |