* [Qemu-devel] [PATCH v2] qom: fix inherited interfaces
@ 2013-12-20 21:54 Paolo Bonzini
2013-12-24 0:18 ` Andreas Färber
0 siblings, 1 reply; 4+ messages in thread
From: Paolo Bonzini @ 2013-12-20 21:54 UTC (permalink / raw)
To: qemu-devel; +Cc: imammedo, peter.crosthwaite, afaerber
The interface type rework had two bugs with interfaces that are inherited
from a superclass. First of all, the implementation type name was wrong
(for example it was subclass::superclass::interface rather than
just subclass::interface). Second, interfaces not registering their
type anymore means that accessing superclass::interface by type name
will fail.
This can be fixed by pre-initializing ti->parent_type of subclass::interface
to superclass::interface.
Reported-by: Igor Mammedov <imammedo@redhat.com>
Tested-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
Andreas, perhaps this can be squashed with
'qom: do not register interface "types" in the type table'.
include/qom/object.h | 1 +
qom/object.c | 19 +++++++++++--------
2 files changed, 12 insertions(+), 8 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 750bb62..f696814 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -215,22 +215,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_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);
@@ -260,8 +263,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++) {
@@ -278,7 +283,7 @@ static void type_initialize(TypeImpl *ti)
continue;
}
- type_initialize_interface(ti, ti->interfaces[i].typename);
+ type_initialize_interface(ti, t, t);
}
}
@@ -294,8 +299,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.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH v2] qom: fix inherited interfaces
2013-12-20 21:54 [Qemu-devel] [PATCH v2] qom: fix inherited interfaces Paolo Bonzini
@ 2013-12-24 0:18 ` Andreas Färber
2013-12-24 11:17 ` Paolo Bonzini
0 siblings, 1 reply; 4+ messages in thread
From: Andreas Färber @ 2013-12-24 0:18 UTC (permalink / raw)
To: Paolo Bonzini, qemu-devel, Igor Mammedov; +Cc: peter.crosthwaite
Am 20.12.2013 22:54, schrieb Paolo Bonzini:
> The interface type rework had two bugs with interfaces that are inherited
> from a superclass. First of all, the implementation type name was wrong
> (for example it was subclass::superclass::interface rather than
> just subclass::interface). Second, interfaces not registering their
> type anymore means that accessing superclass::interface by type name
> will fail.
>
> This can be fixed by pre-initializing ti->parent_type of subclass::interface
> to superclass::interface.
>
> Reported-by: Igor Mammedov <imammedo@redhat.com>
> Tested-by: Igor Mammedov <imammedo@redhat.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> Andreas, perhaps this can be squashed with
> 'qom: do not register interface "types" in the type table'.
Thanks, I have squashed it, but I would appreciate if someone more
familiar with interfaces could take a quick look at my commit message
before I send a PULL tomorrow. Should I drop Reported-by during squash?
https://github.com/afaerber/qemu-cpu/commits/qom-next
Andreas
--
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH v2] qom: fix inherited interfaces
2013-12-24 0:18 ` Andreas Färber
@ 2013-12-24 11:17 ` Paolo Bonzini
2013-12-24 11:26 ` Andreas Färber
0 siblings, 1 reply; 4+ messages in thread
From: Paolo Bonzini @ 2013-12-24 11:17 UTC (permalink / raw)
To: Andreas Färber; +Cc: Igor Mammedov, peter.crosthwaite, qemu-devel
Il 24/12/2013 01:18, Andreas Färber ha scritto:
> Thanks, I have squashed it, but I would appreciate if someone more
> familiar with interfaces could take a quick look at my commit message
> before I send a PULL tomorrow. Should I drop Reported-by during squash?
>
> https://github.com/afaerber/qemu-cpu/commits/qom-next
I think it can be left in because the subclass::superclass::interface
bug was pre-existing. Here is a better wording:
qom: Do not register interface "types" in the type table and fix names
There should be no need to look them 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>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH v2] qom: fix inherited interfaces
2013-12-24 11:17 ` Paolo Bonzini
@ 2013-12-24 11:26 ` Andreas Färber
0 siblings, 0 replies; 4+ messages in thread
From: Andreas Färber @ 2013-12-24 11:26 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: Igor Mammedov, peter.crosthwaite, qemu-devel
Am 24.12.2013 12:17, schrieb Paolo Bonzini:
> Il 24/12/2013 01:18, Andreas Färber ha scritto:
>> Thanks, I have squashed it, but I would appreciate if someone more
>> familiar with interfaces could take a quick look at my commit message
>> before I send a PULL tomorrow. Should I drop Reported-by during squash?
>>
>> https://github.com/afaerber/qemu-cpu/commits/qom-next
>
> I think it can be left in because the subclass::superclass::interface
> bug was pre-existing. Here is a better wording:
>
> qom: Do not register interface "types" in the type table and fix names
>
> There should be no need to look them 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>
Thanks a lot, updated with one minor change: The initial "them" is now
ambiguous (types vs. names), so I've dropped it since the sentence ends
in "types" anyway.
Andreas
--
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-12-24 11:26 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-20 21:54 [Qemu-devel] [PATCH v2] qom: fix inherited interfaces Paolo Bonzini
2013-12-24 0:18 ` Andreas Färber
2013-12-24 11:17 ` Paolo Bonzini
2013-12-24 11:26 ` Andreas Färber
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).