mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2025-07-06 15:50:35 +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)
|
static inline QNull *qnull(void)
|
||||||
{
|
{
|
||||||
qobject_ref(&qnull_);
|
return qobject_ref(&qnull_);
|
||||||
return &qnull_;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool qnull_is_equal(const QObject *x, const QObject *y);
|
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
|
* 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
|
* 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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
qobject_ref(qobj);
|
*obj = qobject_ref(qobj);
|
||||||
*obj = qobj;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void qobject_input_type_null(Visitor *v, const char *name,
|
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.optional = qobject_input_optional;
|
||||||
v->visitor.free = qobject_input_free;
|
v->visitor.free = qobject_input_free;
|
||||||
|
|
||||||
v->root = obj;
|
v->root = qobject_ref(obj);
|
||||||
qobject_ref(obj);
|
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
|
@ -191,8 +191,7 @@ static void qobject_output_type_any(Visitor *v, const char *name, QObject **obj,
|
||||||
Error **errp)
|
Error **errp)
|
||||||
{
|
{
|
||||||
QObjectOutputVisitor *qov = to_qov(v);
|
QObjectOutputVisitor *qov = to_qov(v);
|
||||||
qobject_ref(*obj);
|
qobject_output_add_obj(qov, name, qobject_ref(*obj));
|
||||||
qobject_output_add_obj(qov, name, *obj);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void qobject_output_type_null(Visitor *v, const char *name,
|
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);
|
qdict_flatten_qlist(qobject_to(QList, value), target, new_key);
|
||||||
} else {
|
} else {
|
||||||
/* All other types are moved to the target unchanged. */
|
/* All other types are moved to the target unchanged. */
|
||||||
qobject_ref(value);
|
qdict_put_obj(target, new_key, qobject_ref(value));
|
||||||
qdict_put_obj(target, new_key, value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free(new_key);
|
g_free(new_key);
|
||||||
|
@ -533,8 +532,7 @@ static void qdict_flatten_qdict(QDict *qdict, QDict *target, const char *prefix)
|
||||||
delete = true;
|
delete = true;
|
||||||
} else if (prefix) {
|
} else if (prefix) {
|
||||||
/* All other objects are moved to the target unchanged. */
|
/* All other objects are moved to the target unchanged. */
|
||||||
qobject_ref(value);
|
qdict_put_obj(target, new_key, qobject_ref(value));
|
||||||
qdict_put_obj(target, new_key, value);
|
|
||||||
delete = true;
|
delete = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -576,8 +574,7 @@ bool qdict_rename_keys(QDict *qdict, const QDictRenames *renames, Error **errp)
|
||||||
}
|
}
|
||||||
|
|
||||||
qobj = qdict_get(qdict, renames->from);
|
qobj = qdict_get(qdict, renames->from);
|
||||||
qobject_ref(qobj);
|
qdict_put_obj(qdict, renames->to, qobject_ref(qobj));
|
||||||
qdict_put_obj(qdict, renames->to, qobj);
|
|
||||||
qdict_del(qdict, renames->from);
|
qdict_del(qdict, renames->from);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -611,8 +608,7 @@ void qdict_extract_subqdict(QDict *src, QDict **dst, const char *start)
|
||||||
while (entry != NULL) {
|
while (entry != NULL) {
|
||||||
next = qdict_next(src, entry);
|
next = qdict_next(src, entry);
|
||||||
if (strstart(entry->key, start, &p)) {
|
if (strstart(entry->key, start, &p)) {
|
||||||
qobject_ref(entry->value);
|
qdict_put_obj(*dst, p, qobject_ref(entry->value));
|
||||||
qdict_put_obj(*dst, p, entry->value);
|
|
||||||
qdict_del(src, entry->key);
|
qdict_del(src, entry->key);
|
||||||
}
|
}
|
||||||
entry = next;
|
entry = next;
|
||||||
|
@ -890,16 +886,14 @@ QObject *qdict_crumple(const QDict *src, Error **errp)
|
||||||
qdict_put_obj(two_level, prefix, QOBJECT(child_dict));
|
qdict_put_obj(two_level, prefix, QOBJECT(child_dict));
|
||||||
}
|
}
|
||||||
|
|
||||||
qobject_ref(ent->value);
|
qdict_put_obj(child_dict, suffix, qobject_ref(ent->value));
|
||||||
qdict_put_obj(child_dict, suffix, ent->value);
|
|
||||||
} else {
|
} else {
|
||||||
if (child) {
|
if (child) {
|
||||||
error_setg(errp, "Key %s prefix is already set as a dict",
|
error_setg(errp, "Key %s prefix is already set as a dict",
|
||||||
prefix);
|
prefix);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
qobject_ref(ent->value);
|
qdict_put_obj(two_level, prefix, qobject_ref(ent->value));
|
||||||
qdict_put_obj(two_level, prefix, ent->value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free(prefix);
|
g_free(prefix);
|
||||||
|
@ -921,8 +915,7 @@ QObject *qdict_crumple(const QDict *src, Error **errp)
|
||||||
|
|
||||||
qdict_put_obj(multi_level, ent->key, child);
|
qdict_put_obj(multi_level, ent->key, child);
|
||||||
} else {
|
} else {
|
||||||
qobject_ref(ent->value);
|
qdict_put_obj(multi_level, ent->key, qobject_ref(ent->value));
|
||||||
qdict_put_obj(multi_level, ent->key, ent->value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
qobject_unref(two_level);
|
qobject_unref(two_level);
|
||||||
|
@ -948,8 +941,7 @@ QObject *qdict_crumple(const QDict *src, Error **errp)
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
qobject_ref(child);
|
qlist_append_obj(qobject_to(QList, dst), qobject_ref(child));
|
||||||
qlist_append_obj(qobject_to(QList, dst), child);
|
|
||||||
}
|
}
|
||||||
qobject_unref(multi_level);
|
qobject_unref(multi_level);
|
||||||
multi_level = NULL;
|
multi_level = NULL;
|
||||||
|
@ -990,8 +982,7 @@ void qdict_join(QDict *dest, QDict *src, bool overwrite)
|
||||||
next = qdict_next(src, entry);
|
next = qdict_next(src, entry);
|
||||||
|
|
||||||
if (overwrite || !qdict_haskey(dest, entry->key)) {
|
if (overwrite || !qdict_haskey(dest, entry->key)) {
|
||||||
qobject_ref(entry->value);
|
qdict_put_obj(dest, entry->key, qobject_ref(entry->value));
|
||||||
qdict_put_obj(dest, entry->key, entry->value);
|
|
||||||
qdict_del(src, entry->key);
|
qdict_del(src, entry->key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue