Message ID | 1386954633-28905-6-git-send-email-mreitz@redhat.com |
---|---|
State | New |
Headers | show |
Am 13.12.2013 um 18:10 hat Max Reitz geschrieben: > delete is always set to true, therefore it can be removed. > > Signed-off-by: Max Reitz <mreitz@redhat.com> Nope, this can't be right. delete is always set, except for simple types in the top-level QDict. They get deleted now instead of being left alone. But it coincides pretty well with the new loop condition. Leaving uninteresting stuff aside, the loop looks now like this: while (entry != NULL) { ... entry = qdict_first(qdict); } So the loop only terminates when all elements have been removed. How lucky we are that it really does remove all elements now! Perhaps some other code is broken, or I missed something else, but qemu-iotests 067 segfaults after this patch. Kevin
On 13.12.2013 19:58, Kevin Wolf wrote: > Am 13.12.2013 um 18:10 hat Max Reitz geschrieben: >> delete is always set to true, therefore it can be removed. >> >> Signed-off-by: Max Reitz <mreitz@redhat.com> > Nope, this can't be right. > > delete is always set, except for simple types in the top-level QDict. > They get deleted now instead of being left alone. Ah, I don't know how I missed the "if (prefix)"... Well then, I feared requiring delete would somehow require qdict_flatten_qlist() to have something similar, but if this can be wrong for top-level elements only, at least that won't be the case. Max
diff --git a/qobject/qdict.c b/qobject/qdict.c index 1d0e66c..ec42b1c 100644 --- a/qobject/qdict.c +++ b/qobject/qdict.c @@ -520,18 +520,15 @@ static void qdict_flatten_qlist(QList *qlist, QDict *target, const char *prefix) static void qdict_flatten_qdict(QDict *qdict, QDict *target, const char *prefix) { QObject *value; - const QDictEntry *entry, *next; + const QDictEntry *entry; 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) { new_key = g_strdup_printf("%s.%s", prefix, entry->key); @@ -542,29 +539,21 @@ static void qdict_flatten_qdict(QDict *qdict, QDict *target, const char *prefix) * itself disappears. */ 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. */ qobject_incref(value); qdict_put_obj(target, new_key, value); - delete = true; } g_free(new_key); - if (delete) { - qdict_del(qdict, entry->key); - - /* Restart loop after modifying the iterated QDict */ - entry = qdict_first(qdict); - continue; - } + qdict_del(qdict, entry->key); - entry = next; + /* Restart loop after modifying the iterated QDict */ + entry = qdict_first(qdict); } }
delete is always set to true, therefore it can be removed. Signed-off-by: Max Reitz <mreitz@redhat.com> --- qobject/qdict.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-)