[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [RFC PATCH 09/11] Implement qdict_flatten()
From: |
Eric Blake |
Subject: |
Re: [Qemu-devel] [RFC PATCH 09/11] Implement qdict_flatten() |
Date: |
Thu, 11 Jul 2013 14:25:48 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130625 Thunderbird/17.0.7 |
On 07/09/2013 03:53 AM, Kevin Wolf wrote:
Worth repeating this comment from the code into the commit message?
> + * qdict_flatten(): For each nested QDict with key x, all fields with
key y
> + * are moved to this QDict and their key is renamed to "x.y".
Otherwise, I had to read nearly the entire patch to learn what I was
supposed to be reviewing.
> Signed-off-by: Kevin Wolf <address@hidden>
> ---
> include/qapi/qmp/qdict.h | 1 +
> qobject/qdict.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 48 insertions(+)
>
> +++ b/qobject/qdict.c
> @@ -476,3 +476,50 @@ static void qdict_destroy_obj(QObject *obj)
>
> g_free(qdict);
> }
> +
> +static void qdict_do_flatten(QDict *qdict, QDict *target, const char *prefix)
> +{
> + QObject *value;
> + const QDictEntry *entry, *next;
> + const char *new_key;
> + bool delete;
> +
> + entry = qdict_first(qdict);
> +
> + while (entry != NULL) {
> +
> + next = qdict_next(qdict, entry);
> + value = qdict_entry_value(entry);
> + new_key = NULL;
> + delete = false;
> +
> + if (prefix) {
> + qobject_incref(value);
> + new_key = g_strdup_printf("%s.%s", prefix, entry->key);
> + qdict_put_obj(target, new_key, value);
You are calling this function with the same parameter for both qdict and
target. Doesn't that mean you are modifying qdict while iterating it?
Is that safe? [/me re-reads] - oh, you recursively call this function,
and this modification of target happens _only_ if prefix is non-null,
which happens only:
> + delete = true;
> + }
> +
> + if (qobject_type(value) == QTYPE_QDICT) {
> + qdict_do_flatten(qobject_to_qdict(value), target,
> + new_key ? new_key : entry->key);
when passing two different dicts into the function. Maybe add an
assert(!prefix || qdict != target).
> + delete = true;
> + }
> +
> + if (delete) {
> + qdict_del(qdict, entry->key);
> + }
> +
> + entry = next;
> + }
> +}
> +
> +/**
> + * qdict_flatten(): For each nested QDict with key x, all fields with key y
> + * are moved to this QDict and their key is renamed to "x.y".
> + */
> +void qdict_flatten(QObject *obj)
> +{
> + QDict *qdict = qobject_to_qdict(obj);
> + qdict_do_flatten(qdict, qdict, NULL);
> +}
>
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
- Re: [Qemu-devel] [RFC PATCH 04/11] qapi-visit.py: Implement 'base' for unions, (continued)
- [Qemu-devel] [RFC PATCH 02/11] qapi-types.py: Implement 'base' for unions, Kevin Wolf, 2013/07/09
- [Qemu-devel] [RFC PATCH 05/11] qapi: Add visitor for implicit structs, Kevin Wolf, 2013/07/09
- [Qemu-devel] [RFC PATCH 06/11] qapi: Flat unions with arbitrary discriminator, Kevin Wolf, 2013/07/09
- [Qemu-devel] [RFC PATCH 09/11] Implement qdict_flatten(), Kevin Wolf, 2013/07/09
- Re: [Qemu-devel] [RFC PATCH 09/11] Implement qdict_flatten(),
Eric Blake <=
- [Qemu-devel] [RFC PATCH 07/11] qapi: Add consume argument to qmp_input_get_object(), Kevin Wolf, 2013/07/09
- [Qemu-devel] [RFC PATCH 08/11] qapi: Anonymous unions, Kevin Wolf, 2013/07/09
- [Qemu-devel] [RFC PATCH 10/11] block: Allow "driver" option on the top level, Kevin Wolf, 2013/07/09
- [Qemu-devel] [RFC PATCH 11/11] [WIP] block: Implement 'blockdev-add' QMP command, Kevin Wolf, 2013/07/09