* [Qemu-devel] [PATCH V2 1/2] qom: if @instance_size==0, assign size of object to parent object size
2012-02-28 11:57 [Qemu-devel] [PATCH V2 0/2] QOM: small object creation fix Igor Mitsyanko
@ 2012-02-28 11:57 ` Igor Mitsyanko
2012-02-28 11:57 ` [Qemu-devel] [PATCH V2 2/2] qom/object.c: rename type_class_init() to type_initialize() Igor Mitsyanko
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Igor Mitsyanko @ 2012-02-28 11:57 UTC (permalink / raw)
To: qemu-devel
Cc: Igor Mitsyanko, e.voevodin, kyungmin.park, d.solodkiy, anthony,
pbonzini, m.kozlov
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>
---
qom/object.c | 19 +++++++++++++++++--
1 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/qom/object.c b/qom/object.c
index aa037d2..6d31bc3 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);
@@ -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);
--
1.7.4.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [Qemu-devel] [PATCH V2 2/2] qom/object.c: rename type_class_init() to type_initialize()
2012-02-28 11:57 [Qemu-devel] [PATCH V2 0/2] QOM: small object creation fix Igor Mitsyanko
2012-02-28 11:57 ` [Qemu-devel] [PATCH V2 1/2] qom: if @instance_size==0, assign size of object to parent object size Igor Mitsyanko
@ 2012-02-28 11:57 ` Igor Mitsyanko
2012-02-28 12:02 ` [Qemu-devel] [PATCH V2 0/2] QOM: small object creation fix Paolo Bonzini
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Igor Mitsyanko @ 2012-02-28 11:57 UTC (permalink / raw)
To: qemu-devel
Cc: Igor Mitsyanko, e.voevodin, kyungmin.park, d.solodkiy, anthony,
pbonzini, m.kozlov
Function 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).
Signed-off-by: Igor Mitsyanko <i.mitsyanko@samsung.com>
---
qom/object.c | 12 ++++++------
1 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/qom/object.c b/qom/object.c
index 6d31bc3..9acc624 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -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) {
--
1.7.4.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH V2 0/2] QOM: small object creation fix
2012-02-28 11:57 [Qemu-devel] [PATCH V2 0/2] QOM: small object creation fix Igor Mitsyanko
2012-02-28 11:57 ` [Qemu-devel] [PATCH V2 1/2] qom: if @instance_size==0, assign size of object to parent object size Igor Mitsyanko
2012-02-28 11:57 ` [Qemu-devel] [PATCH V2 2/2] qom/object.c: rename type_class_init() to type_initialize() Igor Mitsyanko
@ 2012-02-28 12:02 ` Paolo Bonzini
2012-03-13 8:24 ` Igor Mitsyanko
2012-03-14 21:18 ` Anthony Liguori
4 siblings, 0 replies; 6+ messages in thread
From: Paolo Bonzini @ 2012-02-28 12:02 UTC (permalink / raw)
To: Igor Mitsyanko
Cc: e.voevodin, qemu-devel, kyungmin.park, d.solodkiy, anthony,
m.kozlov
Il 28/02/2012 12:57, Igor Mitsyanko ha scritto:
> 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(-)
>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Paolo
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH V2 0/2] QOM: small object creation fix
2012-02-28 11:57 [Qemu-devel] [PATCH V2 0/2] QOM: small object creation fix Igor Mitsyanko
` (2 preceding siblings ...)
2012-02-28 12:02 ` [Qemu-devel] [PATCH V2 0/2] QOM: small object creation fix Paolo Bonzini
@ 2012-03-13 8:24 ` Igor Mitsyanko
2012-03-14 21:18 ` Anthony Liguori
4 siblings, 0 replies; 6+ messages in thread
From: Igor Mitsyanko @ 2012-03-13 8:24 UTC (permalink / raw)
Cc: pbonzini, qemu-devel, anthony, d.solodkiy
On 02/28/2012 03:57 PM, Igor Mitsyanko wrote:
> 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(-)
>
ping
--
Mitsyanko Igor
ASWG, Moscow R&D center, Samsung Electronics
email: i.mitsyanko@samsung.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH V2 0/2] QOM: small object creation fix
2012-02-28 11:57 [Qemu-devel] [PATCH V2 0/2] QOM: small object creation fix Igor Mitsyanko
` (3 preceding siblings ...)
2012-03-13 8:24 ` Igor Mitsyanko
@ 2012-03-14 21:18 ` Anthony Liguori
4 siblings, 0 replies; 6+ messages in thread
From: Anthony Liguori @ 2012-03-14 21:18 UTC (permalink / raw)
To: Igor Mitsyanko
Cc: e.voevodin, qemu-devel, kyungmin.park, d.solodkiy, pbonzini,
m.kozlov
On 02/28/2012 05:57 AM, Igor Mitsyanko wrote:
> Eliminate impossibility of creating objects of types with @instance_size == 0.
Applied all. Thanks.
Regards,
Anthony Liguori
>
> 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(-)
>
^ permalink raw reply [flat|nested] 6+ messages in thread