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.

Backports commit 7dc847ebba953db90853d15f140c20eef74d4fb2 from qemu
This commit is contained in:
Max Reitz 2018-03-20 10:52:49 -04:00 committed by Lioncash
parent dbdba16732
commit 275b2ac328
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7
9 changed files with 49 additions and 49 deletions

View file

@ -129,7 +129,7 @@ static QObject *qobject_input_try_get_object(QObjectInputVisitor *qiv,
if (qobject_type(qobj) == QTYPE_QDICT) { if (qobject_type(qobj) == QTYPE_QDICT) {
assert(name); assert(name);
ret = qdict_get(qobject_to_qdict(qobj), name); ret = qdict_get(qobject_to(QDict, qobj), name);
if (tos->h && consume && ret) { if (tos->h && consume && ret) {
bool removed = g_hash_table_remove(tos->h, name); bool removed = g_hash_table_remove(tos->h, name);
assert(removed); assert(removed);
@ -185,11 +185,11 @@ static const QListEntry *qobject_input_push(QObjectInputVisitor *qiv,
if (qobject_type(obj) == QTYPE_QDICT) { if (qobject_type(obj) == QTYPE_QDICT) {
h = g_hash_table_new(g_str_hash, g_str_equal); 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; tos->h = h;
} else { } else {
assert(qobject_type(obj) == QTYPE_QLIST); 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; tos->index = -1;
} }
@ -353,7 +353,7 @@ static void qobject_input_type_int64(Visitor *v, const char *name, int64_t *obj,
if (!qobj) { if (!qobj) {
return; return;
} }
qnum = qobject_to_qnum(qobj); qnum = qobject_to(QNum, qobj);
if (!qnum || !qnum_get_try_int(qnum, obj)) { if (!qnum || !qnum_get_try_int(qnum, obj)) {
error_setg(errp, QERR_INVALID_PARAMETER_TYPE, error_setg(errp, QERR_INVALID_PARAMETER_TYPE,
full_name(qiv, name), "integer"); full_name(qiv, name), "integer");
@ -371,7 +371,7 @@ static void qobject_input_type_uint64(Visitor *v, const char *name, uint64_t *ob
if (!qobj) { if (!qobj) {
return; return;
} }
qnum = qobject_to_qnum(qobj); qnum = qobject_to(QNum, qobj);
if (!qnum) { if (!qnum) {
goto err; goto err;
} }
@ -401,7 +401,7 @@ static void qobject_input_type_bool(Visitor *v, const char *name, bool *obj,
if (!qobj) { if (!qobj) {
return; return;
} }
qbool = qobject_to_qbool(qobj); qbool = qobject_to(QBool, qobj);
if (!qbool) { if (!qbool) {
error_setg(errp, QERR_INVALID_PARAMETER_TYPE, error_setg(errp, QERR_INVALID_PARAMETER_TYPE,
full_name(qiv, name), "boolean"); full_name(qiv, name), "boolean");
@ -422,7 +422,7 @@ static void qobject_input_type_str(Visitor *v, const char *name, char **obj,
if (!qobj) { if (!qobj) {
return; return;
} }
qstr = qobject_to_qstring(qobj); qstr = qobject_to(QString, qobj);
if (!qstr) { if (!qstr) {
error_setg(errp, QERR_INVALID_PARAMETER_TYPE, error_setg(errp, QERR_INVALID_PARAMETER_TYPE,
full_name(qiv, name), "string"); full_name(qiv, name), "string");
@ -442,7 +442,7 @@ static void qobject_input_type_number(Visitor *v, const char *name, double *obj,
if (!qobj) { if (!qobj) {
return; return;
} }
qnum = qobject_to_qnum(qobj); qnum = qobject_to(QNum, qobj);
if (!qnum) { if (!qnum) {
error_setg(errp, QERR_INVALID_PARAMETER_TYPE, error_setg(errp, QERR_INVALID_PARAMETER_TYPE,
full_name(qiv, name), "number"); full_name(qiv, name), "number");

View file

@ -95,11 +95,11 @@ static void qobject_output_add_obj(QObjectOutputVisitor *qov, const char *name,
switch (qobject_type(cur)) { switch (qobject_type(cur)) {
case QTYPE_QDICT: case QTYPE_QDICT:
assert(name); assert(name);
qdict_put_obj(qobject_to_qdict(cur), name, value); qdict_put_obj(qobject_to(QDict, cur), name, value);
break; break;
case QTYPE_QLIST: case QTYPE_QLIST:
assert(!name); assert(!name);
qlist_append_obj(qobject_to_qlist(cur), value); qlist_append_obj(qobject_to(QList, cur), value);
break; break;
default: default:
g_assert_not_reached(); g_assert_not_reached();

View file

@ -55,7 +55,7 @@ QBool *qobject_to_qbool(const QObject *obj)
*/ */
bool qbool_is_equal(const QObject *x, const QObject *y) 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) void qbool_destroy_obj(QObject *obj)
{ {
assert(obj != NULL); assert(obj != NULL);
g_free(qobject_to_qbool(obj)); g_free(qobject_to(QBool, obj));
} }

View file

@ -206,7 +206,7 @@ size_t qdict_size(const QDict *qdict)
*/ */
double qdict_get_double(const QDict *qdict, const char *key) double qdict_get_double(const QDict *qdict, const char *key)
{ {
return qnum_get_double(qobject_to_qnum(qdict_get(qdict, key))); return qnum_get_double(qobject_to(QNum, qdict_get(qdict, key)));
} }
/** /**
@ -219,7 +219,7 @@ double qdict_get_double(const QDict *qdict, const char *key)
*/ */
int64_t qdict_get_int(const QDict *qdict, const char *key) int64_t qdict_get_int(const QDict *qdict, const char *key)
{ {
return qnum_get_int(qobject_to_qnum(qdict_get(qdict, key))); return qnum_get_int(qobject_to(QNum, qdict_get(qdict, key)));
} }
/** /**
@ -232,7 +232,7 @@ int64_t qdict_get_int(const QDict *qdict, const char *key)
*/ */
bool qdict_get_bool(const QDict *qdict, const char *key) bool qdict_get_bool(const QDict *qdict, const char *key)
{ {
return qbool_get_bool(qobject_to_qbool(qdict_get(qdict, key))); return qbool_get_bool(qobject_to(QBool, qdict_get(qdict, key)));
} }
/** /**
@ -240,7 +240,7 @@ bool qdict_get_bool(const QDict *qdict, const char *key)
*/ */
QList *qdict_get_qlist(const QDict *qdict, const char *key) QList *qdict_get_qlist(const QDict *qdict, const char *key)
{ {
return qobject_to_qlist(qdict_get(qdict, key)); return qobject_to(QList, qdict_get(qdict, key));
} }
/** /**
@ -248,7 +248,7 @@ QList *qdict_get_qlist(const QDict *qdict, const char *key)
*/ */
QDict *qdict_get_qdict(const QDict *qdict, const char *key) QDict *qdict_get_qdict(const QDict *qdict, const char *key)
{ {
return qobject_to_qdict(qdict_get(qdict, key)); return qobject_to(QDict, qdict_get(qdict, key));
} }
/** /**
@ -262,7 +262,7 @@ QDict *qdict_get_qdict(const QDict *qdict, const char *key)
*/ */
const char *qdict_get_str(const QDict *qdict, const char *key) const char *qdict_get_str(const QDict *qdict, const char *key)
{ {
return qstring_get_str(qobject_to_qstring(qdict_get(qdict, key))); return qstring_get_str(qobject_to(QString, qdict_get(qdict, key)));
} }
/** /**
@ -275,7 +275,7 @@ const char *qdict_get_str(const QDict *qdict, const char *key)
int64_t qdict_get_try_int(const QDict *qdict, const char *key, int64_t qdict_get_try_int(const QDict *qdict, const char *key,
int64_t def_value) int64_t def_value)
{ {
QNum *qnum = qobject_to_qnum(qdict_get(qdict, key)); QNum *qnum = qobject_to(QNum, qdict_get(qdict, key));
int64_t val; int64_t val;
if (!qnum || !qnum_get_try_int(qnum, &val)) { if (!qnum || !qnum_get_try_int(qnum, &val)) {
@ -294,7 +294,7 @@ int64_t qdict_get_try_int(const QDict *qdict, const char *key,
*/ */
bool qdict_get_try_bool(const QDict *qdict, const char *key, int def_value) bool qdict_get_try_bool(const QDict *qdict, const char *key, int def_value)
{ {
QBool *qbool = qobject_to_qbool(qdict_get(qdict, key)); QBool *qbool = qobject_to(QBool, qdict_get(qdict, key));
return qbool ? qbool_get_bool(qbool) : def_value; return qbool ? qbool_get_bool(qbool) : def_value;
} }
@ -309,7 +309,7 @@ bool qdict_get_try_bool(const QDict *qdict, const char *key, int def_value)
*/ */
const char *qdict_get_try_str(const QDict *qdict, const char *key) const char *qdict_get_try_str(const QDict *qdict, const char *key)
{ {
QString *qstr = qobject_to_qstring(qdict_get(qdict, key)); QString *qstr = qobject_to(QString, qdict_get(qdict, key));
return qstr ? qstring_get_str(qstr) : NULL; return qstr ? qstring_get_str(qstr) : NULL;
} }
@ -432,8 +432,8 @@ void qdict_del(QDict *qdict, const char *key)
*/ */
bool qdict_is_equal(const QObject *x, const QObject *y) bool qdict_is_equal(const QObject *x, const QObject *y)
{ {
const QDict *dict_x = qobject_to_qdict(x); const QDict *dict_x = qobject_to(QDict, x);
const QDict *dict_y = qobject_to_qdict(y); const QDict *dict_y = qobject_to(QDict, y);
const QDictEntry *e; const QDictEntry *e;
if (qdict_size(dict_x) != qdict_size(dict_y)) { if (qdict_size(dict_x) != qdict_size(dict_y)) {
@ -461,7 +461,7 @@ void qdict_destroy_obj(QObject *obj)
QDict *qdict; QDict *qdict;
assert(obj != NULL); assert(obj != NULL);
qdict = qobject_to_qdict(obj); qdict = qobject_to(QDict, obj);
for (i = 0; i < QDICT_BUCKET_MAX; i++) { for (i = 0; i < QDICT_BUCKET_MAX; i++) {
QDictEntry *entry = QLIST_FIRST(&qdict->table[i]); QDictEntry *entry = QLIST_FIRST(&qdict->table[i]);
@ -499,9 +499,9 @@ static void qdict_flatten_qlist(QList *qlist, QDict *target, const char *prefix)
new_key = g_strdup_printf("%s.%i", prefix, i); new_key = g_strdup_printf("%s.%i", prefix, i);
if (qobject_type(value) == QTYPE_QDICT) { if (qobject_type(value) == QTYPE_QDICT) {
qdict_flatten_qdict(qobject_to_qdict(value), target, new_key); qdict_flatten_qdict(qobject_to(QDict, value), target, new_key);
} else if (qobject_type(value) == QTYPE_QLIST) { } else if (qobject_type(value) == QTYPE_QLIST) {
qdict_flatten_qlist(qobject_to_qlist(value), target, new_key); qdict_flatten_qlist(qobject_to(QList, value), target, new_key);
} else { } else {
/* All other types are moved to the target unchanged. */ /* All other types are moved to the target unchanged. */
qobject_incref(value); qobject_incref(value);
@ -535,11 +535,11 @@ static void qdict_flatten_qdict(QDict *qdict, QDict *target, const char *prefix)
if (qobject_type(value) == QTYPE_QDICT) { if (qobject_type(value) == QTYPE_QDICT) {
/* Entries of QDicts are processed recursively, the QDict object /* Entries of QDicts are processed recursively, the QDict object
* itself disappears. */ * itself disappears. */
qdict_flatten_qdict(qobject_to_qdict(value), target, qdict_flatten_qdict(qobject_to(QDict, value), target,
new_key ? new_key : entry->key); new_key ? new_key : entry->key);
delete = true; delete = true;
} else if (qobject_type(value) == QTYPE_QLIST) { } else if (qobject_type(value) == QTYPE_QLIST) {
qdict_flatten_qlist(qobject_to_qlist(value), target, qdict_flatten_qlist(qobject_to(QList, value), target,
new_key ? new_key : entry->key); new_key ? new_key : entry->key);
delete = true; delete = true;
} else if (prefix) { } else if (prefix) {
@ -900,7 +900,7 @@ QObject *qdict_crumple(const QDict *src, Error **errp)
qdict_put_obj(two_level, prefix, child); qdict_put_obj(two_level, prefix, child);
} }
qobject_incref(ent->value); qobject_incref(ent->value);
qdict_put_obj(qobject_to_qdict(child), suffix, ent->value); qdict_put_obj(qobject_to(QDict, child), suffix, ent->value);
} else { } else {
if (child) { if (child) {
error_setg(errp, "Key %s prefix is already set as a dict", error_setg(errp, "Key %s prefix is already set as a dict",
@ -922,7 +922,7 @@ QObject *qdict_crumple(const QDict *src, Error **errp)
ent = qdict_next(two_level, ent)) { ent = qdict_next(two_level, ent)) {
if (qobject_type(ent->value) == QTYPE_QDICT) { if (qobject_type(ent->value) == QTYPE_QDICT) {
child = qdict_crumple(qobject_to_qdict(ent->value), errp); child = qdict_crumple(qobject_to(QDict, ent->value), errp);
if (!child) { if (!child) {
goto error; goto error;
} }
@ -957,7 +957,7 @@ QObject *qdict_crumple(const QDict *src, Error **errp)
} }
qobject_incref(child); qobject_incref(child);
qlist_append_obj(qobject_to_qlist(dst), child); qlist_append_obj(qobject_to(QList, dst), child);
} }
QDECREF(multi_level); QDECREF(multi_level);
multi_level = NULL; multi_level = NULL;

View file

@ -176,8 +176,8 @@ QList *qobject_to_qlist(const QObject *obj)
*/ */
bool qlist_is_equal(const QObject *x, const QObject *y) bool qlist_is_equal(const QObject *x, const QObject *y)
{ {
const QList *list_x = qobject_to_qlist(x); const QList *list_x = qobject_to(QList, x);
const QList *list_y = qobject_to_qlist(y); const QList *list_y = qobject_to(QList, y);
const QListEntry *entry_x, *entry_y; const QListEntry *entry_x, *entry_y;
entry_x = qlist_first(list_x); entry_x = qlist_first(list_x);
@ -206,7 +206,7 @@ void qlist_destroy_obj(QObject *obj)
QListEntry *entry, *next_entry; QListEntry *entry, *next_entry;
assert(obj != NULL); assert(obj != NULL);
qlist = qobject_to_qlist(obj); qlist = qobject_to(QList, obj);
QTAILQ_FOREACH_SAFE(entry, &qlist->head, next, next_entry) { QTAILQ_FOREACH_SAFE(entry, &qlist->head, next, next_entry) {
QTAILQ_REMOVE(&qlist->head, entry, next); QTAILQ_REMOVE(&qlist->head, entry, next);

View file

@ -70,16 +70,16 @@ bool qlit_equal_qobject(const QLitObject *lhs, const QObject *rhs)
switch (lhs->type) { switch (lhs->type) {
case QTYPE_QBOOL: case QTYPE_QBOOL:
return lhs->value.qbool == qbool_get_bool(qobject_to_qbool(rhs)); return lhs->value.qbool == qbool_get_bool(qobject_to(QBool, rhs));
case QTYPE_QNUM: case QTYPE_QNUM:
return lhs->value.qnum == qnum_get_int(qobject_to_qnum(rhs)); return lhs->value.qnum == qnum_get_int(qobject_to(QNum, rhs));
case QTYPE_QSTRING: case QTYPE_QSTRING:
return (strcmp(lhs->value.qstr, return (strcmp(lhs->value.qstr,
qstring_get_str(qobject_to_qstring(rhs))) == 0); qstring_get_str(qobject_to(QString, rhs))) == 0);
case QTYPE_QDICT: case QTYPE_QDICT:
return qlit_equal_qdict(lhs, qobject_to_qdict(rhs)); return qlit_equal_qdict(lhs, qobject_to(QDict, rhs));
case QTYPE_QLIST: case QTYPE_QLIST:
return qlit_equal_qlist(lhs, qobject_to_qlist(rhs)); return qlit_equal_qlist(lhs, qobject_to(QList, rhs));
case QTYPE_QNULL: case QTYPE_QNULL:
return true; return true;
default: default:

View file

@ -221,8 +221,8 @@ QNum *qobject_to_qnum(const QObject *obj)
*/ */
bool qnum_is_equal(const QObject *x, const QObject *y) bool qnum_is_equal(const QObject *x, const QObject *y)
{ {
QNum *num_x = qobject_to_qnum(x); QNum *num_x = qobject_to(QNum, x);
QNum *num_y = qobject_to_qnum(y); QNum *num_y = qobject_to(QNum, y);
switch (num_x->kind) { switch (num_x->kind) {
case QNUM_I64: case QNUM_I64:
@ -271,5 +271,5 @@ bool qnum_is_equal(const QObject *x, const QObject *y)
void qnum_destroy_obj(QObject *obj) void qnum_destroy_obj(QObject *obj)
{ {
assert(obj != NULL); assert(obj != NULL);
g_free(qobject_to_qnum(obj)); g_free(qobject_to(QNum, obj));
} }

View file

@ -131,8 +131,8 @@ const char *qstring_get_str(const QString *qstring)
*/ */
bool qstring_is_equal(const QObject *x, const QObject *y) bool qstring_is_equal(const QObject *x, const QObject *y)
{ {
return !strcmp(qobject_to_qstring(x)->string, return !strcmp(qobject_to(QString, x)->string,
qobject_to_qstring(y)->string); qobject_to(QString, y)->string);
} }
/** /**
@ -144,7 +144,7 @@ void qstring_destroy_obj(QObject *obj)
QString *qs; QString *qs;
assert(obj != NULL); assert(obj != NULL);
qs = qobject_to_qstring(obj); qs = qobject_to(QString, obj);
g_free(qs->string); g_free(qs->string);
g_free(qs); g_free(qs);
} }

View file

@ -1014,7 +1014,7 @@ char *object_property_get_str(struct uc_struct *uc, Object *obj, const char *nam
if (!ret) { if (!ret) {
return NULL; return NULL;
} }
qstring = qobject_to_qstring(ret); qstring = qobject_to(QString, ret);
if (!qstring) { if (!qstring) {
error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name, "string"); error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name, "string");
retval = NULL; retval = NULL;
@ -1075,7 +1075,7 @@ bool object_property_get_bool(struct uc_struct *uc, Object *obj, const char *nam
if (!ret) { if (!ret) {
return false; return false;
} }
qbool = qobject_to_qbool(ret); qbool = qobject_to(QBool, ret);
if (!qbool) { if (!qbool) {
error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name, "boolean"); error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name, "boolean");
retval = false; retval = false;
@ -1107,7 +1107,7 @@ int64_t object_property_get_int(struct uc_struct *uc, Object *obj, const char *n
return -1; return -1;
} }
qnum = qobject_to_qnum(ret); qnum = qobject_to(QNum, ret);
if (!qnum || !qnum_get_try_int(qnum, &retval)) { if (!qnum || !qnum_get_try_int(qnum, &retval)) {
error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name, "int"); error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name, "int");
retval = -1; retval = -1;
@ -1136,7 +1136,7 @@ uint64_t object_property_get_uint(struct uc_struct *uc, Object *obj,
if (!ret) { if (!ret) {
return 0; return 0;
} }
qnum = qobject_to_qnum(ret); qnum = qobject_to(QNum, ret);
if (!qnum || !qnum_get_try_uint(qnum, &retval)) { if (!qnum || !qnum_get_try_uint(qnum, &retval)) {
error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name, "uint"); error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name, "uint");
retval = 0; retval = 0;