aboutsummaryrefslogtreecommitdiff
path: root/qobject
diff options
context:
space:
mode:
authorMax Reitz <mreitz@redhat.com>2018-02-24 16:40:29 +0100
committerEric Blake <eblake@redhat.com>2018-03-19 14:58:36 -0500
commit7dc847ebba953db90853d15f140c20eef74d4fb2 (patch)
treef17aad0438ed253a90674b74732917d449147f07 /qobject
parent1a56b1e2ab5e9d6d89386ca953b4afb419e15abe (diff)
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>
Diffstat (limited to 'qobject')
-rw-r--r--qobject/json-parser.c2
-rw-r--r--qobject/qbool.c4
-rw-r--r--qobject/qdict.c38
-rw-r--r--qobject/qjson.c10
-rw-r--r--qobject/qlist.c6
-rw-r--r--qobject/qlit.c10
-rw-r--r--qobject/qnum.c6
-rw-r--r--qobject/qstring.c6
8 files changed, 41 insertions, 41 deletions
diff --git a/qobject/json-parser.c b/qobject/json-parser.c
index b724562415..055c7f0272 100644
--- a/qobject/json-parser.c
+++ b/qobject/json-parser.c
@@ -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);
diff --git a/qobject/qbool.c b/qobject/qbool.c
index e5a7a53879..5be6277cca 100644
--- a/qobject/qbool.c
+++ b/qobject/qbool.c
@@ -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));
}
diff --git a/qobject/qdict.c b/qobject/qdict.c
index 229b8c840b..1e588123d0 100644
--- a/qobject/qdict.c
+++ b/qobject/qdict.c
@@ -206,7 +206,7 @@ size_t qdict_size(const QDict *qdict)
*/
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)
{
- 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)
{
- 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)
{
- 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)
{
- 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)
{
- 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 def_value)
{
- QNum *qnum = qobject_to_qnum(qdict_get(qdict, key));
+ QNum *qnum = qobject_to(QNum, qdict_get(qdict, key));
int64_t 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, bool 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;
}
@@ -309,7 +309,7 @@ bool qdict_get_try_bool(const QDict *qdict, const char *key, bool def_value)
*/
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;
}
@@ -432,8 +432,8 @@ void qdict_del(QDict *qdict, const char *key)
*/
bool qdict_is_equal(const QObject *x, const QObject *y)
{
- const QDict *dict_x = qobject_to_qdict(x);
- const QDict *dict_y = qobject_to_qdict(y);
+ const QDict *dict_x = qobject_to(QDict, x);
+ const QDict *dict_y = qobject_to(QDict, y);
const QDictEntry *e;
if (qdict_size(dict_x) != qdict_size(dict_y)) {
@@ -461,7 +461,7 @@ void qdict_destroy_obj(QObject *obj)
QDict *qdict;
assert(obj != NULL);
- qdict = qobject_to_qdict(obj);
+ qdict = qobject_to(QDict, obj);
for (i = 0; i < QDICT_BUCKET_MAX; i++) {
QDictEntry *entry = QLIST_FIRST(&qdict->table[i]);
@@ -532,9 +532,9 @@ static void qdict_flatten_qlist(QList *qlist, QDict *target, const char *prefix)
new_key = g_strdup_printf("%s.%i", prefix, i);
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) {
- qdict_flatten_qlist(qobject_to_qlist(value), target, new_key);
+ qdict_flatten_qlist(qobject_to(QList, value), target, new_key);
} else {
/* All other types are moved to the target unchanged. */
qobject_incref(value);
@@ -568,11 +568,11 @@ static void qdict_flatten_qdict(QDict *qdict, QDict *target, const char *prefix)
if (qobject_type(value) == QTYPE_QDICT) {
/* Entries of QDicts are processed recursively, the QDict object
* itself disappears. */
- qdict_flatten_qdict(qobject_to_qdict(value), target,
+ qdict_flatten_qdict(qobject_to(QDict, value), target,
new_key ? new_key : entry->key);
delete = true;
} 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);
delete = true;
} else if (prefix) {
@@ -904,7 +904,7 @@ QObject *qdict_crumple(const QDict *src, Error **errp)
qdict_put_obj(two_level, prefix, child);
}
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 {
if (child) {
error_setg(errp, "Key %s prefix is already set as a dict",
@@ -926,7 +926,7 @@ QObject *qdict_crumple(const QDict *src, Error **errp)
ent = qdict_next(two_level, ent)) {
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) {
goto error;
}
@@ -961,7 +961,7 @@ QObject *qdict_crumple(const QDict *src, Error **errp)
}
qobject_incref(child);
- qlist_append_obj(qobject_to_qlist(dst), child);
+ qlist_append_obj(qobject_to(QList, dst), child);
}
QDECREF(multi_level);
multi_level = NULL;
diff --git a/qobject/qjson.c b/qobject/qjson.c
index e1ce75651c..655d38adf1 100644
--- a/qobject/qjson.c
+++ b/qobject/qjson.c
@@ -137,14 +137,14 @@ static void to_json(const QObject *obj, QString *str, int pretty, int indent)
qstring_append(str, "null");
break;
case QTYPE_QNUM: {
- QNum *val = qobject_to_qnum(obj);
+ QNum *val = qobject_to(QNum, obj);
char *buffer = qnum_to_string(val);
qstring_append(str, buffer);
g_free(buffer);
break;
}
case QTYPE_QSTRING: {
- QString *val = qobject_to_qstring(obj);
+ QString *val = qobject_to(QString, obj);
const char *ptr;
int cp;
char buf[16];
@@ -201,7 +201,7 @@ static void to_json(const QObject *obj, QString *str, int pretty, int indent)
}
case QTYPE_QDICT: {
ToJsonIterState s;
- QDict *val = qobject_to_qdict(obj);
+ QDict *val = qobject_to(QDict, obj);
s.count = 0;
s.str = str;
@@ -220,7 +220,7 @@ static void to_json(const QObject *obj, QString *str, int pretty, int indent)
}
case QTYPE_QLIST: {
ToJsonIterState s;
- QList *val = qobject_to_qlist(obj);
+ QList *val = qobject_to(QList, obj);
s.count = 0;
s.str = str;
@@ -238,7 +238,7 @@ static void to_json(const QObject *obj, QString *str, int pretty, int indent)
break;
}
case QTYPE_QBOOL: {
- QBool *val = qobject_to_qbool(obj);
+ QBool *val = qobject_to(QBool, obj);
if (qbool_get_bool(val)) {
qstring_append(str, "true");
diff --git a/qobject/qlist.c b/qobject/qlist.c
index 613a95c12b..77f19ffda7 100644
--- a/qobject/qlist.c
+++ b/qobject/qlist.c
@@ -173,8 +173,8 @@ QList *qobject_to_qlist(const QObject *obj)
*/
bool qlist_is_equal(const QObject *x, const QObject *y)
{
- const QList *list_x = qobject_to_qlist(x);
- const QList *list_y = qobject_to_qlist(y);
+ const QList *list_x = qobject_to(QList, x);
+ const QList *list_y = qobject_to(QList, y);
const QListEntry *entry_x, *entry_y;
entry_x = qlist_first(list_x);
@@ -203,7 +203,7 @@ void qlist_destroy_obj(QObject *obj)
QListEntry *entry, *next_entry;
assert(obj != NULL);
- qlist = qobject_to_qlist(obj);
+ qlist = qobject_to(QList, obj);
QTAILQ_FOREACH_SAFE(entry, &qlist->head, next, next_entry) {
QTAILQ_REMOVE(&qlist->head, entry, next);
diff --git a/qobject/qlit.c b/qobject/qlit.c
index d0e1b72fd0..be8332136c 100644
--- a/qobject/qlit.c
+++ b/qobject/qlit.c
@@ -69,16 +69,16 @@ bool qlit_equal_qobject(const QLitObject *lhs, const QObject *rhs)
switch (lhs->type) {
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:
- 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:
return (strcmp(lhs->value.qstr,
- qstring_get_str(qobject_to_qstring(rhs))) == 0);
+ qstring_get_str(qobject_to(QString, rhs))) == 0);
case QTYPE_QDICT:
- return qlit_equal_qdict(lhs, qobject_to_qdict(rhs));
+ return qlit_equal_qdict(lhs, qobject_to(QDict, rhs));
case QTYPE_QLIST:
- return qlit_equal_qlist(lhs, qobject_to_qlist(rhs));
+ return qlit_equal_qlist(lhs, qobject_to(QList, rhs));
case QTYPE_QNULL:
return true;
default:
diff --git a/qobject/qnum.c b/qobject/qnum.c
index 60c395c1bc..ea091cfaa4 100644
--- a/qobject/qnum.c
+++ b/qobject/qnum.c
@@ -221,8 +221,8 @@ QNum *qobject_to_qnum(const QObject *obj)
*/
bool qnum_is_equal(const QObject *x, const QObject *y)
{
- QNum *num_x = qobject_to_qnum(x);
- QNum *num_y = qobject_to_qnum(y);
+ QNum *num_x = qobject_to(QNum, x);
+ QNum *num_y = qobject_to(QNum, y);
switch (num_x->kind) {
case QNUM_I64:
@@ -271,5 +271,5 @@ bool qnum_is_equal(const QObject *x, const QObject *y)
void qnum_destroy_obj(QObject *obj)
{
assert(obj != NULL);
- g_free(qobject_to_qnum(obj));
+ g_free(qobject_to(QNum, obj));
}
diff --git a/qobject/qstring.c b/qobject/qstring.c
index 05b4bbc2d6..2b2153206d 100644
--- a/qobject/qstring.c
+++ b/qobject/qstring.c
@@ -132,8 +132,8 @@ const char *qstring_get_str(const QString *qstring)
*/
bool qstring_is_equal(const QObject *x, const QObject *y)
{
- return !strcmp(qobject_to_qstring(x)->string,
- qobject_to_qstring(y)->string);
+ return !strcmp(qobject_to(QString, x)->string,
+ qobject_to(QString, y)->string);
}
/**
@@ -145,7 +145,7 @@ void qstring_destroy_obj(QObject *obj)
QString *qs;
assert(obj != NULL);
- qs = qobject_to_qstring(obj);
+ qs = qobject_to(QString, obj);
g_free(qs->string);
g_free(qs);
}