From patchwork Tue Feb 28 11:57:10 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mitsyanko Igor X-Patchwork-Id: 143435 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C841DB6EEC for ; Tue, 28 Feb 2012 22:57:47 +1100 (EST) Received: from localhost ([::1]:50328 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S2Lgf-0001eB-Mh for incoming@patchwork.ozlabs.org; Tue, 28 Feb 2012 06:57:45 -0500 Received: from eggs.gnu.org ([208.118.235.92]:46583) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S2LgQ-0001PW-59 for qemu-devel@nongnu.org; Tue, 28 Feb 2012 06:57:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S2LgJ-0005yj-Em for qemu-devel@nongnu.org; Tue, 28 Feb 2012 06:57:29 -0500 Received: from mailout1.w1.samsung.com ([210.118.77.11]:58083) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S2LgJ-0005yP-94 for qemu-devel@nongnu.org; Tue, 28 Feb 2012 06:57:23 -0500 Received: from euspt2 (mailout1.w1.samsung.com [210.118.77.11]) by mailout1.w1.samsung.com (iPlanet Messaging Server 5.2 Patch 2 (built Jul 14 2004)) with ESMTP id <0M03009GXQJH5X@mailout1.w1.samsung.com> for qemu-devel@nongnu.org; Tue, 28 Feb 2012 11:57:17 +0000 (GMT) Received: from dodo.rnd.samsung.ru ([106.109.8.162]) by spt2.w1.samsung.com (iPlanet Messaging Server 5.2 Patch 2 (built Jul 14 2004)) with ESMTPA id <0M03002SOQJBJK@spt2.w1.samsung.com> for qemu-devel@nongnu.org; Tue, 28 Feb 2012 11:57:19 +0000 (GMT) Date: Tue, 28 Feb 2012 15:57:10 +0400 From: Igor Mitsyanko In-reply-to: <1330430231-18778-1-git-send-email-i.mitsyanko@samsung.com> To: qemu-devel@nongnu.org Message-id: <1330430231-18778-2-git-send-email-i.mitsyanko@samsung.com> MIME-version: 1.0 X-Mailer: git-send-email 1.7.4.1 Content-type: TEXT/PLAIN Content-transfer-encoding: 7BIT References: <1330430231-18778-1-git-send-email-i.mitsyanko@samsung.com> X-detected-operating-system: by eggs.gnu.org: Solaris 9.1 X-Received-From: 210.118.77.11 Cc: Igor Mitsyanko , e.voevodin@samsung.com, kyungmin.park@samsung.com, d.solodkiy@samsung.com, anthony@codemonkey.ws, pbonzini@redhat.com, m.kozlov@samsung.com Subject: [Qemu-devel] [PATCH V2 1/2] qom: if @instance_size==0, assign size of object to parent object size X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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);