Skip to contentSkip to conversation

qom: remove unused field

PATCH In review Paolo Bonzini 3 participants 3 messages Jan 7, 2025 – Jan 9, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qom: remove unused field

The "concrete_class" field of InterfaceClass is only ever written, and as far as I can tell is not particularly useful when debugging either; remove it.

---
 include/qom/object.h | 5 ++++-
 qom/object.c         | 1 -
 2 files changed, 4 insertions(+), 2 deletions(-)
include/qom/object.h +4 -1
index 95d6e064d9b..f28ffea9a64 100644
@@ -573,12 +573,15 @@ struct InterfaceInfo {
  *
  * The class for all interfaces.  Subclasses of this class should only add
  * virtual methods.
+ *
+ * Note that most of the fields of ObjectClass are unused (all except
+ * "type", in fact).  They are only present in InterfaceClass to allow
+ * @object_class_dynamic_cast to work with both regular classes and interfaces.
  */
 struct InterfaceClass
 {
     ObjectClass parent_class;
     /* private: */
-    ObjectClass *concrete_class;
     Type interface_type;
 };
 
qom/object.c +0 -1
index b4c52d055d9..e9dfad854bd 100644
@@ -314,7 +314,6 @@ static void type_initialize_interface(TypeImpl *ti, TypeImpl *interface_type,
     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, new_iface);
Signature · 1 line
2.47.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Paolo Bonzini

The "concrete_class" field of InterfaceClass is only ever written, and as far as I can tell is not particularly useful when debugging either; remove it.

I think the reason to have the field would be if we supported "given a pointer to an interface class, get the concrete class"; e.g. supposing i have a ResettableClass *rc it would be nice to be able to do
DeviceClass *dc = DEVICE_CLASS(rc);
(asserting if your rc isn't actually one provided by a DeviceClass, obviously). This doesn't currently work because we don't have the code to actually do this, but apparently GObject's object model does support this. See this thread from a few years back:

https://lore.kernel.org/qemu-devel/CAFEAcA8Q3XZrdLJhJ4Uj1CX6J04ON9f91p=NuJXxA+cnEfdz6Q@mail.gmail.com/

But we've lived without this forever (and the thing I wanted it for back then I ended up not needing), so it seems fine to remove the field now; easy enough to put it back in future if somebody does decide to implement cast-to-concrete-class.

thanks
-- PMM