diff options
author | Marc-André Lureau <marcandre.lureau@redhat.com> | 2018-04-19 17:01:44 +0200 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2018-05-04 08:27:53 +0200 |
commit | f5a74a5a50387c6f980b2e2f94f062487a1826da (patch) | |
tree | eefbe4d2f8bb0f889c9643d140fd702f131c4fd0 /qobject/qdict.c | |
parent | cb3e7f08aeaab0ab13e629ce8496dca150a449ba (diff) | |
download | qemu-f5a74a5a50387c6f980b2e2f94f062487a1826da.zip qemu-f5a74a5a50387c6f980b2e2f94f062487a1826da.tar.gz qemu-f5a74a5a50387c6f980b2e2f94f062487a1826da.tar.bz2 |
qobject: Modify qobject_ref() to return obj
For convenience and clarity, make it possible to call qobject_ref() at
the time when the reference is associated with a variable, or
argument, by making qobject_ref() return the same pointer as given.
Use that to simplify the callers.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20180419150145.24795-5-marcandre.lureau@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
[Useless change to qobject_ref_impl() dropped, commit message improved
slightly]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'qobject/qdict.c')
-rw-r--r-- | qobject/qdict.c | 33 |
1 files changed, 11 insertions, 22 deletions
diff --git a/qobject/qdict.c b/qobject/qdict.c index 2e9bd53..22800ee 100644 --- a/qobject/qdict.c +++ b/qobject/qdict.c @@ -373,8 +373,7 @@ QDict *qdict_clone_shallow(const QDict *src) for (i = 0; i < QDICT_BUCKET_MAX; i++) { QLIST_FOREACH(entry, &src->table[i], next) { - qobject_ref(entry->value); - qdict_put_obj(dest, entry->key, entry->value); + qdict_put_obj(dest, entry->key, qobject_ref(entry->value)); } } @@ -480,8 +479,7 @@ void qdict_copy_default(QDict *dst, QDict *src, const char *key) val = qdict_get(src, key); if (val) { - qobject_ref(val); - qdict_put_obj(dst, key, val); + qdict_put_obj(dst, key, qobject_ref(val)); } } @@ -526,8 +524,7 @@ static void qdict_flatten_qlist(QList *qlist, QDict *target, const char *prefix) qdict_flatten_qlist(qobject_to(QList, value), target, new_key); } else { /* All other types are moved to the target unchanged. */ - qobject_ref(value); - qdict_put_obj(target, new_key, value); + qdict_put_obj(target, new_key, qobject_ref(value)); } g_free(new_key); @@ -566,8 +563,7 @@ static void qdict_flatten_qdict(QDict *qdict, QDict *target, const char *prefix) delete = true; } else if (prefix) { /* All other objects are moved to the target unchanged. */ - qobject_ref(value); - qdict_put_obj(target, new_key, value); + qdict_put_obj(target, new_key, qobject_ref(value)); delete = true; } @@ -610,8 +606,7 @@ void qdict_extract_subqdict(QDict *src, QDict **dst, const char *start) while (entry != NULL) { next = qdict_next(src, entry); if (strstart(entry->key, start, &p)) { - qobject_ref(entry->value); - qdict_put_obj(*dst, p, entry->value); + qdict_put_obj(*dst, p, qobject_ref(entry->value)); qdict_del(src, entry->key); } entry = next; @@ -894,16 +889,14 @@ QObject *qdict_crumple(const QDict *src, Error **errp) qdict_put_obj(two_level, prefix, QOBJECT(child_dict)); } - qobject_ref(ent->value); - qdict_put_obj(child_dict, suffix, ent->value); + qdict_put_obj(child_dict, suffix, qobject_ref(ent->value)); } else { if (child) { error_setg(errp, "Key %s prefix is already set as a dict", prefix); goto error; } - qobject_ref(ent->value); - qdict_put_obj(two_level, prefix, ent->value); + qdict_put_obj(two_level, prefix, qobject_ref(ent->value)); } g_free(prefix); @@ -924,8 +917,7 @@ QObject *qdict_crumple(const QDict *src, Error **errp) qdict_put_obj(multi_level, ent->key, child); } else { - qobject_ref(ent->value); - qdict_put_obj(multi_level, ent->key, ent->value); + qdict_put_obj(multi_level, ent->key, qobject_ref(ent->value)); } } qobject_unref(two_level); @@ -951,8 +943,7 @@ QObject *qdict_crumple(const QDict *src, Error **errp) goto error; } - qobject_ref(child); - qlist_append_obj(qobject_to(QList, dst), child); + qlist_append_obj(qobject_to(QList, dst), qobject_ref(child)); } qobject_unref(multi_level); multi_level = NULL; @@ -1055,8 +1046,7 @@ void qdict_join(QDict *dest, QDict *src, bool overwrite) next = qdict_next(src, entry); if (overwrite || !qdict_haskey(dest, entry->key)) { - qobject_ref(entry->value); - qdict_put_obj(dest, entry->key, entry->value); + qdict_put_obj(dest, entry->key, qobject_ref(entry->value)); qdict_del(src, entry->key); } @@ -1088,8 +1078,7 @@ bool qdict_rename_keys(QDict *qdict, const QDictRenames *renames, Error **errp) } qobj = qdict_get(qdict, renames->from); - qobject_ref(qobj); - qdict_put_obj(qdict, renames->to, qobj); + qdict_put_obj(qdict, renames->to, qobject_ref(qobj)); qdict_del(qdict, renames->from); } |