CpuModelInfo member @props is semantically a mapping from name to
value, and syntactically a JSON object on the wire. This translates
to QDict in C. Since the QAPI schema language lacks the means to
express 'object', we use 'any' instead. This is QObject in C.
Commands taking a CpuModelInfo argument need to check the QObject is a
QDict.
For arm, riscv, and s390x, the code checks right before passing the
QObject to visit_start_struct(). visit_start_struct() then checks
again.
Delete the first check.
The error message for @props that are not an object changes slightly
to the the message we get for this kind of type error in other
contexts. Minor improvement.
Additionally, error messages about members of @props now refer to
'props.prop-name' instead of just 'prop-name'. Another minor
improvement.
Both changes are visible in tests/qtest/arm-cpu-features.c.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-ID: <
20240305145919.
2186971-2-armbru@redhat.com>
Acked-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
[Drop #include now superfluous]
#include "qapi/qobject-input-visitor.h"
#include "qapi/qapi-commands-machine-target.h"
#include "qapi/qapi-commands-misc-target.h"
-#include "qapi/qmp/qerror.h"
#include "qapi/qmp/qdict.h"
#include "qom/qom-qobject.h"
Error **errp)
{
CpuModelExpansionInfo *expansion_info;
- const QDict *qdict_in = NULL;
+ const QDict *qdict_in;
QDict *qdict_out;
ObjectClass *oc;
Object *obj;
}
}
- if (model->props) {
- qdict_in = qobject_to(QDict, model->props);
- if (!qdict_in) {
- error_setg(errp, QERR_INVALID_PARAMETER_TYPE, "props", "dict");
- return NULL;
- }
- }
-
obj = object_new(object_class_get_name(oc));
- if (qdict_in) {
+ if (model->props) {
Visitor *visitor;
Error *err = NULL;
visitor = qobject_input_visitor_new(model->props);
- if (!visit_start_struct(visitor, NULL, NULL, 0, errp)) {
+ if (!visit_start_struct(visitor, "props", NULL, 0, errp)) {
visit_free(visitor);
object_unref(obj);
return NULL;
}
+ qdict_in = qobject_to(QDict, model->props);
i = 0;
while ((name = cpu_model_advertised_features[i++]) != NULL) {
if (qdict_get(qdict_in, name)) {
#include "qapi/qapi-commands-machine-target.h"
#include "qapi/qmp/qbool.h"
#include "qapi/qmp/qdict.h"
-#include "qapi/qmp/qerror.h"
#include "qapi/qobject-input-visitor.h"
#include "qapi/visitor.h"
#include "qom/qom-qobject.h"
}
static void riscv_cpuobj_validate_qdict_in(Object *obj, QObject *props,
- const QDict *qdict_in,
Error **errp)
{
+ const QDict *qdict_in;
const QDictEntry *qe;
Visitor *visitor;
Error *local_err = NULL;
visitor = qobject_input_visitor_new(props);
- if (!visit_start_struct(visitor, NULL, NULL, 0, &local_err)) {
+ if (!visit_start_struct(visitor, "props", NULL, 0, &local_err)) {
goto err;
}
+ qdict_in = qobject_to(QDict, props);
for (qe = qdict_first(qdict_in); qe; qe = qdict_next(qdict_in, qe)) {
object_property_find_err(obj, qe->key, &local_err);
if (local_err) {
Error **errp)
{
CpuModelExpansionInfo *expansion_info;
- const QDict *qdict_in = NULL;
QDict *qdict_out;
ObjectClass *oc;
Object *obj;
return NULL;
}
- if (model->props) {
- qdict_in = qobject_to(QDict, model->props);
- if (!qdict_in) {
- error_setg(errp, QERR_INVALID_PARAMETER_TYPE, "props", "dict");
- return NULL;
- }
- }
-
obj = object_new(object_class_get_name(oc));
riscv_check_if_cpu_available(RISCV_CPU(obj), &local_err);
return NULL;
}
- if (qdict_in) {
- riscv_cpuobj_validate_qdict_in(obj, model->props, qdict_in,
- &local_err);
+ if (model->props) {
+ riscv_cpuobj_validate_qdict_in(obj, model->props, &local_err);
if (local_err) {
error_propagate(errp, local_err);
object_unref(obj);
#include "sysemu/kvm.h"
#include "qapi/error.h"
#include "qapi/visitor.h"
-#include "qapi/qmp/qerror.h"
#include "qapi/qobject-input-visitor.h"
#include "qapi/qmp/qdict.h"
#include "qapi/qapi-commands-machine-target.h"
Error **errp)
{
Error *err = NULL;
- const QDict *qdict = NULL;
+ const QDict *qdict;
const QDictEntry *e;
Visitor *visitor;
ObjectClass *oc;
S390CPU *cpu;
Object *obj;
- if (info->props) {
- qdict = qobject_to(QDict, info->props);
- if (!qdict) {
- error_setg(errp, QERR_INVALID_PARAMETER_TYPE, "props", "dict");
- return;
- }
- }
-
oc = cpu_class_by_name(TYPE_S390_CPU, info->name);
if (!oc) {
error_setg(errp, "The CPU definition \'%s\' is unknown.", info->name);
return;
}
- if (qdict) {
+ if (info->props) {
visitor = qobject_input_visitor_new(info->props);
- if (!visit_start_struct(visitor, NULL, NULL, 0, errp)) {
+ if (!visit_start_struct(visitor, "props", NULL, 0, errp)) {
visit_free(visitor);
object_unref(obj);
return;
}
+ qdict = qobject_to(QDict, info->props);
for (e = qdict_first(qdict); e; e = qdict_next(qdict, e)) {
if (!object_property_set(obj, e->key, visitor, &err)) {
break;
g_assert(_resp); \
_error = resp_get_error(_resp); \
g_assert(_error); \
- g_assert(g_str_equal(_error, expected_error)); \
+ g_assert_cmpstr(_error, ==, expected_error); \
qobject_unref(_resp); \
})
g_assert(resp);
error = resp_get_error(resp);
g_assert(error);
- g_assert(g_str_equal(error,
- "The requested expansion type is not supported"));
+ g_assert_cmpstr(error, ==,
+ "The requested expansion type is not supported");
qobject_unref(resp);
}
g_assert(resp);
error = resp_get_error(resp);
g_assert(error);
- g_assert(g_str_equal(error,
- "Invalid parameter type for 'props', expected: dict"));
+ g_assert_cmpstr(error, ==,
+ "Invalid parameter type for 'props', expected: object");
qobject_unref(resp);
}
assert_bad_props(qts, "max");
assert_error(qts, "foo", "The CPU type 'foo' is not a recognized "
"ARM CPU type", NULL);
- assert_error(qts, "max", "Parameter 'not-a-prop' is unexpected",
+ assert_error(qts, "max", "Parameter 'props.not-a-prop' is unexpected",
"{ 'not-a-prop': false }");
assert_error(qts, "host", "The CPU type 'host' requires KVM", NULL);