QObjectInputVisitor *qiv = to_qiv(v);
StackObject *tos = QSLIST_FIRST(&qiv->stack);
- assert(tos && tos->obj && qobject_type(tos->obj) == QTYPE_QLIST);
+ assert(tos && qobject_to(QList, tos->obj));
if (!tos->entry) {
return NULL;
QObjectInputVisitor *qiv = to_qiv(v);
StackObject *tos = QSLIST_FIRST(&qiv->stack);
- assert(tos && tos->obj && qobject_type(tos->obj) == QTYPE_QLIST);
+ assert(tos && qobject_to(QList, tos->obj));
if (tos->entry) {
error_setg(errp, "Only %u list elements expected in %s",
*/
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);
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;
}
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;
}
child = qdict_get(two_level, prefix);
if (suffix) {
- if (child) {
- if (qobject_type(child) != QTYPE_QDICT) {
+ QDict *child_dict = qobject_to(QDict, child);
+ if (!child_dict) {
+ if (child) {
error_setg(errp, "Key %s prefix is already set as a scalar",
prefix);
goto error;
}
- } else {
- child = QOBJECT(qdict_new());
- qdict_put_obj(two_level, prefix, child);
+
+ child_dict = qdict_new();
+ qdict_put_obj(two_level, prefix, QOBJECT(child_dict));
}
+
qobject_incref(ent->value);
- qdict_put_obj(qobject_to(QDict, child), suffix, ent->value);
+ qdict_put_obj(child_dict, suffix, ent->value);
} else {
if (child) {
error_setg(errp, "Key %s prefix is already set as a dict",
multi_level = qdict_new();
for (ent = qdict_first(two_level); ent != NULL;
ent = qdict_next(two_level, ent)) {
-
- if (qobject_type(ent->value) == QTYPE_QDICT) {
- child = qdict_crumple(qobject_to(QDict, ent->value), errp);
+ QDict *dict = qobject_to(QDict, ent->value);
+ if (dict) {
+ child = qdict_crumple(dict, errp);
if (!child) {
goto error;
}