qlit: add qobject_from_qlit()

Instantiate a QObject* from a literal QLitObject.

LitObject only supports int64_t for now. uint64_t and double aren't
implemented.

Backports commit 3cf42b8b3af1bd61e736a9ca0f94806c7931ae56 from qemu
This commit is contained in:
Marc-André Lureau 2018-03-20 10:30:13 -04:00 committed by Lioncash
parent 6b2143ad64
commit 910d50be6b
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7
16 changed files with 53 additions and 0 deletions

View file

@ -2203,6 +2203,7 @@
#define qlist_size_iter qlist_size_iter_aarch64
#define qlist_type qlist_type_aarch64
#define qlit_equal_qobject qlit_equal_qobject_aarch64
#define qobject_from_qlit qobject_from_qlit_aarch64
#define qobject_input_end_implicit_struct qobject_input_end_implicit_struct_aarch64
#define qobject_input_end_list qobject_input_end_list_aarch64
#define qobject_input_end_struct qobject_input_end_struct_aarch64

View file

@ -2203,6 +2203,7 @@
#define qlist_size_iter qlist_size_iter_aarch64eb
#define qlist_type qlist_type_aarch64eb
#define qlit_equal_qobject qlit_equal_qobject_aarch64eb
#define qobject_from_qlit qobject_from_qlit_aarch64eb
#define qobject_input_end_implicit_struct qobject_input_end_implicit_struct_aarch64eb
#define qobject_input_end_list qobject_input_end_list_aarch64eb
#define qobject_input_end_struct qobject_input_end_struct_aarch64eb

View file

@ -2203,6 +2203,7 @@
#define qlist_size_iter qlist_size_iter_arm
#define qlist_type qlist_type_arm
#define qlit_equal_qobject qlit_equal_qobject_arm
#define qobject_from_qlit qobject_from_qlit_arm
#define qobject_input_end_implicit_struct qobject_input_end_implicit_struct_arm
#define qobject_input_end_list qobject_input_end_list_arm
#define qobject_input_end_struct qobject_input_end_struct_arm

View file

@ -2203,6 +2203,7 @@
#define qlist_size_iter qlist_size_iter_armeb
#define qlist_type qlist_type_armeb
#define qlit_equal_qobject qlit_equal_qobject_armeb
#define qobject_from_qlit qobject_from_qlit_armeb
#define qobject_input_end_implicit_struct qobject_input_end_implicit_struct_armeb
#define qobject_input_end_list qobject_input_end_list_armeb
#define qobject_input_end_struct qobject_input_end_struct_armeb

View file

@ -2209,6 +2209,7 @@ symbols = (
'qlist_size_iter',
'qlist_type',
'qlit_equal_qobject',
'qobject_from_qlit',
'qobject_input_end_implicit_struct',
'qobject_input_end_list',
'qobject_input_end_struct',

View file

@ -50,4 +50,6 @@ struct QLitDictEntry {
bool qlit_equal_qobject(const QLitObject *lhs, const QObject *rhs);
QObject *qobject_from_qlit(const QLitObject *qlit);
#endif /* QLIT_H */

View file

@ -2203,6 +2203,7 @@
#define qlist_size_iter qlist_size_iter_m68k
#define qlist_type qlist_type_m68k
#define qlit_equal_qobject qlit_equal_qobject_m68k
#define qobject_from_qlit qobject_from_qlit_m68k
#define qobject_input_end_implicit_struct qobject_input_end_implicit_struct_m68k
#define qobject_input_end_list qobject_input_end_list_m68k
#define qobject_input_end_struct qobject_input_end_struct_m68k

View file

@ -2203,6 +2203,7 @@
#define qlist_size_iter qlist_size_iter_mips
#define qlist_type qlist_type_mips
#define qlit_equal_qobject qlit_equal_qobject_mips
#define qobject_from_qlit qobject_from_qlit_mips
#define qobject_input_end_implicit_struct qobject_input_end_implicit_struct_mips
#define qobject_input_end_list qobject_input_end_list_mips
#define qobject_input_end_struct qobject_input_end_struct_mips

View file

@ -2203,6 +2203,7 @@
#define qlist_size_iter qlist_size_iter_mips64
#define qlist_type qlist_type_mips64
#define qlit_equal_qobject qlit_equal_qobject_mips64
#define qobject_from_qlit qobject_from_qlit_mips64
#define qobject_input_end_implicit_struct qobject_input_end_implicit_struct_mips64
#define qobject_input_end_list qobject_input_end_list_mips64
#define qobject_input_end_struct qobject_input_end_struct_mips64

View file

@ -2203,6 +2203,7 @@
#define qlist_size_iter qlist_size_iter_mips64el
#define qlist_type qlist_type_mips64el
#define qlit_equal_qobject qlit_equal_qobject_mips64el
#define qobject_from_qlit qobject_from_qlit_mips64el
#define qobject_input_end_implicit_struct qobject_input_end_implicit_struct_mips64el
#define qobject_input_end_list qobject_input_end_list_mips64el
#define qobject_input_end_struct qobject_input_end_struct_mips64el

View file

@ -2203,6 +2203,7 @@
#define qlist_size_iter qlist_size_iter_mipsel
#define qlist_type qlist_type_mipsel
#define qlit_equal_qobject qlit_equal_qobject_mipsel
#define qobject_from_qlit qobject_from_qlit_mipsel
#define qobject_input_end_implicit_struct qobject_input_end_implicit_struct_mipsel
#define qobject_input_end_list qobject_input_end_list_mipsel
#define qobject_input_end_struct qobject_input_end_struct_mipsel

View file

@ -2203,6 +2203,7 @@
#define qlist_size_iter qlist_size_iter_powerpc
#define qlist_type qlist_type_powerpc
#define qlit_equal_qobject qlit_equal_qobject_powerpc
#define qobject_from_qlit qobject_from_qlit_powerpc
#define qobject_input_end_implicit_struct qobject_input_end_implicit_struct_powerpc
#define qobject_input_end_list qobject_input_end_list_powerpc
#define qobject_input_end_struct qobject_input_end_struct_powerpc

View file

@ -22,6 +22,7 @@
#include "qapi/qmp/qnum.h"
#include "qapi/qmp/qobject.h"
#include "qapi/qmp/qstring.h"
#include "qapi/qmp/qnull.h"
static bool qlit_equal_qdict(const QLitObject *lhs, const QDict *qdict)
{
@ -87,3 +88,39 @@ bool qlit_equal_qobject(const QLitObject *lhs, const QObject *rhs)
return false;
}
QObject *qobject_from_qlit(const QLitObject *qlit)
{
switch (qlit->type) {
case QTYPE_QNULL:
return QOBJECT(qnull());
case QTYPE_QNUM:
return QOBJECT(qnum_from_int(qlit->value.qnum));
case QTYPE_QSTRING:
return QOBJECT(qstring_from_str(qlit->value.qstr));
case QTYPE_QDICT: {
QDict *qdict = qdict_new();
QLitDictEntry *e;
for (e = qlit->value.qdict; e->key; e++) {
qdict_put_obj(qdict, e->key, qobject_from_qlit(&e->value));
}
return QOBJECT(qdict);
}
case QTYPE_QLIST: {
QList *qlist = qlist_new();
QLitObject *e;
for (e = qlit->value.qlist; e->type != QTYPE_NONE; e++) {
qlist_append_obj(qlist, qobject_from_qlit(e));
}
return QOBJECT(qlist);
}
case QTYPE_QBOOL:
return QOBJECT(qbool_from_bool(qlit->value.qbool));
default:
assert(0);
}
return NULL;
}

View file

@ -2203,6 +2203,7 @@
#define qlist_size_iter qlist_size_iter_sparc
#define qlist_type qlist_type_sparc
#define qlit_equal_qobject qlit_equal_qobject_sparc
#define qobject_from_qlit qobject_from_qlit_sparc
#define qobject_input_end_implicit_struct qobject_input_end_implicit_struct_sparc
#define qobject_input_end_list qobject_input_end_list_sparc
#define qobject_input_end_struct qobject_input_end_struct_sparc

View file

@ -2203,6 +2203,7 @@
#define qlist_size_iter qlist_size_iter_sparc64
#define qlist_type qlist_type_sparc64
#define qlit_equal_qobject qlit_equal_qobject_sparc64
#define qobject_from_qlit qobject_from_qlit_sparc64
#define qobject_input_end_implicit_struct qobject_input_end_implicit_struct_sparc64
#define qobject_input_end_list qobject_input_end_list_sparc64
#define qobject_input_end_struct qobject_input_end_struct_sparc64

View file

@ -2203,6 +2203,7 @@
#define qlist_size_iter qlist_size_iter_x86_64
#define qlist_type qlist_type_x86_64
#define qlit_equal_qobject qlit_equal_qobject_x86_64
#define qobject_from_qlit qobject_from_qlit_x86_64
#define qobject_input_end_implicit_struct qobject_input_end_implicit_struct_x86_64
#define qobject_input_end_list qobject_input_end_list_x86_64
#define qobject_input_end_struct qobject_input_end_struct_x86_64