Skip to content

Commit

Permalink
qapi: Replace qobject_to_X(o) by qobject_to(X, o)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
XanClic authored and ebblake committed Mar 19, 2018
1 parent 1a56b1e commit 7dc847e
Show file tree
Hide file tree
Showing 51 changed files with 231 additions and 227 deletions.
4 changes: 2 additions & 2 deletions block.c
Expand Up @@ -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");
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion block/parallels.c
Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions block/qapi.c
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion block/qcow.c
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion block/qcow2.c
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion block/qed.c
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions block/rbd.c
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion block/sheepdog.c
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion block/vhdx.c
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion block/vpc.c
Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions blockdev.c
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
16 changes: 8 additions & 8 deletions hw/i386/acpi-build.c
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions monitor.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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))) {
Expand All @@ -3814,7 +3814,7 @@ static void handle_qmp_command(JSONMessageParser *parser, GQueue *tokens)

if (rsp) {
if (id) {
qdict_put_obj(qobject_to_qdict(rsp), "id", id);
qdict_put_obj(qobject_to(QDict, rsp), "id", id);
id = NULL;
}

Expand Down
2 changes: 1 addition & 1 deletion qapi/qmp-dispatch.c
Expand Up @@ -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;
Expand Down
20 changes: 10 additions & 10 deletions qapi/qobject-input-visitor.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions qapi/qobject-output-visitor.c
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion qga/main.c
Expand Up @@ -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();
Expand Down

0 comments on commit 7dc847e

Please sign in to comment.