From: "Andreas Färber" <afaerber@suse.de>
To: qemu-devel@nongnu.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
"Andreas Färber" <afaerber@suse.de>
Subject: [Qemu-devel] [PULL 15/24] qom: Do not register interface "types" in the type table and fix names
Date: Tue, 24 Dec 2013 17:57:08 +0100 [thread overview]
Message-ID: <1387904237-6941-16-git-send-email-afaerber@suse.de> (raw)
In-Reply-To: <1387904237-6941-1-git-send-email-afaerber@suse.de>
From: Paolo Bonzini <pbonzini@redhat.com>
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 <imammedo@redhat.com>
Tested-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
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;
};
#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);
}
-static TypeImpl *type_register_internal(const TypeInfo *info)
+static TypeImpl *type_new(const TypeInfo *info)
{
TypeImpl *ti = g_malloc0(sizeof(*ti));
int i;
@@ -122,8 +122,15 @@ static TypeImpl *type_register_internal(const TypeInfo *info)
}
ti->num_interfaces = i;
- type_table_add(ti);
+ return ti;
+}
+static TypeImpl *type_register_internal(const TypeInfo *info)
+{
+ TypeImpl *ti;
+ ti = type_new(info);
+
+ type_table_add(ti);
return ti;
}
@@ -206,22 +213,25 @@ static bool type_is_ancestor(TypeImpl *type, TypeImpl *target_type)
static void type_initialize(TypeImpl *ti);
-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 = { };
TypeImpl *iface_impl;
- info.parent = parent;
- info.name = g_strdup_printf("%s::%s", ti->name, info.parent);
+ info.parent = parent_type->name;
+ info.name = g_strdup_printf("%s::%s", ti->name, interface_type->name);
info.abstract = true;
- iface_impl = type_register(&info);
+ iface_impl = type_new(&info);
+ iface_impl->parent_type = parent_type;
type_initialize(iface_impl);
g_free((char *)info.name);
new_iface = (InterfaceClass *)iface_impl->class;
new_iface->concrete_class = ti->class;
+ new_iface->interface_type = interface_type;
ti->class->interfaces = g_slist_append(ti->class->interfaces,
iface_impl->class);
@@ -251,8 +261,10 @@ static void type_initialize(TypeImpl *ti)
ti->class->interfaces = NULL;
for (e = parent->class->interfaces; e; e = e->next) {
- ObjectClass *iface = e->data;
- type_initialize_interface(ti, object_class_get_name(iface));
+ InterfaceClass *iface = e->data;
+ ObjectClass *klass = OBJECT_CLASS(iface);
+
+ type_initialize_interface(ti, iface->interface_type, klass->type);
}
for (i = 0; i < ti->num_interfaces; i++) {
@@ -269,7 +281,7 @@ static void type_initialize(TypeImpl *ti)
continue;
}
- type_initialize_interface(ti, ti->interfaces[i].typename);
+ type_initialize_interface(ti, t, t);
}
}
@@ -285,8 +297,6 @@ static void type_initialize(TypeImpl *ti)
if (ti->class_init) {
ti->class_init(ti->class, ti->class_data);
}
-
-
}
static void object_init_with_type(Object *obj, TypeImpl *ti)
--
1.8.4
next prev parent reply other threads:[~2013-12-24 16:57 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-24 16:56 [Qemu-devel] [PULL 00/24] QOM devices patch queue 2013-12-24 Andreas Färber
2013-12-24 16:56 ` [Qemu-devel] [PULL 01/24] qdev: Replace no_user by cannot_instantiate_with_device_add_yet Andreas Färber
2013-12-24 16:56 ` [Qemu-devel] [PULL 02/24] sysbus: Set cannot_instantiate_with_device_add_yet Andreas Färber
2013-12-24 16:56 ` [Qemu-devel] [PULL 03/24] cpu: Document why cannot_instantiate_with_device_add_yet Andreas Färber
2013-12-24 16:56 ` [Qemu-devel] [PULL 04/24] apic: " Andreas Färber
2013-12-24 16:56 ` [Qemu-devel] [PULL 05/24] pci-host: Consistently set cannot_instantiate_with_device_add_yet Andreas Färber
2013-12-24 16:56 ` [Qemu-devel] [PULL 06/24] ich9: Document why cannot_instantiate_with_device_add_yet Andreas Färber
2013-12-24 16:57 ` [Qemu-devel] [PULL 07/24] piix3 piix4: Clean up use of cannot_instantiate_with_device_add_yet Andreas Färber
2013-12-24 16:57 ` [Qemu-devel] [PULL 08/24] vt82c686: " Andreas Färber
2013-12-24 16:57 ` [Qemu-devel] [PULL 09/24] isa: " Andreas Färber
2013-12-24 16:57 ` [Qemu-devel] [PULL 10/24] qdev: Do not let the user try to device_add when it cannot work Andreas Färber
2013-12-24 16:57 ` [Qemu-devel] [PULL 11/24] qdev-monitor: Avoid device_add crashing on non-device driver name Andreas Färber
2013-12-24 16:57 ` [Qemu-devel] [PULL 12/24] hw: cannot_instantiate_with_device_add_yet due to pointer props Andreas Färber
2013-12-24 16:57 ` [Qemu-devel] [PULL 13/24] qdev: Document that pointer properties kill device_add Andreas Färber
2013-12-24 16:57 ` [Qemu-devel] [PULL 14/24] qom: Split out object and class caches Andreas Färber
2013-12-24 16:57 ` Andreas Färber [this message]
2013-12-24 16:57 ` [Qemu-devel] [PULL 16/24] tests: Test QOM interface casting Andreas Färber
2013-12-24 16:57 ` [Qemu-devel] [PULL 17/24] qom: Detect bad reentrance during object_class_foreach() Andreas Färber
2013-12-24 16:57 ` [Qemu-devel] [PULL 18/24] qdev: Drop misleading qbus_free() function Andreas Färber
2013-12-24 16:57 ` [Qemu-devel] [PULL 19/24] apic: Cleanup for QOM'ification Andreas Färber
2013-12-24 16:57 ` [Qemu-devel] [PULL 20/24] apic: QOM'ify APIC Andreas Färber
2013-12-24 16:57 ` [Qemu-devel] [PULL 21/24] icc_bus: QOM'ify ICC Andreas Färber
2013-12-24 16:57 ` [Qemu-devel] [PULL 22/24] ioapic: Cleanup for QOM'ification Andreas Färber
2013-12-24 16:57 ` [Qemu-devel] [PULL 23/24] ioapic: QOM'ify ioapic Andreas Färber
2013-12-24 16:57 ` [Qemu-devel] [PULL 24/24] qdev-monitor: Improve error message for -device nonexistant Andreas Färber
2013-12-24 17:01 ` [Qemu-devel] [PULL 00/24] QOM devices patch queue 2013-12-24 Andreas Färber
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1387904237-6941-16-git-send-email-afaerber@suse.de \
--to=afaerber@suse.de \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).