diff options
author | Anthony Liguori <aliguori@us.ibm.com> | 2013-07-26 16:54:19 -0500 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2013-07-26 16:54:19 -0500 |
commit | 405c97c3a5950d8a49b90cb977e33b6b3f9a8f95 (patch) | |
tree | 0ea08a86ce91960577be3b720de34a0dddfe7623 /qobject | |
parent | 2fb861eb02f0955876e15b3de1f9c2d1f469dcf2 (diff) | |
parent | e3409362bd64731e042c9d001e43cc1d13d2df5d (diff) | |
download | qemu-405c97c3a5950d8a49b90cb977e33b6b3f9a8f95.zip qemu-405c97c3a5950d8a49b90cb977e33b6b3f9a8f95.tar.gz qemu-405c97c3a5950d8a49b90cb977e33b6b3f9a8f95.tar.bz2 |
Merge remote-tracking branch 'kwolf/for-anthony' into staging
# By Kevin Wolf (16) and Ian Main (2)
# Via Kevin Wolf
* kwolf/for-anthony:
Add tests for sync modes 'TOP' and 'NONE'
Implement sync modes for drive-backup.
Implement qdict_flatten()
blockdev: Split up 'cache' option
blockdev: Rename 'readonly' option to 'read-only'
qcow2: Use dashes instead of underscores in options
blockdev: Rename I/O throttling options for QMP
QemuOpts: Add qemu_opt_unset()
block: Allow "driver" option on the top level
qapi: Anonymous unions
qapi.py: Maintain a list of union types
qapi: Add consume argument to qmp_input_get_object()
qapi: Flat unions with arbitrary discriminator
qapi: Add visitor for implicit structs
docs: Document QAPI union types
qapi-visit.py: Implement 'base' for unions
qapi-visit.py: Split off generate_visit_struct_fields()
qapi-types.py: Implement 'base' for unions
Message-id: 1374870032-31672-1-git-send-email-kwolf@redhat.com
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'qobject')
-rw-r--r-- | qobject/qdict.c | 51 | ||||
-rw-r--r-- | qobject/qjson.c | 2 |
2 files changed, 53 insertions, 0 deletions
diff --git a/qobject/qdict.c b/qobject/qdict.c index ed381f9..472f106 100644 --- a/qobject/qdict.c +++ b/qobject/qdict.c @@ -476,3 +476,54 @@ 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); + delete = true; + } + + if (qobject_type(value) == QTYPE_QDICT) { + qdict_do_flatten(qobject_to_qdict(value), target, + new_key ? new_key : entry->key); + delete = true; + } + + if (delete) { + qdict_del(qdict, entry->key); + + /* Restart loop after modifying the iterated QDict */ + entry = qdict_first(qdict); + continue; + } + + 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". This operation + * is applied recursively for nested QDicts. + */ +void qdict_flatten(QDict *qdict) +{ + qdict_do_flatten(qdict, qdict, NULL); +} diff --git a/qobject/qjson.c b/qobject/qjson.c index 19085a1..6cf2511 100644 --- a/qobject/qjson.c +++ b/qobject/qjson.c @@ -260,6 +260,8 @@ static void to_json(const QObject *obj, QString *str, int pretty, int indent) /* XXX: should QError be emitted? */ case QTYPE_NONE: break; + case QTYPE_MAX: + abort(); } } |