Received: from eggs.gnu.org ([2001:4830:134:3::10]:48556) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VvVPU-00061r-O0 for qemu-devel@nongnu.org; Tue, 24 Dec 2013 12:04:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VvVPO-00047L-1r for qemu-devel@nongnu.org; Tue, 24 Dec 2013 12:04:48 -0500 Received: from cantor2.suse.de ([195.135.220.15]:54428 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VvVPN-00046i-NW for qemu-devel@nongnu.org; Tue, 24 Dec 2013 12:04:41 -0500 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Tue, 24 Dec 2013 18:04:26 +0100 Message-Id: <1387904675-7962-16-git-send-email-afaerber@suse.de> In-Reply-To: <1387904675-7962-1-git-send-email-afaerber@suse.de> References: <1387904675-7962-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] [PULL v2 15/24] qom: Do not register interface "types" in the type table and fix names 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?= From: Paolo Bonzini There should be no need to look up nor enumerate the interface "types", whose "classes" are really just vtables. Just create the types and add them to the interface list of the parent type. Interfaces not registering their type anymore means that accessing superclass::interface by type name will fail when initializing subclass::interface. Thus, we need to pre-initialize the subclass's parent_type field before calling type_initialize. Apart from this, the interface "types" should never be used and thus it is harmless to leave them out of the hashtable. Further, the interface types had a bug with interfaces that are inherited from a superclass: The implementation type name was wrong (for example it was subclass::superclass::interface rather than just subclass::interface). This patch fixes this as well. Reported-by: Igor Mammedov Tested-by: Igor Mammedov Signed-off-by: Paolo Bonzini Signed-off-by: Andreas F=C3=A4rber --- include/qom/object.h | 1 + qom/object.c | 32 +++++++++++++++++++++----------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/include/qom/object.h b/include/qom/object.h index 5f78847..e0ff212 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -536,6 +536,7 @@ struct InterfaceClass ObjectClass parent_class; /*< private >*/ ObjectClass *concrete_class; + Type interface_type; }; =20 #define TYPE_INTERFACE "interface" diff --git a/qom/object.c b/qom/object.c index 21b5a0b..470a1ac 100644 --- a/qom/object.c +++ b/qom/object.c @@ -88,7 +88,7 @@ static TypeImpl *type_table_lookup(const char *name) return g_hash_table_lookup(type_table_get(), name); } =20 -static TypeImpl *type_register_internal(const TypeInfo *info) +static TypeImpl *type_new(const TypeInfo *info) { TypeImpl *ti =3D g_malloc0(sizeof(*ti)); int i; @@ -122,8 +122,15 @@ static TypeImpl *type_register_internal(const TypeIn= fo *info) } ti->num_interfaces =3D i; =20 - type_table_add(ti); + return ti; +} =20 +static TypeImpl *type_register_internal(const TypeInfo *info) +{ + TypeImpl *ti; + ti =3D type_new(info); + + type_table_add(ti); return ti; } =20 @@ -206,22 +213,25 @@ static bool type_is_ancestor(TypeImpl *type, TypeIm= pl *target_type) =20 static void type_initialize(TypeImpl *ti); =20 -static void type_initialize_interface(TypeImpl *ti, const char *parent) +static void type_initialize_interface(TypeImpl *ti, TypeImpl *interface_= type, + TypeImpl *parent_type) { InterfaceClass *new_iface; TypeInfo info =3D { }; TypeImpl *iface_impl; =20 - info.parent =3D parent; - info.name =3D g_strdup_printf("%s::%s", ti->name, info.parent); + info.parent =3D parent_type->name; + info.name =3D g_strdup_printf("%s::%s", ti->name, interface_type->na= me); info.abstract =3D true; =20 - iface_impl =3D type_register(&info); + iface_impl =3D type_new(&info); + iface_impl->parent_type =3D parent_type; type_initialize(iface_impl); g_free((char *)info.name); =20 new_iface =3D (InterfaceClass *)iface_impl->class; new_iface->concrete_class =3D ti->class; + new_iface->interface_type =3D interface_type; =20 ti->class->interfaces =3D g_slist_append(ti->class->interfaces, iface_impl->class); @@ -251,8 +261,10 @@ static void type_initialize(TypeImpl *ti) ti->class->interfaces =3D NULL; =20 for (e =3D parent->class->interfaces; e; e =3D e->next) { - ObjectClass *iface =3D e->data; - type_initialize_interface(ti, object_class_get_name(iface)); + InterfaceClass *iface =3D e->data; + ObjectClass *klass =3D OBJECT_CLASS(iface); + + type_initialize_interface(ti, iface->interface_type, klass->= type); } =20 for (i =3D 0; i < ti->num_interfaces; i++) { @@ -269,7 +281,7 @@ static void type_initialize(TypeImpl *ti) continue; } =20 - type_initialize_interface(ti, ti->interfaces[i].typename); + type_initialize_interface(ti, t, t); } } =20 @@ -285,8 +297,6 @@ static void type_initialize(TypeImpl *ti) if (ti->class_init) { ti->class_init(ti->class, ti->class_data); } - - } =20 static void object_init_with_type(Object *obj, TypeImpl *ti) --=20 1.8.4