QOM: small object creation fix
v2 cover QOM: small object creation fix
Eliminate impossibility of creating objects of types with @instance_size == 0.
v1->v2: type's instance size now initialized during type initialization.
type_class_init() renamed (in additional patch)
Igor Mitsyanko (2):
qom: if @instance_size==0, assign size of object to parent object
size
qom/object.c: rename type_class_init() to type_initialize()
qom/object.c | 27 +++++++++++++++++++++------ 1 files changed, 21 insertions(+), 6 deletions(-)
Signature · 1 line
1.7.4.1
PATCH v2 1/2 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.
--- qom/object.c | 19 +++++++++++++++++-- 1 files changed, 17 insertions(+), 2 deletions(-)
qom/object.c +17 -2
@@ -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);
@@ -356,6 +370,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);
Signature · 1 line
1.7.4.1
PATCH v2 2/2 qom/object.c: rename type_class_init() to type_initialize()
In reply to Igor MitsyankoFunction name type_class_init() gave us a wrong impression of separation of type's "class" and "object" entities initialization. Name type_initialize() is more appropriate for type_class_init() function (considering what operations it performs).
--- qom/object.c | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-)
qom/object.c +6 -6
@@ -206,7 +206,7 @@ static void type_class_interface_init(TypeImpl *ti, InterfaceImpl *iface)g_free (name); } -static void type_class_init (TypeImpl *ti) +static void type_initialize (TypeImpl *ti) {size_t class_size =sizeof (ObjectClass);int i;
@@ -224,7 +224,7 @@ static void type_class_init(TypeImpl *ti)if (type_has_parent (ti)) {TypeImpl *parent =type_get_parent (ti); -type_class_init (parent); +type_initialize (parent); class_size = parent->class_size;g_assert (parent->class_size <= ti->class_size);
@@ -278,7 +278,7 @@ void object_initialize_with_type(void *data, TypeImpl *type)Object *obj = data;g_assert (type !=NULL ); -type_class_init (type); +type_initialize (type);g_assert (type->instance_size >=sizeof (Object));g_assert (type->abstract == false);
@@ -370,7 +370,7 @@ Object *object_new_with_type(Type type)Object *obj;g_assert (type !=NULL ); -type_class_init (type); +type_initialize (type); obj =g_malloc (type->instance_size);object_initialize_with_type (obj, type);
@@ -543,7 +543,7 @@ ObjectClass *object_class_by_name(const char *typename)return NULL ; } -type_class_init (type); +type_initialize (type);return type->class; }
@@ -563,7 +563,7 @@ static void object_class_foreach_tramp(gpointer key, gpointer value,TypeImpl *type = value;ObjectClass *k; -type_class_init (type); +type_initialize (type); k = type->class;if (!data->include_abstract && type->abstract) {
Signature · 1 line
1.7.4.1
Il 28/02/2012 12:57, Igor Mitsyanko ha scritto:
Quoted 5 lines
Eliminate impossibility of creating objects of types with @instance_size == 0.
v1->v2: type's instance size now initialized during type initialization.
type_class_init()renamed (in additional patch)
Quoted 8 lines
Igor Mitsyanko (2):
qom: if @instance_size==0, assign size of object to parent object
size
qom/object.c: renametype_class_init()totype_initialize()qom/object.c | 27 +++++++++++++++++++++------ 1 files changed, 21 insertions(+), 6 deletions(-)
Paolo
Quoted 5 lines · Igor Mitsyanko
Eliminate impossibility of creating objects of types with @instance_size == 0.
v1->v2: type's instance size now initialized during type initialization.
type_class_init()renamed (in additional patch)
Quoted 8 lines
Igor Mitsyanko (2):
qom: if @instance_size==0, assign size of object to parent object
size
qom/object.c: renametype_class_init()totype_initialize()qom/object.c | 27 +++++++++++++++++++++------ 1 files changed, 21 insertions(+), 6 deletions(-)
ping
Signature · 3 lines
Mitsyanko Igor ASWG, Moscow R&D center, Samsung Electronics email: [email protected]
Anthony Liguori
AppliedQuoted 1 line · Igor Mitsyanko
Eliminate impossibility of creating objects of types with @instance_size == 0.
Applied all. Thanks.
Regards,
Anthony Liguori
Quoted 12 lines
v1->v2: type's instance size now initialized during type initialization.
type_class_init()renamed (in additional patch)Igor Mitsyanko (2):
qom: if @instance_size==0, assign size of object to parent object
size
qom/object.c: renametype_class_init()totype_initialize()qom/object.c | 27 +++++++++++++++++++++------ 1 files changed, 21 insertions(+), 6 deletions(-)