Patchwork [v2,09/24] qdev: do not propagate properties to subclasses

login
register
mail settings
Submitter Paolo Bonzini
Date April 11, 2012, 9:30 p.m.
Message ID <1334179842-6061-9-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/151904/
State New
Headers show

Comments

Paolo Bonzini - April 11, 2012, 9:30 p.m.
As soon as we'll look up properties along the inheritance chain, we
will have duplicates if class A defines some properties and its
subclass B does not define any, because class_b->props will be
left equal to class_a->props.

The solution here is to reintroduce the class_base_init TypeInfo
callback, that was present in one of the early QOM versions but
removed (on my request...) before committing.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/qdev.c |   11 +++++++++++
 1 file changed, 11 insertions(+)

Patch

diff --git a/hw/qdev.c b/hw/qdev.c
index bb6c1aa..d622dd7 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -653,6 +653,16 @@  static void device_finalize(Object *obj)
     QTAILQ_REMOVE(&dev->parent_bus->children, dev, sibling);
 }
 
+static void device_class_base_init(ObjectClass *class, void *data)
+{
+    DeviceClass *klass = DEVICE_CLASS(class);
+
+    /* We explicitly look up properties in the superclasses,
+     * so do not propagate them to the subclasses.
+     */
+    klass->props = NULL;
+}
+
 void device_reset(DeviceState *dev)
 {
     DeviceClass *klass = DEVICE_GET_CLASS(dev);
@@ -679,6 +689,7 @@  static TypeInfo device_type_info = {
     .instance_size = sizeof(DeviceState),
     .instance_init = device_initfn,
     .instance_finalize = device_finalize,
+    .class_base_init = device_class_base_init,
     .abstract = true,
     .class_size = sizeof(DeviceClass),
 };