diff options
author | Markus Armbruster <armbru@redhat.com> | 2018-07-03 10:53:47 +0200 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2018-07-03 23:18:56 +0200 |
commit | a193352ff9c7cd2cd07846118bc49921d0f53af8 (patch) | |
tree | c89a35a6fb781e57629832b4f95b086bdc90fa38 /qobject/qjson.c | |
parent | cab5ad86b41af6deead6f9bd6edc8a2353eb3e90 (diff) | |
download | qemu-a193352ff9c7cd2cd07846118bc49921d0f53af8.zip qemu-a193352ff9c7cd2cd07846118bc49921d0f53af8.tar.gz qemu-a193352ff9c7cd2cd07846118bc49921d0f53af8.tar.bz2 |
qobject: New qdict_from_jsonf_nofail()
Many uses of qobject_from_jsonf() convert JSON objects. Create new
convenience function qdict_from_jsonf_nofail() that includes the
conversion to QDict. The next few commits will put it to use.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20180703085358.13941-22-armbru@redhat.com>
Diffstat (limited to 'qobject/qjson.c')
-rw-r--r-- | qobject/qjson.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/qobject/qjson.c b/qobject/qjson.c index 9816a65..0df3120 100644 --- a/qobject/qjson.c +++ b/qobject/qjson.c @@ -76,6 +76,24 @@ QObject *qobject_from_jsonf(const char *string, ...) return obj; } +/* + * Parse @string as JSON object with %-escapes interpolated. + * Abort on error. Do not use with untrusted @string. + * Return the resulting QDict. It is never null. + */ +QDict *qdict_from_jsonf_nofail(const char *string, ...) +{ + QDict *obj; + va_list ap; + + va_start(ap, string); + obj = qobject_to(QDict, qobject_from_jsonv(string, &ap, &error_abort)); + va_end(ap); + + assert(obj); + return obj; +} + typedef struct ToJsonIterState { int indent; |