Remove dependency on qapi qtype, replace a field by a few helper functions to determine the default value type (introduced in commit 4f2d3d7).
Signed-off-by: Marc-André Lureau <marcandre.lur...@redhat.com> --- include/hw/qdev-core.h | 1 - include/hw/qdev-properties.h | 5 ----- hw/core/qdev.c | 32 ++++++++++++++++++++++++++------ 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 4bf86b0ad8..0f21a500cd 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -225,7 +225,6 @@ struct Property { PropertyInfo *info; ptrdiff_t offset; uint8_t bitnr; - QType qtype; int64_t defval; int arrayoffset; PropertyInfo *arrayinfo; diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h index 1d69fa7a8f..16d5d0629b 100644 --- a/include/hw/qdev-properties.h +++ b/include/hw/qdev-properties.h @@ -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), \ diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 02b632f6b3..83b0297755 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -755,6 +755,30 @@ static void qdev_property_add_legacy(DeviceState *dev, Property *prop, g_free(name); } +static bool prop_info_is_bool(const PropertyInfo *info) +{ + return info == &qdev_prop_bit + || info == &qdev_prop_bit64 + || info == &qdev_prop_bool; +} + +static bool prop_info_is_int(const PropertyInfo *info) +{ + return info == &qdev_prop_uint8 + || info == &qdev_prop_uint16 + || info == &qdev_prop_uint32 + || info == &qdev_prop_int32 + || info == &qdev_prop_uint64 + || info == &qdev_prop_size + || info == &qdev_prop_pci_devfn + || info == &qdev_prop_on_off_auto + || info == &qdev_prop_losttickpolicy + || info == &qdev_prop_blockdev_on_error + || info == &qdev_prop_bios_chs_trans + || info == &qdev_prop_blocksize + || info == &qdev_prop_arraylen; +} + /** * qdev_property_add_static: * @dev: Device to add the property to. @@ -794,16 +818,12 @@ 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) { + if (prop_info_is_bool(prop->info)) { 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) { + } else if (prop_info_is_int(prop->info)) { object_property_set_int(obj, prop->defval, prop->name, &error_abort); } } -- 2.13.0.rc1.16.gd80b50c3f