diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2017-09-04 13:28:09 +0100 |
---|---|---|
committer | Peter Maydell <peter.maydell@linaro.org> | 2017-09-04 13:28:09 +0100 |
commit | 98bfaac788be0ca63d7d010c8d4ba100ff1d8278 (patch) | |
tree | a6adc21256f54beb05f428440b0ed0e69bdddc45 /qobject | |
parent | 32f0f68bb77289b75a82925f712bb52e16eac3ba (diff) | |
parent | ebf677c8497ee81537f7ce57b165c978511ccde5 (diff) |
Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2017-09-01-v3' into staging
QAPI patches for 2017-09-01
# gpg: Signature made Mon 04 Sep 2017 12:30:31 BST
# gpg: using RSA key 0x3870B400EB918653
# gpg: Good signature from "Markus Armbruster <armbru@redhat.com>"
# gpg: aka "Markus Armbruster <armbru@pond.sub.org>"
# Primary key fingerprint: 354B C8B3 D7EB 2A6B 6867 4E5F 3870 B400 EB91 8653
* remotes/armbru/tags/pull-qapi-2017-09-01-v3: (47 commits)
qapi: drop the sentinel in enum array
qapi: Change data type of the FOO_lookup generated for enum FOO
qapi: Convert indirect uses of FOO_lookup[...] to qapi_enum_lookup()
qapi: Mechanically convert FOO_lookup[...] to FOO_str(...)
qapi: Generate FOO_str() macro for QAPI enum FOO
qapi: Avoid unnecessary use of enum lookup table's sentinel
qapi: Use qapi_enum_parse() in input_type_enum()
crypto: Use qapi_enum_parse() in qcrypto_block_luks_name_lookup()
quorum: Use qapi_enum_parse() in quorum_open()
block: Use qemu_enum_parse() in blkdebug_debug_breakpoint()
hmp: Use qapi_enum_parse() in hmp_migrate_set_parameter()
hmp: Use qapi_enum_parse() in hmp_migrate_set_capability()
tpm: Clean up model registration & lookup
tpm: Clean up driver registration & lookup
qapi: Drop superfluous qapi_enum_parse() parameter max
qapi: Update qapi-code-gen.txt examples to match current code
qapi-schema: Improve section headings
qapi-schema: Move queries from common.json to qapi-schema.json
qapi-schema: Make block-core.json self-contained
qapi-schema: Fold event.json back into qapi-schema.json
...
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'qobject')
-rw-r--r-- | qobject/Makefile.objs | 2 | ||||
-rw-r--r-- | qobject/qlit.c | 84 |
2 files changed, 85 insertions, 1 deletions
diff --git a/qobject/Makefile.objs b/qobject/Makefile.objs index fc8885c9a4..002d25873a 100644 --- a/qobject/Makefile.objs +++ b/qobject/Makefile.objs @@ -1,2 +1,2 @@ -util-obj-y = qnull.o qnum.o qstring.o qdict.o qlist.o qbool.o +util-obj-y = qnull.o qnum.o qstring.o qdict.o qlist.o qbool.o qlit.o util-obj-y += qjson.o qobject.o json-lexer.o json-streamer.o json-parser.o diff --git a/qobject/qlit.c b/qobject/qlit.c new file mode 100644 index 0000000000..3c4882c784 --- /dev/null +++ b/qobject/qlit.c @@ -0,0 +1,84 @@ +/* + * QLit literal qobject + * + * Copyright IBM, Corp. 2009 + * Copyright (c) 2013, 2015, 2017 Red Hat Inc. + * + * Authors: + * Anthony Liguori <aliguori@us.ibm.com> + * Markus Armbruster <armbru@redhat.com> + * Marc-André Lureau <marcandre.lureau@redhat.com> + * + * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. + * See the COPYING.LIB file in the top-level directory. + */ + +#include "qemu/osdep.h" + +#include "qapi/qmp/qlit.h" +#include "qapi/qmp/types.h" + +static bool qlit_equal_qdict(const QLitObject *lhs, const QDict *qdict) +{ + int i; + + for (i = 0; lhs->value.qdict[i].key; i++) { + QObject *obj = qdict_get(qdict, lhs->value.qdict[i].key); + + if (!qlit_equal_qobject(&lhs->value.qdict[i].value, obj)) { + return false; + } + } + + /* Note: the literal qdict must not contain duplicates, this is + * considered a programming error and it isn't checked here. */ + if (qdict_size(qdict) != i) { + return false; + } + + return true; +} + +static bool qlit_equal_qlist(const QLitObject *lhs, const QList *qlist) +{ + QListEntry *e; + int i = 0; + + QLIST_FOREACH_ENTRY(qlist, e) { + QObject *obj = qlist_entry_obj(e); + + if (!qlit_equal_qobject(&lhs->value.qlist[i], obj)) { + return false; + } + i++; + } + + return !e && lhs->value.qlist[i].type == QTYPE_NONE; +} + +bool qlit_equal_qobject(const QLitObject *lhs, const QObject *rhs) +{ + if (!rhs || lhs->type != qobject_type(rhs)) { + return false; + } + + switch (lhs->type) { + case QTYPE_QBOOL: + return lhs->value.qbool == qbool_get_bool(qobject_to_qbool(rhs)); + case QTYPE_QNUM: + return lhs->value.qnum == qnum_get_int(qobject_to_qnum(rhs)); + case QTYPE_QSTRING: + return (strcmp(lhs->value.qstr, + qstring_get_str(qobject_to_qstring(rhs))) == 0); + case QTYPE_QDICT: + return qlit_equal_qdict(lhs, qobject_to_qdict(rhs)); + case QTYPE_QLIST: + return qlit_equal_qlist(lhs, qobject_to_qlist(rhs)); + case QTYPE_QNULL: + return true; + default: + break; + } + + return false; +} |