Received: from eggs.gnu.org ([208.118.235.92]:56321) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S3QmK-0002e7-9H for qemu-devel@nongnu.org; Fri, 02 Mar 2012 06:36:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S3QmD-0005VO-Rr for qemu-devel@nongnu.org; Fri, 02 Mar 2012 06:36:03 -0500 Received: from mailout2.w1.samsung.com ([210.118.77.12]:28702) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S3QmD-0005Ua-M7 for qemu-devel@nongnu.org; Fri, 02 Mar 2012 06:35:57 -0500 Received: from euspt1 (mailout2.w1.samsung.com [210.118.77.12]) by mailout2.w1.samsung.com (iPlanet Messaging Server 5.2 Patch 2 (built Jul 14 2004)) with ESMTP id <0M0900FPH9JTQL@mailout2.w1.samsung.com> for qemu-devel@nongnu.org; Fri, 02 Mar 2012 11:35:53 +0000 (GMT) Received: from dodo.rnd.samsung.ru ([106.109.8.162]) by spt1.w1.samsung.com (iPlanet Messaging Server 5.2 Patch 2 (built Jul 14 2004)) with ESMTPA id <0M0900JK29JL0S@spt1.w1.samsung.com> for qemu-devel@nongnu.org; Fri, 02 Mar 2012 11:35:53 +0000 (GMT) Date: Fri, 02 Mar 2012 15:35:41 +0400 From: Igor Mitsyanko In-reply-to: <1330688145-22944-1-git-send-email-i.mitsyanko@samsung.com> Message-id: <1330688145-22944-2-git-send-email-i.mitsyanko@samsung.com> MIME-version: 1.0 Content-type: TEXT/PLAIN Content-transfer-encoding: 7BIT References: <1330688145-22944-1-git-send-email-i.mitsyanko@samsung.com> Subject: [Qemu-devel] [PATCH 1/5] qom: if @instance_size==0, assign size of object to parent object size List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, Igor Mitsyanko , e.voevodin@samsung.com, kyungmin.park@samsung.com, d.solodkiy@samsung.com, m.kozlov@samsung.com 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 Reviewed-by: Paolo Bonzini --- 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