mbox series

[PATCH-for-10.1,0/6] qom: Add object_class_implements_type()

Message ID 20250320154722.27349-1-philmd@linaro.org
Headers show
Series qom: Add object_class_implements_type() | expand

Message

Philippe Mathieu-Daudé March 20, 2025, 3:47 p.m. UTC
Hi,

object_class_dynamic_cast() checks whether a class implements
a type name, and return the class casted appropriately. This
also works with interfaces, except when an interface is
implemented multiple times (by intermediate abstract parents /
interfaces).

This series factors object_class_implements_type() out of
object_class_dynamic_cast() and use it (at least the meaning
seems clearer to me when reviewing).

I could get it working with object_class_foreach() but for
some reason fail at writing a proper test. Posting the last
patch as RFC so we can discuss it on the list.

Regards,

Phil.

Philippe Mathieu-Daudé (6):
  qom: Factor object_class_dynamic_cast_ambiguous() out
  qom: Add object_class_implements_type()
  qom: Test object_class_implements_type()
  qom: Prefer object_class_implements_type() to check type
    implementation
  qom: Use object_class_implements_type() in object_class_foreach()
  XXX qom: Test object_class_get_list()

 include/qom/object.h             | 10 ++++++
 chardev/char.c                   |  2 +-
 hw/arm/xlnx-versal-virt.c        |  2 +-
 hw/core/cpu-common.c             |  2 +-
 hw/core/machine.c                |  4 +--
 hw/i386/xen/xen_platform.c       |  2 +-
 hw/pci/pci.c                     |  6 ++--
 qom/object.c                     | 29 ++++++++++++++---
 qom/object_interfaces.c          |  2 +-
 qom/qom-qmp-cmds.c               |  4 +--
 system/qdev-monitor.c            |  4 +--
 system/tpm.c                     |  2 +-
 target/alpha/cpu.c               |  2 +-
 target/rx/cpu.c                  |  2 +-
 tests/unit/check-qom-interface.c | 56 ++++++++++++++++++++++++++++++++
 15 files changed, 108 insertions(+), 21 deletions(-)

Comments

Philippe Mathieu-Daudé March 20, 2025, 5:18 p.m. UTC | #1
On 20/3/25 16:47, Philippe Mathieu-Daudé wrote:
> Hi,
> 
> object_class_dynamic_cast() checks whether a class implements
> a type name, and return the class casted appropriately. This
> also works with interfaces, except when an interface is
> implemented multiple times (by intermediate abstract parents /
> interfaces).

I had a chat with Pierrick where he said diamond graph often leads
to problems, so it is safer to not allow multiple inheritance that
way; and returning the casted class is simple enough.

I'll see how to do differently, effectively not pursuing this series.

> 
> This series factors object_class_implements_type() out of
> object_class_dynamic_cast() and use it (at least the meaning
> seems clearer to me when reviewing).
> 
> I could get it working with object_class_foreach() but for
> some reason fail at writing a proper test. Posting the last
> patch as RFC so we can discuss it on the list.
> 
> Regards,
> 
> Phil.