qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 2/4] qom: provide convenient macros for declaring and definin


From: Eduardo Habkost
Subject: Re: [PATCH 2/4] qom: provide convenient macros for declaring and defining types
Date: Sun, 9 Aug 2020 00:21:18 -0400

There are implicit requirements in the macros that will be a problem in some
existing type definitions:

On Thu, Jul 23, 2020 at 07:14:08PM +0100, Daniel P. Berrangé wrote:
[...]
> +/**
> + * OBJECT_DECLARE_TYPE:
> + * @ModuleObjName: the object name with initial capitalization
> + * @module_obj_name: the object name in lowercase with underscore separators
> + * @MODULE_OBJ_NAME: the object name in uppercase with underscore separators
> + *
> + * This macro is typically used in a header file, and will:
> + *
> + *   - create the typedefs for the object and class structs
> + *   - register the type for use with g_autoptr
> + *   - provide three standard type cast functions
> + *
> + * The object struct and class struct need to be declared manually.
> + */
> +#define OBJECT_DECLARE_TYPE(ModuleObjName, module_obj_name, MODULE_OBJ_NAME) 
> \
> +    typedef struct ModuleObjName ModuleObjName; \
> +    typedef struct ModuleObjName##Class ModuleObjName##Class; \

The ModuleObjName / ModuleObjName##Class pattern will be a problem in the 
following cases:

hw/arm/mps2-tz.c:107:1: class typedef MPS2TZMachineClass doesn't match instance 
typedef MPS2TZMachineState
hw/arm/mps2.c:83:1: class typedef MPS2MachineClass doesn't match instance 
typedef MPS2MachineState
hw/arm/musca.c:89:1: class typedef MuscaMachineClass doesn't match instance 
typedef MuscaMachineState
hw/arm/raspi.c:53:1: class typedef RaspiMachineClass doesn't match instance 
typedef RaspiMachineState
hw/arm/spitz.c:59:1: class typedef SpitzMachineClass doesn't match instance 
typedef SpitzMachineState
hw/arm/vexpress.c:182:1: class typedef VexpressMachineClass doesn't match 
instance typedef VexpressMachineState
hw/avr/arduino.c:36:1: class typedef ArduinoMachineClass doesn't match instance 
typedef ArduinoMachineState
hw/block/m25p80.c:462:1: class typedef M25P80Class doesn't match instance 
typedef Flash
hw/i386/kvm/i8254.c:40:1: class typedef KVMPITClass doesn't match instance 
typedef KVMPITState
hw/input/adb-kbd.c:33:1: class typedef ADBKeyboardClass doesn't match instance 
typedef KBDState
hw/input/adb-mouse.c:32:1: class typedef ADBMouseClass doesn't match instance 
typedef MouseState
hw/intc/arm_gic_kvm.c:34:1: class typedef KVMARMGICClass doesn't match instance 
typedef GICState
hw/intc/arm_gicv3_its_kvm.c:32:1: class typedef KVMARMITSClass doesn't match 
instance typedef GICv3ITSState
hw/intc/arm_gicv3_kvm.c:44:1: class typedef KVMARMGICv3Class doesn't match 
instance typedef GICv3State
hw/misc/tmp421.c:74:1: class typedef TMP421Class doesn't match instance typedef 
TMP421State
hw/rtc/m48t59-isa.c:39:1: class typedef M48txxISADeviceClass doesn't match 
instance typedef M48txxISAState
hw/rtc/m48t59.c:49:1: class typedef M48txxSysBusDeviceClass doesn't match 
instance typedef M48txxSysBusState
hw/rx/rx-gdbsim.c:53:1: class typedef RxGdbSimMachineClass doesn't match 
instance typedef RxGdbSimMachineState
hw/scsi/scsi-disk.c:56:1: class typedef SCSIDiskClass doesn't match instance 
typedef SCSIDiskState
hw/virtio/virtio-pci.h:29:1: class typedef VirtioPCIBusClass doesn't match 
instance typedef VirtioPCIBusState
hw/virtio/virtio-pci.h:101:1: class typedef VirtioPCIClass doesn't match 
instance typedef VirtIOPCIProxy
include/hw/boards.h:24:1: class typedef MachineClass doesn't match instance 
typedef MachineState
include/hw/i386/pc.h:124:1: class typedef PCMachineClass doesn't match instance 
typedef PCMachineState
include/hw/qdev-core.h:15:1: class typedef DeviceClass doesn't match instance 
typedef DeviceState
include/hw/qdev-core.h:206:1: class typedef BusClass doesn't match instance 
typedef BusState

> +    \
> +    G_DEFINE_AUTOPTR_CLEANUP_FUNC(ModuleObjName##Class, object_unref) \
> +    \
> +    static inline G_GNUC_UNUSED ModuleObjName##Class * \
> +    MODULE_OBJ_NAME##_GET_CLASS(void *obj) \
> +    { return OBJECT_GET_CLASS(ModuleObjName##Class, obj, \
> +                              TYPE_##MODULE_OBJ_NAME); } \

The TYPE_##MODULE_OBJ_NAME pattern will be a problem in the following cases:

accel/tcg/tcg-all.c:47:1: macro name TCG_STATE doesn't match type name 
TYPE_TCG_ACCEL
chardev/baum.c:106:1: macro name BAUM_CHARDEV doesn't match type name 
TYPE_CHARDEV_BRAILLE
chardev/char-parallel.c:57:1: macro name PARALLEL_CHARDEV doesn't match type 
name TYPE_CHARDEV_PARALLEL
chardev/char-parallel.c:184:1: macro name PARALLEL_CHARDEV doesn't match type 
name TYPE_CHARDEV_PARALLEL
chardev/char-pty.c:45:1: macro name PTY_CHARDEV doesn't match type name 
TYPE_CHARDEV_PTY
chardev/char-ringbuf.c:42:1: macro name RINGBUF_CHARDEV doesn't match type name 
TYPE_CHARDEV_RINGBUF
chardev/char-socket.c:88:1: macro name SOCKET_CHARDEV doesn't match type name 
TYPE_CHARDEV_SOCKET
chardev/char-udp.c:45:1: macro name UDP_CHARDEV doesn't match type name 
TYPE_CHARDEV_UDP
chardev/char-win-stdio.c:40:1: macro name WIN_STDIO_CHARDEV doesn't match type 
name TYPE_CHARDEV_WIN_STDIO
chardev/msmouse.c:46:1: macro name MOUSE_CHARDEV doesn't match type name 
TYPE_CHARDEV_MSMOUSE
chardev/testdev.c:41:1: macro name TESTDEV_CHARDEV doesn't match type name 
TYPE_CHARDEV_TESTDEV
chardev/wctablet.c:87:1: macro name WCTABLET_CHARDEV doesn't match type name 
TYPE_CHARDEV_WCTABLET
hw/audio/intel-hda.c:205:1: macro name INTEL_HDA doesn't match type name 
TYPE_INTEL_HDA_GENERIC
hw/char/etraxfs_ser.c:52:1: macro name ETRAX_SERIAL doesn't match type name 
TYPE_ETRAX_FS_SERIAL
hw/char/virtio-console.c:24:1: macro name VIRTIO_CONSOLE doesn't match type 
name TYPE_VIRTIO_CONSOLE_SERIAL_PORT
hw/display/ramfb-standalone.c:8:1: macro name RAMFB doesn't match type name 
TYPE_RAMFB_DEVICE
hw/i386/kvm/i8254.c:40:1: macro name KVM_PIT doesn't match type name 
TYPE_KVM_I8254
hw/i386/kvm/i8254.c:42:1: macro name KVM_PIT_CLASS doesn't match type name 
TYPE_KVM_I8254
hw/i386/kvm/i8254.c:44:1: macro name KVM_PIT_GET_CLASS doesn't match type name 
TYPE_KVM_I8254
hw/i386/kvm/i8259.c:22:1: macro name KVM_PIC_CLASS doesn't match type name 
TYPE_KVM_I8259
hw/i386/kvm/i8259.c:24:1: macro name KVM_PIC_GET_CLASS doesn't match type name 
TYPE_KVM_I8259
hw/intc/i8259.c:40:1: macro name PIC_CLASS doesn't match type name TYPE_I8259
hw/intc/i8259.c:41:1: macro name PIC_GET_CLASS doesn't match type name 
TYPE_I8259
hw/mips/boston.c:46:1: macro name BOSTON doesn't match type name 
TYPE_MIPS_BOSTON
hw/misc/edu.c:36:1: macro name EDU doesn't match type name TYPE_PCI_EDU_DEVICE
hw/misc/pvpanic.c:31:1: macro name ISA_PVPANIC_DEVICE doesn't match type name 
TYPE_PVPANIC
hw/net/can/can_kvaser_pci.c:48:1: macro name KVASER_PCI_DEV doesn't match type 
name TYPE_CAN_PCI_DEV
hw/net/can/can_mioe3680_pci.c:44:1: macro name MIOe3680_PCI_DEV doesn't match 
type name TYPE_CAN_PCI_DEV
hw/net/can/can_pcm3680_pci.c:44:1: macro name PCM3680i_PCI_DEV doesn't match 
type name TYPE_CAN_PCI_DEV
hw/net/e1000.c:150:1: macro name E1000 doesn't match type name TYPE_E1000_BASE
hw/net/e1000.c:153:1: macro name E1000_DEVICE_CLASS doesn't match type name 
TYPE_E1000_BASE
hw/net/e1000.c:156:1: macro name E1000_DEVICE_GET_CLASS doesn't match type name 
TYPE_E1000_BASE
hw/net/vmxnet3.c:135:1: macro name VMXNET3_DEVICE_CLASS doesn't match type name 
TYPE_VMXNET3
hw/net/vmxnet3.c:138:1: macro name VMXNET3_DEVICE_GET_CLASS doesn't match type 
name TYPE_VMXNET3
hw/pci-bridge/pci_expander_bridge.c:41:1: macro name PXB_DEV doesn't match type 
name TYPE_PXB_DEVICE
hw/pci-bridge/pci_expander_bridge.c:44:1: macro name PXB_PCIE_DEV doesn't match 
type name TYPE_PXB_PCIE_DEVICE
hw/pci-host/versatile.c:159:1: macro name PCI_VPB doesn't match type name 
TYPE_VERSATILE_PCI
hw/pci-host/versatile.c:163:1: macro name PCI_VPB_HOST doesn't match type name 
TYPE_VERSATILE_PCIHOST
hw/ppc/rs6000_mc.c:31:1: macro name RS6000MC_DEVICE doesn't match type name 
TYPE_RS6000MC
hw/scsi/esp-pci.c:38:1: macro name PCI_ESP doesn't match type name 
TYPE_AM53C974_DEVICE
hw/scsi/esp-pci.c:417:1: macro name DC390 doesn't match type name 
TYPE_DC390_DEVICE
hw/scsi/megasas.c:133:1: macro name MEGASAS doesn't match type name 
TYPE_MEGASAS_BASE
hw/scsi/megasas.c:136:1: macro name MEGASAS_DEVICE_CLASS doesn't match type 
name TYPE_MEGASAS_BASE
hw/scsi/megasas.c:139:1: macro name MEGASAS_DEVICE_GET_CLASS doesn't match type 
name TYPE_MEGASAS_BASE
hw/scsi/mptsas.c:46:1: macro name MPT_SAS doesn't match type name 
TYPE_MPTSAS1068
hw/scsi/vmw_pvscsi.c:66:1: macro name PVSCSI_DEVICE_CLASS doesn't match type 
name TYPE_PVSCSI
hw/scsi/vmw_pvscsi.c:69:1: macro name PVSCSI_DEVICE_GET_CLASS doesn't match 
type name TYPE_PVSCSI
hw/sparc/sun4m.c:777:1: macro name SUN4M_RAM doesn't match type name 
TYPE_SUN4M_MEMORY
hw/sparc64/sun4u.c:490:1: macro name SUN4U_RAM doesn't match type name 
TYPE_SUN4U_MEMORY
hw/timer/etraxfs_timer.c:51:1: macro name ETRAX_TIMER doesn't match type name 
TYPE_ETRAX_FS_TIMER
hw/timer/i8254.c:38:1: macro name PIT_CLASS doesn't match type name TYPE_I8254
hw/timer/i8254.c:40:1: macro name PIT_GET_CLASS doesn't match type name 
TYPE_I8254
hw/tpm/tpm_crb.c:47:1: macro name CRB doesn't match type name TYPE_TPM_CRB
hw/tpm/tpm_spapr.c:31:1: macro name VIO_SPAPR_VTPM doesn't match type name 
TYPE_TPM_SPAPR
hw/usb/ccid-card-emulated.c:48:1: macro name EMULATED_CCID_CARD doesn't match 
type name TYPE_EMULATED_CCID
hw/usb/ccid-card-passthru.c:67:1: macro name PASSTHRU_CCID_CARD doesn't match 
type name TYPE_CCID_PASSTHRU
hw/usb/dev-serial.c:114:1: macro name USB_SERIAL_DEV doesn't match type name 
TYPE_USB_SERIAL
hw/usb/dev-smartcard-reader.c:63:1: macro name USB_CCID_DEV doesn't match type 
name CCID_DEV_NAME
hw/usb/dev-storage.c:71:1: macro name USB_STORAGE_DEV doesn't match type name 
TYPE_USB_STORAGE
hw/usb/redirect.c:147:1: macro name USB_REDIRECT doesn't match type name 
TYPE_USB_REDIR
hw/usb/tusb6010.c:33:1: macro name TUSB doesn't match type name TYPE_TUSB6010
hw/vfio/ap.c:38:1: macro name VFIO_AP_DEVICE doesn't match type name 
VFIO_AP_DEVICE_TYPE
hw/vfio/pci.c:46:1: macro name PCI_VFIO doesn't match type name TYPE_VFIO_PCI
net/filter-rewriter.c:25:1: macro name FILTER_COLO_REWRITER doesn't match type 
name TYPE_FILTER_REWRITER
tests/check-qom-proplist.c:35:1: macro name DUMMY_OBJECT doesn't match type 
name TYPE_DUMMY
tests/test-qdev-global-props.c:34:1: macro name STATIC_TYPE doesn't match type 
name TYPE_STATIC_PROPS
tests/test-qdev-global-props.c:130:1: macro name DYNAMIC_TYPE doesn't match 
type name TYPE_DYNAMIC_PROPS
ui/console.c:1091:1: macro name VC_CHARDEV doesn't match type name 
TYPE_CHARDEV_VC
ui/gtk.c:181:1: macro name VC_CHARDEV doesn't match type name TYPE_CHARDEV_VC
ui/spice-app.c:48:1: macro name VC_CHARDEV doesn't match type name 
TYPE_CHARDEV_VC



> +    \
> +    static inline G_GNUC_UNUSED ModuleObjName##Class * \
> +    MODULE_OBJ_NAME##_CLASS(void *klass) \
> +    { return OBJECT_CLASS_CHECK(ModuleObjName##Class, klass, \
> +                                TYPE_##MODULE_OBJ_NAME); } \
> +    \
> +    static inline G_GNUC_UNUSED ModuleObjName * \
> +    MODULE_OBJ_NAME(void *obj) \
> +    { return OBJECT_CHECK(ModuleObjName, obj, \
> +                          TYPE_##MODULE_OBJ_NAME); }
> +
[...]

-- 
Eduardo




reply via email to

[Prev in Thread] Current Thread [Next in Thread]