Received: from eggs.gnu.org ([2001:4830:134:3::10]:38852) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bkX6M-0004rY-DJ for qemu-devel@nongnu.org; Thu, 15 Sep 2016 09:53:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bkX6I-0000Gj-Oa for qemu-devel@nongnu.org; Thu, 15 Sep 2016 09:53:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53736) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bkX6I-0000G9-F6 for qemu-devel@nongnu.org; Thu, 15 Sep 2016 09:53:14 -0400 Date: Thu, 15 Sep 2016 15:53:10 +0200 From: Kevin Wolf Message-ID: <20160915135310.GJ4726@noname.redhat.com> References: <1473943523-20270-1-git-send-email-berrange@redhat.com> <1473943523-20270-2-git-send-email-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1473943523-20270-2-git-send-email-berrange@redhat.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v12 1/6] qdict: implement a qdict_crumple method for un-flattening a dict List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Daniel P. Berrange" Cc: qemu-devel@nongnu.org, Markus Armbruster , Max Reitz , =?iso-8859-1?Q?Marc-Andr=E9?= Lureau , Paolo Bonzini , Andreas =?iso-8859-1?Q?F=E4rber?= Am 15.09.2016 um 14:45 hat Daniel P. Berrange geschrieben: > The qdict_flatten() method will take a dict whose elements are > further nested dicts/lists and flatten them by concatenating > keys. >=20 > The qdict_crumple() method aims to do the reverse, taking a flat > qdict, and turning it into a set of nested dicts/lists. It will > apply nesting based on the key name, with a '.' indicating a > new level in the hierarchy. If the keys in the nested structure > are all numeric, it will create a list, otherwise it will create > a dict. >=20 > If the keys are a mixture of numeric and non-numeric, or the > numeric keys are not in strictly ascending order, an error will > be reported. >=20 > As an example, a flat dict containing >=20 > { > 'foo.0.bar': 'one', > 'foo.0.wizz': '1', > 'foo.1.bar': 'two', > 'foo.1.wizz': '2' > } >=20 > will get turned into a dict with one element 'foo' whose > value is a list. The list elements will each in turn be > dicts. >=20 > { > 'foo': [ > { 'bar': 'one', 'wizz': '1' }, > { 'bar': 'two', 'wizz': '2' } > ], > } >=20 > If the key is intended to contain a literal '.', then it must > be escaped as '..'. ie a flat dict >=20 > { > 'foo..bar': 'wizz', > 'bar.foo..bar': 'eek', > 'bar.hello': 'world' > } >=20 > Will end up as >=20 > { > 'foo.bar': 'wizz', > 'bar': { > 'foo.bar': 'eek', > 'hello': 'world' > } > } >=20 > The intent of this function is that it allows a set of QemuOpts > to be turned into a nested data structure that mirrors the nesting > used when the same object is defined over QMP. >=20 > Reviewed-by: Marc-Andr=E9 Lureau > Signed-off-by: Daniel P. Berrange > + /* NB this isn't a perfect check - eg it won't catch > + * a list containing '1', '+1', '01', '3', but that > + * does nto matter - we've still proved that the s/nto/not/ > + if (is_list) { > + dst =3D QOBJECT(qlist_new()); > + > + for (i =3D 0; i < qdict_size(multi_level); i++) { > + char *key =3D g_strdup_printf("%zu", i); > + > + child =3D qdict_get(multi_level, key); > + g_free(key); > + > + if (!child) { > + error_setg(errp, > + "Missing list index %zu", i); This fits on a single line. > + goto error; > + } > + > + qobject_incref(child); > + qlist_append_obj(qobject_to_qlist(dst), child); > + } > + QDECREF(multi_level); > + multi_level =3D NULL; > + } else { > + dst =3D QOBJECT(multi_level); > + } The rest looks good, so with these fixed you can add: Reviewed-by: Kevin Wolf