qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Fam Zheng <famz@redhat.com>
To: Max Reitz <mreitz@redhat.com>, qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>, Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v3 04/21] qapi: extend qdict_flatten() for QLists
Date: Thu, 12 Dec 2013 14:17:59 +0800	[thread overview]
Message-ID: <52A95517.3020303@redhat.com> (raw)
In-Reply-To: <1386785473-26157-5-git-send-email-mreitz@redhat.com>

On 2013年12月12日 02:10, Max Reitz wrote:
> Reversing qdict_array_split(), qdict_flatten() should flatten QLists as
> well by interpreting them as QDicts where every entry's key is its
> index.
>
> This allows bringing QDicts with QLists from QMP commands to the same
> form as they would be given as command-line options, thereby allowing
> them to be parsed the same way.
>
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---

The logic looks fine, just a few questions about assertions below.

>   qobject/qdict.c | 45 +++++++++++++++++++++++++++++++++++++++++----
>   1 file changed, 41 insertions(+), 4 deletions(-)
>
> diff --git a/qobject/qdict.c b/qobject/qdict.c
> index fca1902..d7ce4b3 100644
> --- a/qobject/qdict.c
> +++ b/qobject/qdict.c
> @@ -477,7 +477,40 @@ static void qdict_destroy_obj(QObject *obj)
>       g_free(qdict);
>   }
>
> -static void qdict_do_flatten(QDict *qdict, QDict *target, const char *prefix)
> +static void qdict_flatten_qdict(QDict *qdict, QDict *target,
> +                                const char *prefix);
> +
> +static void qdict_flatten_qlist(QList *qlist, QDict *target, const char *prefix)
> +{
> +    QObject *value;
> +    const QListEntry *entry;
> +    char *new_key;
> +    int i;
> +
> +    /* This function is never called with prefix == NULL, i.e., it is always
> +     * called from within qdict_flatten_q(list|dict)(). Therefore, it does not
> +     * need to remove list entries during the iteration (the whole list will be
> +     * deleted eventually anyway from qdict_flatten_qdict()). Also, prefix can
> +     * never be NULL. */

Then maybe assert this?

> +
> +    entry = qlist_first(qlist);
> +
> +    for (i = 0; entry; entry = qlist_next(entry), i++) {
> +        value = qlist_entry_obj(entry);
> +
> +        qobject_incref(value);
> +        new_key = g_strdup_printf("%s.%i", prefix, i);
> +        qdict_put_obj(target, new_key, value);
> +
> +        if (qobject_type(value) == QTYPE_QDICT) {
> +            qdict_flatten_qdict(qobject_to_qdict(value), target, new_key);
> +        } else {

And maybe assert the type are not something other than dict and list?


> +            qdict_flatten_qlist(qobject_to_qlist(value), target, new_key);
> +        }
> +    }
> +}
> +
> +static void qdict_flatten_qdict(QDict *qdict, QDict *target, const char *prefix)
>   {
>       QObject *value;
>       const QDictEntry *entry, *next;
> @@ -500,8 +533,12 @@ static void qdict_do_flatten(QDict *qdict, QDict *target, const char *prefix)
>           if (qobject_type(value) == QTYPE_QDICT) {
>               /* Entries of QDicts are processed recursively, the QDict object
>                * itself disappears. */
> -            qdict_do_flatten(qobject_to_qdict(value), target,
> -                             new_key ? new_key : entry->key);
> +            qdict_flatten_qdict(qobject_to_qdict(value), target,
> +                                new_key ? new_key : entry->key);
> +            delete = true;
> +        } else if (qobject_type(value) == QTYPE_QLIST) {
> +            qdict_flatten_qlist(qobject_to_qlist(value), target,
> +                                new_key ? new_key : entry->key);
>               delete = true;
>           } else if (prefix) {
>               /* All other objects are moved to the target unchanged. */
> @@ -531,7 +568,7 @@ static void qdict_do_flatten(QDict *qdict, QDict *target, const char *prefix)
>    */
>   void qdict_flatten(QDict *qdict)
>   {
> -    qdict_do_flatten(qdict, qdict, NULL);
> +    qdict_flatten_qdict(qdict, qdict, NULL);

If there was an assumption that the top level is a qdict, also assert 
that here?

Thanks,

Fam

  parent reply	other threads:[~2013-12-12  6:18 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-11 18:10 [Qemu-devel] [PATCH v3 00/21] blkdebug/blkverify: Allow QMP configuration Max Reitz
2013-12-11 18:10 ` [Qemu-devel] [PATCH v3 01/21] blkdebug: Use errp for read_config() Max Reitz
2013-12-11 18:10 ` [Qemu-devel] [PATCH v3 02/21] blkdebug: Don't require sophisticated filename Max Reitz
2013-12-11 18:10 ` [Qemu-devel] [PATCH v3 03/21] qdict: Add qdict_array_split() Max Reitz
2013-12-11 18:10 ` [Qemu-devel] [PATCH v3 04/21] qapi: extend qdict_flatten() for QLists Max Reitz
2013-12-11 18:23   ` [Qemu-devel] [PATCH v4 " Max Reitz
2013-12-12  6:17   ` Fam Zheng [this message]
2013-12-13 15:52     ` [Qemu-devel] [PATCH v3 " Max Reitz
2013-12-12  6:21   ` Fam Zheng
2013-12-13 15:53     ` Max Reitz
2013-12-11 18:10 ` [Qemu-devel] [PATCH v3 05/21] qemu-option: Add qemu_config_parse_qdict() Max Reitz
2013-12-11 18:10 ` [Qemu-devel] [PATCH v3 06/21] blkdebug: Always call read_config() Max Reitz
2013-12-11 18:10 ` [Qemu-devel] [PATCH v3 07/21] blkdebug: Use command-line in read_config() Max Reitz
2013-12-11 18:11 ` [Qemu-devel] [PATCH v3 08/21] block: Allow reference for bdrv_file_open() Max Reitz
2013-12-12  8:01   ` Fam Zheng
2013-12-13 15:55     ` Max Reitz
2013-12-11 18:11 ` [Qemu-devel] [PATCH v3 09/21] block: Pass reference to bdrv_file_open() Max Reitz
2013-12-11 18:11 ` [Qemu-devel] [PATCH v3 10/21] block: Allow block devices without files Max Reitz
2013-12-11 18:11 ` [Qemu-devel] [PATCH v3 11/21] block: Allow recursive "file"s Max Reitz
2013-12-11 18:11 ` [Qemu-devel] [PATCH v3 12/21] qemu-iotests: Fix output of test 051 Max Reitz
2013-12-11 18:11 ` [Qemu-devel] [PATCH v3 13/21] blockdev: Move "file" to legacy_opts Max Reitz
2013-12-11 18:11 ` [Qemu-devel] [PATCH v3 14/21] blkdebug: Allow command-line file configuration Max Reitz
2013-12-11 18:11 ` [Qemu-devel] [PATCH v3 15/21] blkdebug: Make filename optional Max Reitz
2013-12-11 18:11 ` [Qemu-devel] [PATCH v3 16/21] blkverify: Allow command-line configuration Max Reitz
2013-12-11 18:11 ` [Qemu-devel] [PATCH v3 17/21] blkverify: Don't require protocol filename Max Reitz
2013-12-11 18:11 ` [Qemu-devel] [PATCH v3 18/21] blkdebug: Alias "errno" as "error" Max Reitz
2013-12-11 18:11 ` [Qemu-devel] [PATCH v3 19/21] qapi: QMP interface for blkdebug and blkverify Max Reitz
2013-12-11 18:11 ` [Qemu-devel] [PATCH v3 20/21] qemu-io: Make filename optional Max Reitz
2013-12-11 18:11 ` [Qemu-devel] [PATCH v3 21/21] iotests: Test new blkdebug/blkverify interface Max Reitz
2013-12-12 10:41   ` Fam Zheng
2013-12-13 15:59     ` Max Reitz
2013-12-12 10:45 ` [Qemu-devel] [PATCH v3 00/21] blkdebug/blkverify: Allow QMP configuration Fam Zheng

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=52A95517.3020303@redhat.com \
    --to=famz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /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).