qapi: Replace qobject_to_X(o) by qobject_to(X, o)

This patch was generated using the following Coccinelle script:

@@
expression Obj;
@@
(
- qobject_to_qnum(Obj)
+ qobject_to(QNum, Obj)
|
- qobject_to_qstring(Obj)
+ qobject_to(QString, Obj)
|
- qobject_to_qdict(Obj)
+ qobject_to(QDict, Obj)
|
- qobject_to_qlist(Obj)
+ qobject_to(QList, Obj)
|
- qobject_to_qbool(Obj)
+ qobject_to(QBool, Obj)
)

and a bit of manual fix-up for overly long lines and three places in
tests/check-qjson.c that Coccinelle did not find.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Alberto Garcia <berto@igalia.com>
Message-Id: <20180224154033.29559-4-mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
[eblake: swap order from qobject_to(o, X), rebase to master, also a fix
to latent false-positive compiler complaint about hw/i386/acpi-build.c]
Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
Max Reitz
2018-03-19 14:58:36 -05:00
committed by Eric Blake
parent 1a56b1e2ab
commit 7dc847ebba
51 changed files with 231 additions and 227 deletions
+2 -2
View File
@@ -1457,7 +1457,7 @@ static QDict *parse_json_filename(const char *filename, Error **errp)
return NULL;
}
options = qobject_to_qdict(options_obj);
options = qobject_to(QDict, options_obj);
if (!options) {
qobject_decref(options_obj);
error_setg(errp, "Invalid JSON object given");
@@ -2433,7 +2433,7 @@ BlockDriverState *bdrv_open_blockdev_ref(BlockdevRef *ref, Error **errp)
}
visit_complete(v, &obj);
qdict = qobject_to_qdict(obj);
qdict = qobject_to(QDict, obj);
qdict_flatten(qdict);
/* bdrv_open_inherit() defaults to the values in bdrv_flags (for
+1 -1
View File
@@ -647,7 +647,7 @@ static int coroutine_fn parallels_co_create_opts(const char *filename,
qobj = qdict_crumple(qdict, errp);
QDECREF(qdict);
qdict = qobject_to_qdict(qobj);
qdict = qobject_to(QDict, qobj);
if (qdict == NULL) {
ret = -EINVAL;
goto done;
+6 -6
View File
@@ -647,29 +647,29 @@ static void dump_qobject(fprintf_function func_fprintf, void *f,
{
switch (qobject_type(obj)) {
case QTYPE_QNUM: {
QNum *value = qobject_to_qnum(obj);
QNum *value = qobject_to(QNum, obj);
char *tmp = qnum_to_string(value);
func_fprintf(f, "%s", tmp);
g_free(tmp);
break;
}
case QTYPE_QSTRING: {
QString *value = qobject_to_qstring(obj);
QString *value = qobject_to(QString, obj);
func_fprintf(f, "%s", qstring_get_str(value));
break;
}
case QTYPE_QDICT: {
QDict *value = qobject_to_qdict(obj);
QDict *value = qobject_to(QDict, obj);
dump_qdict(func_fprintf, f, comp_indent, value);
break;
}
case QTYPE_QLIST: {
QList *value = qobject_to_qlist(obj);
QList *value = qobject_to(QList, obj);
dump_qlist(func_fprintf, f, comp_indent, value);
break;
}
case QTYPE_QBOOL: {
QBool *value = qobject_to_qbool(obj);
QBool *value = qobject_to(QBool, obj);
func_fprintf(f, "%s", qbool_get_bool(value) ? "true" : "false");
break;
}
@@ -730,7 +730,7 @@ void bdrv_image_info_specific_dump(fprintf_function func_fprintf, void *f,
visit_type_ImageInfoSpecific(v, NULL, &info_spec, &error_abort);
visit_complete(v, &obj);
data = qdict_get(qobject_to_qdict(obj), "data");
data = qdict_get(qobject_to(QDict, obj), "data");
dump_qobject(func_fprintf, f, 1, data);
qobject_decref(obj);
visit_free(v);
+1 -1
View File
@@ -996,7 +996,7 @@ static int coroutine_fn qcow_co_create_opts(const char *filename,
qobj = qdict_crumple(qdict, errp);
QDECREF(qdict);
qdict = qobject_to_qdict(qobj);
qdict = qobject_to(QDict, qobj);
if (qdict == NULL) {
ret = -EINVAL;
goto fail;
+1 -1
View File
@@ -3125,7 +3125,7 @@ static int coroutine_fn qcow2_co_create_opts(const char *filename, QemuOpts *opt
/* Now get the QAPI type BlockdevCreateOptions */
qobj = qdict_crumple(qdict, errp);
QDECREF(qdict);
qdict = qobject_to_qdict(qobj);
qdict = qobject_to(QDict, qobj);
if (qdict == NULL) {
ret = -EINVAL;
goto finish;
+1 -1
View File
@@ -764,7 +764,7 @@ static int coroutine_fn bdrv_qed_co_create_opts(const char *filename,
qobj = qdict_crumple(qdict, errp);
QDECREF(qdict);
qdict = qobject_to_qdict(qobj);
qdict = qobject_to(QDict, qobj);
if (qdict == NULL) {
ret = -EINVAL;
goto fail;
+4 -4
View File
@@ -263,14 +263,14 @@ static int qemu_rbd_set_keypairs(rados_t cluster, const char *keypairs_json,
if (!keypairs_json) {
return ret;
}
keypairs = qobject_to_qlist(qobject_from_json(keypairs_json,
&error_abort));
keypairs = qobject_to(QList,
qobject_from_json(keypairs_json, &error_abort));
remaining = qlist_size(keypairs) / 2;
assert(remaining);
while (remaining--) {
name = qobject_to_qstring(qlist_pop(keypairs));
value = qobject_to_qstring(qlist_pop(keypairs));
name = qobject_to(QString, qlist_pop(keypairs));
value = qobject_to(QString, qlist_pop(keypairs));
assert(name && value);
key = qstring_get_str(name);
+1 -1
View File
@@ -1887,7 +1887,7 @@ static int sd_create_prealloc(BlockdevOptionsSheepdog *location, int64_t size,
return -EINVAL;
}
qdict = qobject_to_qdict(obj);
qdict = qobject_to(QDict, obj);
qdict_flatten(qdict);
qdict_put_str(qdict, "driver", "sheepdog");
+1 -1
View File
@@ -1997,7 +1997,7 @@ static int coroutine_fn vhdx_co_create_opts(const char *filename,
qobj = qdict_crumple(qdict, errp);
QDECREF(qdict);
qdict = qobject_to_qdict(qobj);
qdict = qobject_to(QDict, qobj);
if (qdict == NULL) {
ret = -EINVAL;
goto fail;
+1 -1
View File
@@ -1120,7 +1120,7 @@ static int coroutine_fn vpc_co_create_opts(const char *filename,
qobj = qdict_crumple(qdict, errp);
QDECREF(qdict);
qdict = qobject_to_qdict(qobj);
qdict = qobject_to(QDict, qobj);
if (qdict == NULL) {
ret = -EINVAL;
goto fail;
+4 -3
View File
@@ -334,7 +334,8 @@ static bool parse_stats_intervals(BlockAcctStats *stats, QList *intervals,
case QTYPE_QSTRING: {
unsigned long long length;
const char *str = qstring_get_str(qobject_to_qstring(entry->value));
const char *str = qstring_get_str(qobject_to(QString,
entry->value));
if (parse_uint_full(str, &length, 10) == 0 &&
length > 0 && length <= UINT_MAX) {
block_acct_add_interval(stats, (unsigned) length);
@@ -346,7 +347,7 @@ static bool parse_stats_intervals(BlockAcctStats *stats, QList *intervals,
}
case QTYPE_QNUM: {
int64_t length = qnum_get_int(qobject_to_qnum(entry->value));
int64_t length = qnum_get_int(qobject_to(QNum, entry->value));
if (length > 0 && length <= UINT_MAX) {
block_acct_add_interval(stats, (unsigned) length);
@@ -4054,7 +4055,7 @@ void qmp_blockdev_add(BlockdevOptions *options, Error **errp)
}
visit_complete(v, &obj);
qdict = qobject_to_qdict(obj);
qdict = qobject_to(QDict, obj);
qdict_flatten(qdict);
+8 -8
View File
@@ -154,21 +154,21 @@ static void acpi_get_pm_info(AcpiPmInfo *pm)
/* Fill in optional s3/s4 related properties */
o = object_property_get_qobject(obj, ACPI_PM_PROP_S3_DISABLED, NULL);
if (o) {
pm->s3_disabled = qnum_get_uint(qobject_to_qnum(o));
pm->s3_disabled = qnum_get_uint(qobject_to(QNum, o));
} else {
pm->s3_disabled = false;
}
qobject_decref(o);
o = object_property_get_qobject(obj, ACPI_PM_PROP_S4_DISABLED, NULL);
if (o) {
pm->s4_disabled = qnum_get_uint(qobject_to_qnum(o));
pm->s4_disabled = qnum_get_uint(qobject_to(QNum, o));
} else {
pm->s4_disabled = false;
}
qobject_decref(o);
o = object_property_get_qobject(obj, ACPI_PM_PROP_S4_VAL, NULL);
if (o) {
pm->s4_val = qnum_get_uint(qobject_to_qnum(o));
pm->s4_val = qnum_get_uint(qobject_to(QNum, o));
} else {
pm->s4_val = false;
}
@@ -507,14 +507,14 @@ static void build_append_pcihp_notify_entry(Aml *method, int slot)
static void build_append_pci_bus_devices(Aml *parent_scope, PCIBus *bus,
bool pcihp_bridge_en)
{
Aml *dev, *notify_method, *method;
Aml *dev, *notify_method = NULL, *method;
QObject *bsel;
PCIBus *sec;
int i;
bsel = object_property_get_qobject(OBJECT(bus), ACPI_PCIHP_PROP_BSEL, NULL);
if (bsel) {
uint64_t bsel_val = qnum_get_uint(qobject_to_qnum(bsel));
uint64_t bsel_val = qnum_get_uint(qobject_to(QNum, bsel));
aml_append(parent_scope, aml_name_decl("BSEL", aml_int(bsel_val)));
notify_method = aml_method("DVNT", 2, AML_NOTSERIALIZED);
@@ -624,7 +624,7 @@ static void build_append_pci_bus_devices(Aml *parent_scope, PCIBus *bus,
/* If bus supports hotplug select it and notify about local events */
if (bsel) {
uint64_t bsel_val = qnum_get_uint(qobject_to_qnum(bsel));
uint64_t bsel_val = qnum_get_uint(qobject_to(QNum, bsel));
aml_append(method, aml_store(aml_int(bsel_val), aml_name("BNUM")));
aml_append(method,
@@ -2638,12 +2638,12 @@ static bool acpi_get_mcfg(AcpiMcfgInfo *mcfg)
if (!o) {
return false;
}
mcfg->mcfg_base = qnum_get_uint(qobject_to_qnum(o));
mcfg->mcfg_base = qnum_get_uint(qobject_to(QNum, o));
qobject_decref(o);
o = object_property_get_qobject(pci_host, PCIE_HOST_MCFG_SIZE, NULL);
assert(o);
mcfg->mcfg_size = qnum_get_uint(qobject_to_qnum(o));
mcfg->mcfg_size = qnum_get_uint(qobject_to(QNum, o));
qobject_decref(o);
return true;
}
+4 -4
View File
@@ -447,7 +447,7 @@ monitor_qapi_event_queue(QAPIEvent event, QDict *qdict, Error **errp)
/* Unthrottled event */
monitor_qapi_event_emit(event, qdict);
} else {
QDict *data = qobject_to_qdict(qdict_get(qdict, "data"));
QDict *data = qobject_to(QDict, qdict_get(qdict, "data"));
MonitorQAPIEventState key = { .event = event, .data = data };
evstate = g_hash_table_lookup(monitor_qapi_event_state, &key);
@@ -3777,7 +3777,7 @@ static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens)
goto err_out;
}
qdict = qobject_to_qdict(req);
qdict = qobject_to(QDict, req);
if (qdict) {
id = qdict_get(qdict, "id");
qobject_incref(id);
@@ -3793,7 +3793,7 @@ static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens)
rsp = qmp_dispatch(cur_mon->qmp.commands, req);
if (mon->qmp.commands == &qmp_cap_negotiation_commands) {
qdict = qdict_get_qdict(qobject_to_qdict(rsp), "error");
qdict = qdict_get_qdict(qobject_to(QDict, rsp), "error");
if (qdict
&& !g_strcmp0(qdict_get_try_str(qdict, "class"),
QapiErrorClass_str(ERROR_CLASS_COMMAND_NOT_FOUND))) {
@@ -3814,7 +3814,7 @@ err_out:
if (rsp) {
if (id) {
qdict_put_obj(qobject_to_qdict(rsp), "id", id);
qdict_put_obj(qobject_to(QDict, rsp), "id", id);
id = NULL;
}
+1 -1
View File
@@ -26,7 +26,7 @@ static QDict *qmp_dispatch_check_obj(const QObject *request, Error **errp)
bool has_exec_key = false;
QDict *dict = NULL;
dict = qobject_to_qdict(request);
dict = qobject_to(QDict, request);
if (!dict) {
error_setg(errp, "QMP input must be a JSON object");
return NULL;
+10 -10
View File
@@ -137,7 +137,7 @@ static QObject *qobject_input_try_get_object(QObjectInputVisitor *qiv,
if (qobject_type(qobj) == QTYPE_QDICT) {
assert(name);
ret = qdict_get(qobject_to_qdict(qobj), name);
ret = qdict_get(qobject_to(QDict, qobj), name);
if (tos->h && consume && ret) {
bool removed = g_hash_table_remove(tos->h, name);
assert(removed);
@@ -185,7 +185,7 @@ static const char *qobject_input_get_keyval(QObjectInputVisitor *qiv,
return NULL;
}
qstr = qobject_to_qstring(qobj);
qstr = qobject_to(QString, qobj);
if (!qstr) {
switch (qobject_type(qobj)) {
case QTYPE_QDICT:
@@ -224,11 +224,11 @@ static const QListEntry *qobject_input_push(QObjectInputVisitor *qiv,
if (qobject_type(obj) == QTYPE_QDICT) {
h = g_hash_table_new(g_str_hash, g_str_equal);
qdict_iter(qobject_to_qdict(obj), qdict_add_key, h);
qdict_iter(qobject_to(QDict, obj), qdict_add_key, h);
tos->h = h;
} else {
assert(qobject_type(obj) == QTYPE_QLIST);
tos->entry = qlist_first(qobject_to_qlist(obj));
tos->entry = qlist_first(qobject_to(QList, obj));
tos->index = -1;
}
@@ -395,7 +395,7 @@ static void qobject_input_type_int64(Visitor *v, const char *name, int64_t *obj,
if (!qobj) {
return;
}
qnum = qobject_to_qnum(qobj);
qnum = qobject_to(QNum, qobj);
if (!qnum || !qnum_get_try_int(qnum, obj)) {
error_setg(errp, QERR_INVALID_PARAMETER_TYPE,
full_name(qiv, name), "integer");
@@ -430,7 +430,7 @@ static void qobject_input_type_uint64(Visitor *v, const char *name,
if (!qobj) {
return;
}
qnum = qobject_to_qnum(qobj);
qnum = qobject_to(QNum, qobj);
if (!qnum) {
goto err;
}
@@ -477,7 +477,7 @@ static void qobject_input_type_bool(Visitor *v, const char *name, bool *obj,
if (!qobj) {
return;
}
qbool = qobject_to_qbool(qobj);
qbool = qobject_to(QBool, qobj);
if (!qbool) {
error_setg(errp, QERR_INVALID_PARAMETER_TYPE,
full_name(qiv, name), "boolean");
@@ -518,7 +518,7 @@ static void qobject_input_type_str(Visitor *v, const char *name, char **obj,
if (!qobj) {
return;
}
qstr = qobject_to_qstring(qobj);
qstr = qobject_to(QString, qobj);
if (!qstr) {
error_setg(errp, QERR_INVALID_PARAMETER_TYPE,
full_name(qiv, name), "string");
@@ -547,7 +547,7 @@ static void qobject_input_type_number(Visitor *v, const char *name, double *obj,
if (!qobj) {
return;
}
qnum = qobject_to_qnum(qobj);
qnum = qobject_to(QNum, qobj);
if (!qnum) {
error_setg(errp, QERR_INVALID_PARAMETER_TYPE,
full_name(qiv, name), "number");
@@ -734,7 +734,7 @@ Visitor *qobject_input_visitor_new_str(const char *str,
}
return NULL;
}
args = qobject_to_qdict(obj);
args = qobject_to(QDict, obj);
assert(args);
v = qobject_input_visitor_new(QOBJECT(args));
} else {
+2 -2
View File
@@ -92,11 +92,11 @@ static void qobject_output_add_obj(QObjectOutputVisitor *qov, const char *name,
switch (qobject_type(cur)) {
case QTYPE_QDICT:
assert(name);
qdict_put_obj(qobject_to_qdict(cur), name, value);
qdict_put_obj(qobject_to(QDict, cur), name, value);
break;
case QTYPE_QLIST:
assert(!name);
qlist_append_obj(qobject_to_qlist(cur), value);
qlist_append_obj(qobject_to(QList, cur), value);
break;
default:
g_assert_not_reached();
+1 -1
View File
@@ -607,7 +607,7 @@ static void process_event(JSONMessageParser *parser, GQueue *tokens)
g_assert(s && parser);
g_debug("process_event: called");
qdict = qobject_to_qdict(json_parser_parse_err(tokens, NULL, &err));
qdict = qobject_to(QDict, json_parser_parse_err(tokens, NULL, &err));
if (err || !qdict) {
QDECREF(qdict);
qdict = qdict_new();
+1 -1
View File
@@ -705,7 +705,7 @@ void qmp_object_add(const char *type, const char *id,
Object *obj;
if (props) {
pdict = qobject_to_qdict(props);
pdict = qobject_to(QDict, props);
if (!pdict) {
error_setg(errp, QERR_INVALID_PARAMETER_TYPE, "props", "dict");
return;
+1 -1
View File
@@ -308,7 +308,7 @@ static int parse_pair(JSONParserContext *ctxt, QDict *dict, va_list *ap)
goto out;
}
qdict_put_obj(dict, qstring_get_str(qobject_to_qstring(key)), value);
qdict_put_obj(dict, qstring_get_str(qobject_to(QString, key)), value);
qobject_decref(key);
+2 -2
View File
@@ -55,7 +55,7 @@ QBool *qobject_to_qbool(const QObject *obj)
*/
bool qbool_is_equal(const QObject *x, const QObject *y)
{
return qobject_to_qbool(x)->value == qobject_to_qbool(y)->value;
return qobject_to(QBool, x)->value == qobject_to(QBool, y)->value;
}
/**
@@ -65,5 +65,5 @@ bool qbool_is_equal(const QObject *x, const QObject *y)
void qbool_destroy_obj(QObject *obj)
{
assert(obj != NULL);
g_free(qobject_to_qbool(obj));
g_free(qobject_to(QBool, obj));
}

Some files were not shown because too many files have changed in this diff Show More