mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2024-12-22 19:35:34 +00:00
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. Backports commit f5a74a5a50387c6f980b2e2f94f062487a1826da from qemu
This commit is contained in:
parent
ab4528c1e4
commit
0087625b7e
|
@ -23,8 +23,7 @@ extern QNull qnull_;
|
|||
|
||||
static inline QNull *qnull(void)
|
||||
{
|
||||
qobject_ref(&qnull_);
|
||||
return &qnull_;
|
||||
return qobject_ref(&qnull_);
|
||||
}
|
||||
|
||||
bool qnull_is_equal(const QObject *x, const QObject *y);
|
||||
|
|
|
@ -103,8 +103,15 @@ static inline void qobject_unref_impl(QObject *obj)
|
|||
|
||||
/**
|
||||
* qobject_ref(): Increment QObject's reference count
|
||||
*
|
||||
* Returns: the same @obj. The type of @obj will be propagated to the
|
||||
* return type.
|
||||
*/
|
||||
#define qobject_ref(obj) qobject_ref_impl(QOBJECT(obj))
|
||||
#define qobject_ref(obj) ({ \
|
||||
typeof(obj) _o = (obj); \
|
||||
qobject_ref_impl(QOBJECT(_o)); \
|
||||
_o; \
|
||||
})
|
||||
|
||||
/**
|
||||
* qobject_unref(): Decrement QObject's reference count, deallocate
|
||||
|
|
|
@ -463,8 +463,7 @@ static void qobject_input_type_any(Visitor *v, const char *name, QObject **obj,
|
|||
return;
|
||||
}
|
||||
|
||||
qobject_ref(qobj);
|
||||
*obj = qobj;
|
||||
*obj = qobject_ref(qobj);
|
||||
}
|
||||
|
||||
static void qobject_input_type_null(Visitor *v, const char *name,
|
||||
|
@ -536,8 +535,7 @@ static QObjectInputVisitor *qobject_input_visitor_base_new(QObject *obj)
|
|||
v->visitor.optional = qobject_input_optional;
|
||||
v->visitor.free = qobject_input_free;
|
||||
|
||||
v->root = obj;
|
||||
qobject_ref(obj);
|
||||
v->root = qobject_ref(obj);
|
||||
|
||||
return v;
|
||||
}
|
||||
|
|
|
@ -191,8 +191,7 @@ static void qobject_output_type_any(Visitor *v, const char *name, QObject **obj,
|
|||
Error **errp)
|
||||
{
|
||||
QObjectOutputVisitor *qov = to_qov(v);
|
||||
qobject_ref(*obj);
|
||||
qobject_output_add_obj(qov, name, *obj);
|
||||
qobject_output_add_obj(qov, name, qobject_ref(*obj));
|
||||
}
|
||||
|
||||
static void qobject_output_type_null(Visitor *v, const char *name,
|
||||
|
|
|
@ -493,8 +493,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);
|
||||
|
@ -533,8 +532,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;
|
||||
}
|
||||
|
||||
|
@ -576,8 +574,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);
|
||||
}
|
||||
|
||||
|
@ -611,8 +608,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;
|
||||
|
@ -890,16 +886,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);
|
||||
|
@ -921,8 +915,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);
|
||||
|
@ -948,8 +941,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;
|
||||
|
@ -990,8 +982,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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue