The typename parameter becomes a QAPITypeInfo pointer, and the validation compares prop->qapi_type against it instead of matching prop->type strings.
Signed-off-by: Marc-André Lureau <[email protected]> --- include/qom/object.h | 4 ++-- hw/core/machine-qmp-cmds.c | 3 ++- qom/object.c | 8 ++++---- tests/unit/check-qom-proplist.c | 6 +++--- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/include/qom/object.h b/include/qom/object.h index ba2df54258b..573414c7270 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -1410,7 +1410,7 @@ uint64_t object_property_get_uint(Object *obj, const char *name, * object_property_get_enum: * @obj: the object * @name: the name of the property - * @typename: the name of the enum data type + * @type_info: the QAPITypeInfo of the enum * @errp: returns an error if this function fails * * Returns: the value of the property, converted to an integer (which @@ -1418,7 +1418,7 @@ uint64_t object_property_get_uint(Object *obj, const char *name, * value is not an enum). */ int object_property_get_enum(Object *obj, const char *name, - const char *typename, Error **errp); + const QAPITypeInfo *type_info, Error **errp); /** * object_property_set: diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c index e62cb4ec888..9b449080dd5 100644 --- a/hw/core/machine-qmp-cmds.c +++ b/hw/core/machine-qmp-cmds.c @@ -17,6 +17,7 @@ #include "qapi/qapi-commands-accelerator.h" #include "qapi/qapi-commands-machine.h" #include "qobject/qobject.h" +#include "qapi/qapi-type-infos-common.h" #include "qapi/qobject-input-visitor.h" #include "qapi/type-helpers.h" #include "qemu/uuid.h" @@ -218,7 +219,7 @@ static int query_memdev(Object *obj, void *opaque) } else { m->has_reserve = true; } - m->policy = object_property_get_enum(obj, "policy", "HostMemPolicy", + m->policy = object_property_get_enum(obj, "policy", &HostMemPolicy_type_info, &error_abort); host_nodes = object_property_get_qobject(obj, "host-nodes", diff --git a/qom/object.c b/qom/object.c index c378d20c4db..08f2e93d0a1 100644 --- a/qom/object.c +++ b/qom/object.c @@ -1604,7 +1604,7 @@ uint64_t object_property_get_uint(Object *obj, const char *name, } int object_property_get_enum(Object *obj, const char *name, - const char *typename, Error **errp) + const QAPITypeInfo *type_info, Error **errp) { char *str; int ret; @@ -1614,10 +1614,10 @@ int object_property_get_enum(Object *obj, const char *name, return -1; } - if (!g_str_equal(prop->type, typename)) { + if (prop->qapi_type != type_info) { error_setg(errp, "Property %s on %s is not '%s' enum type", - name, object_class_get_name( - object_get_class(obj)), typename); + name, object_class_get_name(object_get_class(obj)), + type_info->name); return -1; } diff --git a/tests/unit/check-qom-proplist.c b/tests/unit/check-qom-proplist.c index 7f10befe687..d6703e64827 100644 --- a/tests/unit/check-qom-proplist.c +++ b/tests/unit/check-qom-proplist.c @@ -528,14 +528,14 @@ static void test_dummy_getenum(void) val = object_property_get_enum(OBJECT(dobj), "av", - "DummyAnimal", + &dummy_animal_qapi_type_info, &error_abort); g_assert(val == DUMMY_PLATYPUS); /* A bad enum type name */ val = object_property_get_enum(OBJECT(dobj), "av", - "BadAnimal", + &dummy_str_qapi_type_info, &err); g_assert(val == -1); error_free_or_abort(&err); @@ -543,7 +543,7 @@ static void test_dummy_getenum(void) /* A non-enum property name */ val = object_property_get_enum(OBJECT(dobj), "iv", - "DummyAnimal", + &dummy_animal_qapi_type_info, &err); g_assert(val == -1); error_free_or_abort(&err); -- 2.54.0
