mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2025-01-11 10:45:32 +00:00
qapi: Make more of qobject_to()
This patch reworks some places which use either qobject_type() checks plus qobject_to(), where the latter alone is sufficient, or NULL checks plus qobject_type() checks where we can simply do a qobject_to() != NULL check. Backports commit 532fb532847365f61a9c6e1291b6588a43bc1cc4 from qemu
This commit is contained in:
parent
0c71b44d41
commit
65b2b73b12
|
@ -297,7 +297,7 @@ static GenericList *qobject_input_next_list(Visitor *v, GenericList *tail,
|
||||||
QObjectInputVisitor *qiv = to_qiv(v);
|
QObjectInputVisitor *qiv = to_qiv(v);
|
||||||
StackObject *tos = QSLIST_FIRST(&qiv->stack);
|
StackObject *tos = QSLIST_FIRST(&qiv->stack);
|
||||||
|
|
||||||
assert(tos && tos->obj && qobject_type(tos->obj) == QTYPE_QLIST);
|
assert(tos && qobject_to(QList, tos->obj));
|
||||||
|
|
||||||
if (!tos->entry) {
|
if (!tos->entry) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -311,7 +311,7 @@ static void qobject_input_check_list(Visitor *v, Error **errp)
|
||||||
QObjectInputVisitor *qiv = to_qiv(v);
|
QObjectInputVisitor *qiv = to_qiv(v);
|
||||||
StackObject *tos = QSLIST_FIRST(&qiv->stack);
|
StackObject *tos = QSLIST_FIRST(&qiv->stack);
|
||||||
|
|
||||||
assert(tos && tos->obj && qobject_type(tos->obj) == QTYPE_QLIST);
|
assert(tos && qobject_to(QList, tos->obj));
|
||||||
|
|
||||||
if (tos->entry) {
|
if (tos->entry) {
|
||||||
error_setg(errp, "Only %u list elements expected in %s",
|
error_setg(errp, "Only %u list elements expected in %s",
|
||||||
|
|
|
@ -878,18 +878,20 @@ QObject *qdict_crumple(const QDict *src, Error **errp)
|
||||||
|
|
||||||
child = qdict_get(two_level, prefix);
|
child = qdict_get(two_level, prefix);
|
||||||
if (suffix) {
|
if (suffix) {
|
||||||
if (child) {
|
QDict *child_dict = qobject_to(QDict, child);
|
||||||
if (qobject_type(child) != QTYPE_QDICT) {
|
if (!child_dict) {
|
||||||
|
if (child) {
|
||||||
error_setg(errp, "Key %s prefix is already set as a scalar",
|
error_setg(errp, "Key %s prefix is already set as a scalar",
|
||||||
prefix);
|
prefix);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
child = QOBJECT(qdict_new());
|
child_dict = qdict_new();
|
||||||
qdict_put_obj(two_level, prefix, child);
|
qdict_put_obj(two_level, prefix, QOBJECT(child_dict));
|
||||||
}
|
}
|
||||||
|
|
||||||
qobject_incref(ent->value);
|
qobject_incref(ent->value);
|
||||||
qdict_put_obj(qobject_to(QDict, child), suffix, 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",
|
||||||
|
@ -910,8 +912,9 @@ QObject *qdict_crumple(const QDict *src, Error **errp)
|
||||||
for (ent = qdict_first(two_level); ent != NULL;
|
for (ent = qdict_first(two_level); ent != NULL;
|
||||||
ent = qdict_next(two_level, ent)) {
|
ent = qdict_next(two_level, ent)) {
|
||||||
|
|
||||||
if (qobject_type(ent->value) == QTYPE_QDICT) {
|
QDict *dict = qobject_to(QDict, ent->value);
|
||||||
child = qdict_crumple(qobject_to(QDict, ent->value), errp);
|
if (dict) {
|
||||||
|
child = qdict_crumple(dict, errp);
|
||||||
if (!child) {
|
if (!child) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue