summary refs log tree commit diff stats
path: root/qobject/qdict.c
diff options
context:
space:
mode:
authorMax Reitz <mreitz@redhat.com>2018-03-10 16:14:36 -0600
committerEric Blake <eblake@redhat.com>2018-03-19 14:58:36 -0500
commit532fb532847365f61a9c6e1291b6588a43bc1cc4 (patch)
tree46d7355bfca3e0ab48784eec191e2d81f383fa68 /qobject/qdict.c
parentcb51b976babf7ee16dc5eda4f2189d65b8b700a3 (diff)
downloadfocaccia-qemu-532fb532847365f61a9c6e1291b6588a43bc1cc4.tar.gz
focaccia-qemu-532fb532847365f61a9c6e1291b6588a43bc1cc4.zip
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>
Diffstat (limited to 'qobject/qdict.c')
-rw-r--r--qobject/qdict.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/qobject/qdict.c b/qobject/qdict.c
index 45c8b53361..d1997a0d8a 100644
--- a/qobject/qdict.c
+++ b/qobject/qdict.c
@@ -882,18 +882,20 @@ QObject *qdict_crumple(const QDict *src, Error **errp)
 
         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",
@@ -913,9 +915,9 @@ QObject *qdict_crumple(const QDict *src, Error **errp)
     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;
             }