qobject/qapi: add uint type
v3 cover qobject/qapi: add uint type
Hi,
In previously sent series "[PATCH 00/21] WIP: dump: add kaslr support (for after 2.9)", I proposed changes to accept uint64 values from json, by adding a QUint type. During review, it was suggested to introduce a QNum type to hold various number representations.
This series introduces the QNum type, adds uint representation to it, and make uint64 values over json possible (while keeping json negative int for values >INT64_MAX to unsigned cast compatibility). It also improves some int vs uint usage for object properties and other QObject related clean-ups.
v3:
- rebased, drop the first keyval-related patches now upstream
- update "tests: Remove test cases for alternates of 'number' and 'int'" commit message, and drop now useless conflict checks
- added "qapi: minor refactoring"
- add missing Author/Copyright lines lost during merge
- add qnum_get_try_(u)int() and simplify related code
- fix some code comments
- replace g_assert_not_reached() with assert(0) in qapi/
- replace qapi/qmp/types.h include with the min required headers
- add comment about changes in json serialization in "qapi: update the qobject visitor to use QNUM_U64"
- update comment in "object: use more specific property type names" with the externally visible changes
- split "qdev: make default property int" patch, rename macros DEFINE_PROP_SIGNED/DEFINE_PROP_UNSIGNED
- in tests, compare with expected float value
- add r-b and suggested tags
v2:
- add set_default_value() callback in PropertyInfo
- use Markus version of "remove alt num-int cases"
- add more int/number ranges visitor checks
- replace Error usage for success bool return value in get_int/uint()
- various updated comments, patch and code reorganization
- avoid temporary regression from patch "json: learn to parse uint64 numbers", drop related patch
- split get_mmcfg_size() fix in a seperate patch
- added "apic-common: make "id" property a uint32" patch
- split the qdev uint proprety patch
- split "Use uint property getter/setter where appropriate" in various patches
- add some qdict tests
- dropped s3/s4 bool patch
- add some r-b tags
Marc-André Lureau (43):
qdev: remove PropertyInfo.qtype field
object: fix potential leak in getters
tests: Remove test cases for alternates of 'number' and 'int'
tests: add more int/number ranges checks
qapi: minor refactoring
qapi: merge QInt and QFloat in QNum
qapi: Remove visit_start_alternate() parameter promote_int
tests: remove /{qnum,qlist,dict}/destroy test
qnum: add uint type
json: learn to parse uint64 numbers
qapi: update the qobject visitor to use QNUM_U64
object: add uint property setter/getter
q35: fix get_mmcfg_size to use uint64 visitor
object: use more specific property type names
qdev: rename DEFINE_PROP_DEFAULT() to DEFINE_PROP_SIGNED()
qdev: wrap default property value in an union
qdev: avoid type casts between signed and unsigned
apic-common: make "id" property a uint32
qdev: use appropriate getter/setters type
isa: use get_uint() for "io-base"
pc-dimm: use get_uint() for dimm properties
pc-dimm: make "size" property uint64
pcihp: use get_uint() for "bsel" property
aspeed: use {set,get}_uint() for "ram-size" property
bcm2835_fb: use {get,set}_uint() for "vcram-size" and "vcram-base"
platform-bus: use get_uint() for "addr" property
acpi: use get_uint() for "acpi-pcihp-io*" properties
acpi: use get_uint() for various acpi properties
acpi: use get_uint() for "pci-hole*" properties
pc: use get_uint() for "iobase" property
pc: use get_uint() for "apic-id" property
pc: use get_uint() for "hpet-intcap" property
xen: use get_uint() for "max-ram-below-4g" property
arm: use get_uint() for "mp-affinity" property
auxbus: use get_uint() for "addr" property
pvpanic: use get_uint() for "ioport" property
pnv-core: use get_uint() for "core-pir" property
numa: use get_uint() for "size" property
i386/cpu: use get_uint() for "min-level"/"min-xlevel" properties
console: use get_uint() for "head" property tests/qdict: check more get_try_int() cases
RFC: qdict: add uint
qobject: move dump_qobject() from block/ to qobject/
include/qapi/visitor.h | 4 +- include/qapi/visitor-impl.h | 2 +- scripts/qapi.py | 36 +++-- scripts/qapi-visit.py | 12 +- include/hw/isa/isa.h | 2 +- include/hw/qdev-core.h | 7 +- include/hw/qdev-properties.h | 50 ++++--- include/qapi/qmp/qdict.h | 10 +- include/qapi/qmp/qfloat.h | 29 ---- include/qapi/qmp/qint.h | 28 ---- include/qapi/qmp/qlist.h | 5 +- include/qapi/qmp/qnum.h | 53 ++++++++ include/qapi/qmp/qobject.h | 7 + include/qapi/qmp/types.h | 3 +- include/qapi/qobject-input-visitor.h | 6 +- include/qapi/qobject-output-visitor.h | 8 +- include/qom/object.h | 23 ++++ qapi/qapi-visit-core.c | 6 +- backends/cryptodev.c | 2 +- block/blkdebug.c | 1 - block/nbd.c | 1 - block/nfs.c | 1 - block/qapi.c | 93 +------------ block/quorum.c | 1 - block/sheepdog.c | 1 - block/ssh.c | 1 - block/vvfat.c | 1 - blockdev.c | 8 +- hw/acpi/memory_hotplug.c | 12 +- hw/acpi/nvdimm.c | 18 +-- hw/acpi/pcihp.c | 7 +- hw/arm/aspeed.c | 8 +- hw/arm/bcm2835_peripherals.c | 9 +- hw/arm/raspi.c | 4 +- hw/block/fdc.c | 18 +-- hw/core/platform-bus.c | 2 +- hw/core/qdev-properties.c | 40 +++++- hw/core/qdev.c | 13 +- hw/i386/acpi-build.c | 71 +++++----- hw/i386/pc.c | 6 +- hw/i386/xen/xen-hvm.c | 6 +- hw/intc/apic_common.c | 10 +- hw/intc/arm_gicv3_common.c | 2 +- hw/mem/pc-dimm.c | 23 ++-- hw/misc/auxbus.c | 2 +- hw/misc/pvpanic.c | 2 +- hw/net/e1000e.c | 6 +- hw/pci-host/gpex.c | 2 +- hw/pci-host/piix.c | 8 +- hw/pci-host/q35.c | 15 +-- hw/pci-host/xilinx-pcie.c | 2 +- hw/ppc/pnv.c | 2 +- hw/ppc/pnv_core.c | 2 +- hw/ppc/spapr.c | 7 +- hw/usb/xen-usb.c | 1 - monitor.c | 2 +- net/dump.c | 2 +- net/filter-buffer.c | 2 +- numa.c | 6 +- qapi/qapi-clone-visitor.c | 2 +- qapi/qapi-dealloc-visitor.c | 2 +- qapi/qobject-input-visitor.c | 58 ++++---- qapi/qobject-output-visitor.c | 7 +- qga/commands.c | 2 +- qga/main.c | 1 - qobject/json-lexer.c | 4 + qobject/json-parser.c | 56 +++++--- qobject/qdict.c | 100 +++++++++++--- qobject/qfloat.c | 62 --------- qobject/qint.c | 61 --------- qobject/qjson.c | 37 +----- qobject/qlist.c | 23 ++++ qobject/qnum.c | 221 +++++++++++++++++++++++++++++++ qobject/qobject.c | 22 ++- qom/object.c | 51 +++++-- target/i386/cpu.c | 10 +- tests/check-qdict.c | 80 ++++++++--- tests/check-qfloat.c | 53 -------- tests/check-qint.c | 87 ------------ tests/check-qjson.c | 154 +++++++++++++++------ tests/check-qlist.c | 40 ++---- tests/check-qnum.c | 170 ++++++++++++++++++++++++ tests/check-qstring.c | 9 -- tests/test-keyval.c | 4 +- tests/test-qmp-commands.c | 8 +- tests/test-qmp-event.c | 9 +- tests/test-qobject-input-visitor.c | 110 ++++++++------- tests/test-qobject-output-visitor.c | 91 ++++++++----- tests/test-x86-cpuid-compat.c | 18 ++- ui/console.c | 4 +- ui/spice-core.c | 1 - ui/vnc-enc-tight.c | 1 - util/qemu-option.c | 24 ++-- MAINTAINERS | 3 +- qapi/trace-events | 2 +- qobject/Makefile.objs | 2 +- scripts/coccinelle/qobject.cocci | 4 +- tests/.gitignore | 3 +- tests/Makefile.include | 13 +- tests/qapi-schema/comments.out | 2 +- tests/qapi-schema/doc-good.out | 2 +- tests/qapi-schema/empty.out | 2 +- tests/qapi-schema/event-case.out | 2 +- tests/qapi-schema/ident-with-escape.out | 2 +- tests/qapi-schema/include-relpath.out | 2 +- tests/qapi-schema/include-repetition.out | 2 +- tests/qapi-schema/include-simple.out | 2 +- tests/qapi-schema/indented-expr.out | 2 +- tests/qapi-schema/qapi-schema-test.json | 2 - tests/qapi-schema/qapi-schema-test.out | 10 +- 110 files changed, 1331 insertions(+), 1019 deletions(-) delete mode 100644 include/qapi/qmp/qfloat.h delete mode 100644 include/qapi/qmp/qint.h create mode 100644 include/qapi/qmp/qnum.h delete mode 100644 qobject/qfloat.c delete mode 100644 qobject/qint.c create mode 100644 qobject/qnum.c delete mode 100644 tests/check-qfloat.c delete mode 100644 tests/check-qint.c create mode 100644 tests/check-qnum.c
Signature · 1 line
2.13.0.91.g00982b8dd
PATCH v3 1/43 qdev: remove PropertyInfo.qtype field
Remove dependency on qapi qtype, replace a field by a few PropertyInfo callbacks to set the default value type (introduced in commit 4f2d3d7).
--- include/hw/qdev-core.h | 2 +- include/hw/qdev-properties.h | 5 ----- hw/core/qdev-properties.c | 35 ++++++++++++++++++++++++++++++++++- hw/core/qdev.c | 13 ++----------- 4 files changed, 37 insertions(+), 18 deletions(-)
include/hw/qdev-core.h +1 -1
@@ -226,7 +226,6 @@ struct Property {PropertyInfo *info;ptrdiff_t offset;uint8_t bitnr; -QType qtype;int64_t defval;int arrayoffset;PropertyInfo *arrayinfo;
@@ -238,6 +237,7 @@ struct PropertyInfo {const char *description;const char *const *enum_table;int (*print)(DeviceState *dev,Property *prop,char *dest,size_t len); +void (*set_default_value)(Object *obj,const Property *prop);ObjectPropertyAccessor *get;ObjectPropertyAccessor *set;ObjectPropertyRelease *release;
include/hw/qdev-properties.h +0 -5
@@ -42,7 +42,6 @@ extern PropertyInfo qdev_prop_arraylen; .info = &(_prop), \ .offset = offsetof(_state, _field) \ + type_check(_type,typeof_field(_state, _field)), \ - .qtype = QTYPE_QINT, \ .defval = (_type)_defval, \ }#define DEFINE_PROP_BIT (_name, _state, _field, _bit, _defval) { \
@@ -51,7 +50,6 @@ extern PropertyInfo qdev_prop_arraylen; .bitnr = (_bit), \ .offset = offsetof(_state, _field) \ + type_check(uint32_t,typeof_field(_state, _field)), \ - .qtype = QTYPE_QBOOL, \ .defval = (bool)_defval, \ }#define DEFINE_PROP_BIT64 (_name, _state, _field, _bit, _defval) { \
@@ -60,7 +58,6 @@ extern PropertyInfo qdev_prop_arraylen; .bitnr = (_bit), \ .offset = offsetof(_state, _field) \ + type_check(uint64_t, typeof_field(_state, _field)), \ - .qtype = QTYPE_QBOOL, \ .defval = (bool)_defval, \ }
@@ -69,7 +66,6 @@ extern PropertyInfo qdev_prop_arraylen; .info = &(qdev_prop_bool), \ .offset = offsetof(_state, _field) \ + type_check(bool, typeof_field(_state, _field)), \ - .qtype = QTYPE_QBOOL, \ .defval = (bool)_defval, \ }
@@ -105,7 +101,6 @@ extern PropertyInfo qdev_prop_arraylen; .info = &(qdev_prop_arraylen), \ .offset = offsetof(_state , _field) \ + type_check(uint32_t, typeof_field(_state, _field)), \ - .qtype = QTYPE_QINT, \ .arrayinfo = &(_arrayprop), \ .arrayfieldsize = sizeof(_arraytype), \ .arrayoffset = offsetof(_state, _arrayfield), \
hw/core/qdev-properties.c +34 -1
@@ -69,6 +69,12 @@ static void set_enum(Object *obj, Visitor *v, const char *name, void *opaque,visit_type_enum (v, prop->name, ptr, prop->info->enum_table, errp); } +static void set_default_value_enum (Object *obj,const Property *prop) +{ +object_property_set_str (obj, prop->info->enum_table[prop->defval], + prop->name, &error_abort); +} +/* Bit */ static uint32_t qdev_get_prop_mask (Property *prop)
@@ -120,11 +126,17 @@ static void prop_set_bit(Object *obj, Visitor *v, const char *name,bit_prop_set (dev, prop, value); } +static void set_default_value_bool (Object *obj,const Property *prop) +{ +object_property_set_bool (obj, prop->defval, prop->name, &error_abort); +} +PropertyInfo qdev_prop_bit = { .name ="bool" , .description ="on/off" , .get = prop_get_bit, .set = prop_set_bit, + .set_default_value = set_default_value_bool, };/* Bit64 */
@@ -183,6 +195,7 @@ PropertyInfo qdev_prop_bit64 = { .description = "on/off", .get = prop_get_bit64, .set = prop_set_bit64, + .set_default_value = set_default_value_bool, };/* --- bool --- */
@@ -216,6 +229,7 @@ PropertyInfo qdev_prop_bool = { .name = "bool", .get = get_bool, .set = set_bool, + .set_default_value = set_default_value_bool, };/* --- 8bit integer --- */
@@ -245,10 +259,16 @@ static void set_uint8(Object *obj, Visitor *v, const char *name, void *opaque,visit_type_uint8 (v, name, ptr, errp); } +static void set_default_value_int (Object *obj,const Property *prop) +{ +object_property_set_int (obj, prop->defval, prop->name, &error_abort); +} +PropertyInfo qdev_prop_uint8 = { .name ="uint8" , .get = get_uint8, .set = set_uint8, + .set_default_value = set_default_value_int, };/* --- 16bit integer --- */
@@ -282,6 +302,7 @@ PropertyInfo qdev_prop_uint16 = { .name = "uint16", .get = get_uint16, .set = set_uint16, + .set_default_value = set_default_value_int, };/* --- 32bit integer --- */
@@ -340,12 +361,14 @@ PropertyInfo qdev_prop_uint32 = { .name = "uint32", .get = get_uint32, .set = set_uint32, + .set_default_value = set_default_value_int, };PropertyInfo qdev_prop_int32 = { .name ="int32" , .get = get_int32, .set = set_int32, + .set_default_value = set_default_value_int, };/* --- 64bit integer --- */
@@ -379,6 +402,7 @@ PropertyInfo qdev_prop_uint64 = { .name = "uint64", .get = get_uint64, .set = set_uint64, + .set_default_value = set_default_value_int, };/* --- string --- */
@@ -526,6 +550,7 @@ PropertyInfo qdev_prop_on_off_auto = { .enum_table = OnOffAuto_lookup, .get = get_enum, .set = set_enum, + .set_default_value = set_default_value_enum, };/* --- lost tick policy --- */
@@ -537,6 +562,7 @@ PropertyInfo qdev_prop_losttickpolicy = { .enum_table = LostTickPolicy_lookup, .get = get_enum, .set = set_enum, + .set_default_value = set_default_value_enum, };/* --- Block device error handling policy --- */
@@ -550,6 +576,7 @@ PropertyInfo qdev_prop_blockdev_on_error = { .enum_table = BlockdevOnError_lookup, .get = get_enum, .set = set_enum, + .set_default_value = set_default_value_enum, };/* --- BIOS CHS translation */
@@ -563,6 +590,7 @@ PropertyInfo qdev_prop_bios_chs_trans = { .enum_table = BiosAtaTranslation_lookup, .get = get_enum, .set = set_enum, + .set_default_value = set_default_value_enum, };/* --- FDC default drive types */
@@ -573,7 +601,8 @@ PropertyInfo qdev_prop_fdc_drive_type = { "144/288/120/none/auto", .enum_table = FloppyDriveType_lookup, .get = get_enum, - .set = set_enum + .set = set_enum, + .set_default_value = set_default_value_enum, };/* --- pci address --- */
@@ -648,6 +677,7 @@ PropertyInfo qdev_prop_pci_devfn = { .print = print_pci_devfn, .get = get_int32, .set = set_pci_devfn, + .set_default_value = set_default_value_int, };/* --- blocksize --- */
@@ -695,6 +725,7 @@ PropertyInfo qdev_prop_blocksize = { .description = "A power of two between 512 and 32768", .get = get_uint16, .set = set_blocksize, + .set_default_value = set_default_value_int, };/* --- pci host address --- */
@@ -917,6 +948,7 @@ PropertyInfo qdev_prop_arraylen = { .name = "uint32", .get = get_uint32, .set = set_prop_arraylen, + .set_default_value = set_default_value_int, };/* --- public helpers --- */
@@ -1153,4 +1185,5 @@ PropertyInfo qdev_prop_size = { .name = "size", .get = get_size, .set = set_size, + .set_default_value = set_default_value_int, };
hw/core/qdev.c +2 -11
@@ -793,17 +793,8 @@ void qdev_property_add_static(DeviceState *dev, Property *prop, prop->info->description, &error_abort); -if (prop->qtype ==QTYPE_NONE ) { -return ; - } - -if (prop->qtype ==QTYPE_QBOOL ) { -object_property_set_bool (obj, prop->defval, prop->name, &error_abort); - }else if (prop->info->enum_table) { -object_property_set_str (obj, prop->info->enum_table[prop->defval], - prop->name, &error_abort); - }else if (prop->qtype ==QTYPE_QINT ) { -object_property_set_int (obj, prop->defval, prop->name, &error_abort); +if (prop->info->set_default_value) { + prop->info->set_default_value (obj, prop); } }
Signature · 1 line
2.13.0.91.g00982b8dd
PATCH v3 2/43 object: fix potential leak in getters
In reply to Marc-André LureauIf the property is not of the requested type, the getters will leak a QObject.
--- qom/object.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
qom/object.c +3 -3
@@ -1122,7 +1122,7 @@ char *object_property_get_str(Object *obj, const char *name, retval =g_strdup (qstring_get_str (qstring)); } -QDECREF (qstring); +qobject_decref (ret);return retval; }
@@ -1183,7 +1183,7 @@ bool object_property_get_bool(Object *obj, const char *name, retval =qbool_get_bool (qbool); } -QDECREF (qbool); +qobject_decref (ret);return retval; }
@@ -1214,7 +1214,7 @@ int64_t object_property_get_int(Object *obj, const char *name, retval =qint_get_int (qint); } -QDECREF (qint); +qobject_decref (ret);return retval; }
Signature · 1 line
2.13.0.91.g00982b8dd