|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH v7 64/65] qom: use QAPITypeInfo in object_property_get_enum
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: Markus Armbruster <armbru@xxxxxxxxxx>
Signed-off-by: Marc-André Lureau <marcandre.lureau@xxxxxxxxxx>
---
hw/core/machine-qmp-cmds.c | 4 +++-
include/qom/object.h | 4 ++--
qom/object.c | 8 ++++----
tests/unit/check-qom-proplist.c | 6 +++---
4 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c
index 3fee45d568da..6b425baeb2da 100644
--- a/hw/core/machine-qmp-cmds.c
+++ b/hw/core/machine-qmp-cmds.c
@@ -18,6 +18,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"
@@ -252,7 +253,8 @@ 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/include/qom/object.h b/include/qom/object.h
index a9bbc44cfcc9..9f937e30dae5 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -1566,7 +1566,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
@@ -1574,7 +1574,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/qom/object.c b/qom/object.c
index 791d981dc689..40b569d4d574 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -1775,7 +1775,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;
@@ -1785,10 +1785,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 69155e720751..1cb48c7490ef 100644
--- a/tests/unit/check-qom-proplist.c
+++ b/tests/unit/check-qom-proplist.c
@@ -582,14 +582,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);
@@ -597,7 +597,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.56.0.116.g6de20f6092dc
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |