thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
ae23c9
From 5d1c329444f36191b0e868f2a43178d289ba1f59 Mon Sep 17 00:00:00 2001
ae23c9
From: Markus Armbruster <armbru@redhat.com>
ae23c9
Date: Mon, 18 Jun 2018 08:43:24 +0200
ae23c9
Subject: [PATCH 026/268] block-qdict: Clean up qdict_crumple() a bit
ae23c9
ae23c9
RH-Author: Markus Armbruster <armbru@redhat.com>
ae23c9
Message-id: <20180618084330.30009-18-armbru@redhat.com>
ae23c9
Patchwork-id: 80729
ae23c9
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH 17/23] block-qdict: Clean up qdict_crumple() a bit
ae23c9
Bugzilla: 1557995
ae23c9
RH-Acked-by: Max Reitz <mreitz@redhat.com>
ae23c9
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
ae23c9
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
ae23c9
ae23c9
When you mix scalar and non-scalar keys, whether you get an "already
ae23c9
set as scalar" or an "already set as dict" error depends on qdict
ae23c9
iteration order.  Neither message makes much sense.  Replace by
ae23c9
""Cannot mix scalar and non-scalar keys".  This is similar to the
ae23c9
message we get for mixing list and non-list keys.
ae23c9
ae23c9
I find qdict_crumple()'s first loop hard to understand.  Rearrange it
ae23c9
and add a comment.
ae23c9
ae23c9
Signed-off-by: Markus Armbruster <armbru@redhat.com>
ae23c9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
ae23c9
(cherry picked from commit 3692b5d76819e573dedc9004c4b2b0e3dad83530)
ae23c9
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
ae23c9
---
ae23c9
 qobject/block-qdict.c | 32 ++++++++++++++++----------------
ae23c9
 1 file changed, 16 insertions(+), 16 deletions(-)
ae23c9
ae23c9
diff --git a/qobject/block-qdict.c b/qobject/block-qdict.c
ae23c9
index a4e1c8d..36cf58a 100644
ae23c9
--- a/qobject/block-qdict.c
ae23c9
+++ b/qobject/block-qdict.c
ae23c9
@@ -403,7 +403,7 @@ static int qdict_is_list(QDict *maybe_list, Error **errp)
ae23c9
 QObject *qdict_crumple(const QDict *src, Error **errp)
ae23c9
 {
ae23c9
     const QDictEntry *ent;
ae23c9
-    QDict *two_level, *multi_level = NULL;
ae23c9
+    QDict *two_level, *multi_level = NULL, *child_dict;
ae23c9
     QObject *dst = NULL, *child;
ae23c9
     size_t i;
ae23c9
     char *prefix = NULL;
ae23c9
@@ -422,28 +422,28 @@ QObject *qdict_crumple(const QDict *src, Error **errp)
ae23c9
         }
ae23c9
 
ae23c9
         qdict_split_flat_key(ent->key, &prefix, &suffix);
ae23c9
-
ae23c9
         child = qdict_get(two_level, prefix);
ae23c9
+        child_dict = qobject_to(QDict, child);
ae23c9
+
ae23c9
+        if (child) {
ae23c9
+            /*
ae23c9
+             * If @child_dict, then all previous keys with this prefix
ae23c9
+             * had a suffix.  If @suffix, this one has one as well,
ae23c9
+             * and we're good, else there's a clash.
ae23c9
+             */
ae23c9
+            if (!child_dict || !suffix) {
ae23c9
+                error_setg(errp, "Cannot mix scalar and non-scalar keys");
ae23c9
+                goto error;
ae23c9
+            }
ae23c9
+        }
ae23c9
+
ae23c9
         if (suffix) {
ae23c9
-            QDict *child_dict = qobject_to(QDict, child);
ae23c9
             if (!child_dict) {
ae23c9
-                if (child) {
ae23c9
-                    error_setg(errp, "Key %s prefix is already set as a scalar",
ae23c9
-                               prefix);
ae23c9
-                    goto error;
ae23c9
-                }
ae23c9
-
ae23c9
                 child_dict = qdict_new();
ae23c9
-                qdict_put_obj(two_level, prefix, QOBJECT(child_dict));
ae23c9
+                qdict_put(two_level, prefix, child_dict);
ae23c9
             }
ae23c9
-
ae23c9
             qdict_put_obj(child_dict, suffix, qobject_ref(ent->value));
ae23c9
         } else {
ae23c9
-            if (child) {
ae23c9
-                error_setg(errp, "Key %s prefix is already set as a dict",
ae23c9
-                           prefix);
ae23c9
-                goto error;
ae23c9
-            }
ae23c9
             qdict_put_obj(two_level, prefix, qobject_ref(ent->value));
ae23c9
         }
ae23c9
 
ae23c9
-- 
ae23c9
1.8.3.1
ae23c9