* [PATCH] qom/type_initialize_interface: inherit .class_data from the template TypeInfo
@ 2019-10-27 12:56 Maciej Bielski
0 siblings, 0 replies; only message in thread
From: Maciej Bielski @ 2019-10-27 12:56 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-trivial, Paolo Bonzini, Maciej Bielski,
Daniel P. Berrangé, Eduardo Habkost
The `TypeInfo::class_data` value of an interface is never properly
propagated for initializations of all types implementing the interface.
Although interfaces are rarely used, IMHO their functionality is
currently a bit incomplete.
A `TypeInfo fooable_info` of an interface "fooable" may have the
`.class_base_init` callback and the `.class_data` field defined. Let's
assume that `.class_data = 0xdeadbeef`. Additionally, the `fooable_info`
is only used to allocate one associated instance of `TypeImpl`, let's
say `fooable_impl`.
Then, for each type `TypeInfo xyz_info`, that implements the interface
"fooable", there is another `TypeInfo info` (and associated TypeImpl)
automatically created within `type_initialize_interface()`. The
automatic `info` reflects the fact that the interface "fooable" is
implemented by `xyz_info` (for example by having
`.name="xyz::fooable"`). In a way, the `info` inherits from
`fooable_impl`, for example it sets `.parent` field accordingly.
The problem is that this inheritance is fixed by the implementation of
`type_initialize_interface` and the `info.class_data` is always `NULL`.
Further, this NULL value is passed to `fooable_info::class_base_init()`,
where actually a common-sense expectation would be to have the
`0xdeadbeef` from the interface definition.
The fix below seems to be the easiest solution. Another option would be
to dereference `klass->type->parent_type->...->parent_type->class_data`
but the `TypeImpl` definition is (perhaps on purpose) private to
`qom/object.c`.
Signed-off-by: Maciej Bielski <bielski.maciek@gmail.com>
---
qom/object.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/qom/object.c b/qom/object.c
index aac08351b7..dc305e14b0 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -248,6 +248,7 @@ static void type_initialize_interface(TypeImpl *ti, TypeImpl *interface_type,
TypeImpl *iface_impl;
info.parent = parent_type->name;
+ info.class_data = parent_type->class_data;
info.name = g_strdup_printf("%s::%s", ti->name, interface_type->name);
info.abstract = true;
--
2.21.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2019-10-27 14:01 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-10-27 12:56 [PATCH] qom/type_initialize_interface: inherit .class_data from the template TypeInfo Maciej Bielski
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).