From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:37818) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SgcUm-0001cC-Vq for qemu-devel@nongnu.org; Mon, 18 Jun 2012 10:00:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SgcUT-0003Vl-Nu for qemu-devel@nongnu.org; Mon, 18 Jun 2012 09:59:56 -0400 Received: from cantor2.suse.de ([195.135.220.15]:53229 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SgcUT-0003VX-E3 for qemu-devel@nongnu.org; Mon, 18 Jun 2012 09:59:37 -0400 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Mon, 18 Jun 2012 15:58:57 +0200 Message-Id: <1340027954-19045-6-git-send-email-afaerber@suse.de> In-Reply-To: <1340027954-19045-1-git-send-email-afaerber@suse.de> References: <1340027954-19045-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH 05/22] qom: Make Object a type List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Anthony Liguori From: Paolo Bonzini Right now the base Object class has a special NULL type. Change this so that we will be able to add class_init and class_base_init callbacks. To do this, remove some special casing of ObjectClass that is not really necessary. Signed-off-by: Paolo Bonzini Signed-off-by: Andreas F=C3=A4rber --- include/qemu/object.h | 2 +- qom/object.c | 59 +++++++++++++++++++++++++------------------= ------ 2 files changed, 31 insertions(+), 30 deletions(-) diff --git a/include/qemu/object.h b/include/qemu/object.h index 3c29c17..ff5444f 100644 --- a/include/qemu/object.h +++ b/include/qemu/object.h @@ -33,7 +33,7 @@ typedef struct TypeInfo TypeInfo; typedef struct InterfaceClass InterfaceClass; typedef struct InterfaceInfo InterfaceInfo; =20 -#define TYPE_OBJECT NULL +#define TYPE_OBJECT "object" =20 /** * SECTION:object.h diff --git a/qom/object.c b/qom/object.c index 36379a1..dac9de5 100644 --- a/qom/object.c +++ b/qom/object.c @@ -210,7 +210,7 @@ static void type_class_interface_init(TypeImpl *ti, I= nterfaceImpl *iface) =20 static void type_initialize(TypeImpl *ti) { - size_t class_size =3D sizeof(ObjectClass); + TypeImpl *parent; int i; =20 if (ti->class) { @@ -221,30 +221,24 @@ static void type_initialize(TypeImpl *ti) ti->instance_size =3D type_object_get_size(ti); =20 ti->class =3D g_malloc0(ti->class_size); - ti->class->type =3D ti; - - if (type_has_parent(ti)) { - TypeImpl *parent =3D type_get_parent(ti); =20 + parent =3D type_get_parent(ti); + if (parent) { type_initialize(parent); =20 - class_size =3D parent->class_size; g_assert(parent->class_size <=3D ti->class_size); + memcpy(ti->class, parent->class, parent->class_size); + } =20 - memcpy((void *)ti->class + sizeof(ObjectClass), - (void *)parent->class + sizeof(ObjectClass), - parent->class_size - sizeof(ObjectClass)); + ti->class->type =3D ti; =20 - while (parent) { - if (parent->class_base_init) { - parent->class_base_init(ti->class, ti->class_data); - } - parent =3D type_get_parent(parent); + while (parent) { + if (parent->class_base_init) { + parent->class_base_init(ti->class, ti->class_data); } + parent =3D type_get_parent(parent); } =20 - memset((void *)ti->class + class_size, 0, ti->class_size - class_siz= e); - for (i =3D 0; i < ti->num_interfaces; i++) { type_class_interface_init(ti, &ti->interfaces[i]); } @@ -477,19 +471,6 @@ Object *object_dynamic_cast(Object *obj, const char = *typename) } =20 =20 -static void register_types(void) -{ - static TypeInfo interface_info =3D { - .name =3D TYPE_INTERFACE, - .instance_size =3D sizeof(Interface), - .abstract =3D true, - }; - - type_interface =3D type_register_static(&interface_info); -} - -type_init(register_types) - Object *object_dynamic_cast_assert(Object *obj, const char *typename) { Object *inst; @@ -1243,3 +1224,23 @@ void object_property_add_str(Object *obj, const ch= ar *name, property_release_str, prop, errp); } + +static void register_types(void) +{ + static TypeInfo interface_info =3D { + .name =3D TYPE_INTERFACE, + .instance_size =3D sizeof(Interface), + .abstract =3D true, + }; + + static TypeInfo object_info =3D { + .name =3D TYPE_OBJECT, + .instance_size =3D sizeof(Object), + .abstract =3D true, + }; + + type_interface =3D type_register_static(&interface_info); + type_register_static(&object_info); +} + +type_init(register_types) --=20 1.7.7