qapi: Make more of qobject_to()

This patch reworks some places which use either qobject_type() checks
plus qobject_to(), where the latter alone is sufficient, or NULL checks
plus qobject_type() checks where we can simply do a qobject_to() != NULL
check.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Alberto Garcia <berto@igalia.com>
Message-Id: <20180224154033.29559-6-mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
[eblake: rebase to qobject_to() parameter ordering]
Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
Max Reitz 2018-03-10 16:14:36 -06:00 committed by Eric Blake
parent cb51b976ba
commit 532fb53284
3 changed files with 20 additions and 17 deletions

View file

@ -276,7 +276,8 @@ static void parser_context_free(JSONParserContext *ctxt)
*/
static int parse_pair(JSONParserContext *ctxt, QDict *dict, va_list *ap)
{
QObject *key = NULL, *value;
QObject *value;
QString *key = NULL;
JSONToken *peek, *token;
peek = parser_context_peek_token(ctxt);
@ -285,8 +286,8 @@ static int parse_pair(JSONParserContext *ctxt, QDict *dict, va_list *ap)
goto out;
}
key = parse_value(ctxt, ap);
if (!key || qobject_type(key) != QTYPE_QSTRING) {
key = qobject_to(QString, parse_value(ctxt, ap));
if (!key) {
parse_error(ctxt, peek, "key is not a string in object");
goto out;
}
@ -308,14 +309,14 @@ 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(key), value);
qobject_decref(key);
QDECREF(key);
return 0;
out:
qobject_decref(key);
QDECREF(key);
return -1;
}