qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: "Daniel P. Berrange" <berrange@redhat.com>
Cc: qemu-devel@nongnu.org, "Markus Armbruster" <armbru@redhat.com>,
	"Max Reitz" <mreitz@redhat.com>,
	"Marc-André Lureau" <marcandre.lureau@gmail.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Andreas Färber" <afaerber@suse.de>
Subject: Re: [Qemu-devel] [PATCH v12 1/6] qdict: implement a qdict_crumple method for un-flattening a dict
Date: Thu, 15 Sep 2016 15:53:10 +0200	[thread overview]
Message-ID: <20160915135310.GJ4726@noname.redhat.com> (raw)
In-Reply-To: <1473943523-20270-2-git-send-email-berrange@redhat.com>

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.lureau@redhat.com>
> Signed-off-by: Daniel P. Berrange <berrange@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 <kwolf@redhat.com>

  reply	other threads:[~2016-09-15 13:53 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-15 12:45 [Qemu-devel] [PATCH v12 0/6] QAPI/QOM work for non-scalar object properties Daniel P. Berrange
2016-09-15 12:45 ` [Qemu-devel] [PATCH v12 1/6] qdict: implement a qdict_crumple method for un-flattening a dict Daniel P. Berrange
2016-09-15 13:53   ` Kevin Wolf [this message]
2016-09-15 12:45 ` [Qemu-devel] [PATCH v12 2/6] option: make parse_option_bool/number non-static Daniel P. Berrange
2016-09-15 12:45 ` [Qemu-devel] [PATCH v12 3/6] qapi: rename QmpInputVisitor to QObjectInputVisitor Daniel P. Berrange
2016-09-15 13:56   ` Kevin Wolf
2016-09-15 12:45 ` [Qemu-devel] [PATCH v12 4/6] qapi: rename QmpOutputVisitor to QObjectOutputVisitor Daniel P. Berrange
2016-09-15 13:56   ` Kevin Wolf
2016-09-15 12:45 ` [Qemu-devel] [PATCH v12 5/6] qapi: add a QObjectInputVisitor that does string conversion Daniel P. Berrange
2016-09-15 14:08   ` Kevin Wolf
2016-09-15 12:45 ` [Qemu-devel] [PATCH v12 6/6] qom: support arbitrary non-scalar properties with -object Daniel P. Berrange

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160915135310.GJ4726@noname.redhat.com \
    --to=kwolf@redhat.com \
    --cc=afaerber@suse.de \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=marcandre.lureau@gmail.com \
    --cc=mreitz@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).