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. > > 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. > > 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. > > As an example, a flat dict containing > > { > 'foo.0.bar': 'one', > 'foo.0.wizz': '1', > 'foo.1.bar': 'two', > 'foo.1.wizz': '2' > } > > will get turned into a dict with one element 'foo' whose > value is a list. The list elements will each in turn be > dicts. > > { > 'foo': [ > { 'bar': 'one', 'wizz': '1' }, > { 'bar': 'two', 'wizz': '2' } > ], > } > > If the key is intended to contain a literal '.', then it must > be escaped as '..'. ie a flat dict > > { > 'foo..bar': 'wizz', > 'bar.foo..bar': 'eek', > 'bar.hello': 'world' > } > > Will end up as > > { > 'foo.bar': 'wizz', > 'bar': { > 'foo.bar': 'eek', > 'hello': 'world' > } > } > > 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. > > Reviewed-by: Marc-André Lureau <marcandre.lur...@redhat.com> > Signed-off-by: Daniel P. Berrange <berra...@redhat.com>
> + /* 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 = QOBJECT(qlist_new()); > + > + for (i = 0; i < qdict_size(multi_level); i++) { > + char *key = g_strdup_printf("%zu", i); > + > + child = 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 = NULL; > + } else { > + dst = QOBJECT(multi_level); > + } The rest looks good, so with these fixed you can add: Reviewed-by: Kevin Wolf <kw...@redhat.com>