From 99dbfd1db1110f579f47b40155b9bf750d2cd6ad Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Tue, 28 Feb 2017 22:26:54 +0100 Subject: [PATCH] qobject: Propagate parse errors through qobject_from_jsonv() The next few commits will put the errors to use where appropriate. Signed-off-by: Markus Armbruster Reviewed-by: Kevin Wolf Message-Id: <1488317230-26248-9-git-send-email-armbru@redhat.com> --- include/qapi/qmp/qjson.h | 3 ++- qobject/qjson.c | 12 ++++++++---- tests/libqtest.c | 2 +- tests/test-qobject-input-visitor.c | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/include/qapi/qmp/qjson.h b/include/qapi/qmp/qjson.h index 02b1f2ce31..6fe42d0f13 100644 --- a/include/qapi/qmp/qjson.h +++ b/include/qapi/qmp/qjson.h @@ -19,7 +19,8 @@ QObject *qobject_from_json(const char *string); QObject *qobject_from_jsonf(const char *string, ...) GCC_FMT_ATTR(1, 2); -QObject *qobject_from_jsonv(const char *string, va_list *ap) GCC_FMT_ATTR(1, 0); +QObject *qobject_from_jsonv(const char *string, va_list *ap, Error **errp) + GCC_FMT_ATTR(1, 0); QString *qobject_to_json(const QObject *obj); QString *qobject_to_json_pretty(const QObject *obj); diff --git a/qobject/qjson.c b/qobject/qjson.c index 9a0de89079..339c9f7de2 100644 --- a/qobject/qjson.c +++ b/qobject/qjson.c @@ -12,6 +12,7 @@ */ #include "qemu/osdep.h" +#include "qapi/error.h" #include "qapi/qmp/json-lexer.h" #include "qapi/qmp/json-parser.h" #include "qapi/qmp/json-streamer.h" @@ -24,15 +25,17 @@ typedef struct JSONParsingState JSONMessageParser parser; va_list *ap; QObject *result; + Error *err; } JSONParsingState; static void parse_json(JSONMessageParser *parser, GQueue *tokens) { JSONParsingState *s = container_of(parser, JSONParsingState, parser); - s->result = json_parser_parse(tokens, s->ap); + + s->result = json_parser_parse_err(tokens, s->ap, &s->err); } -QObject *qobject_from_jsonv(const char *string, va_list *ap) +QObject *qobject_from_jsonv(const char *string, va_list *ap, Error **errp) { JSONParsingState state = {}; @@ -43,12 +46,13 @@ QObject *qobject_from_jsonv(const char *string, va_list *ap) json_message_parser_flush(&state.parser); json_message_parser_destroy(&state.parser); + error_propagate(errp, state.err); return state.result; } QObject *qobject_from_json(const char *string) { - return qobject_from_jsonv(string, NULL); + return qobject_from_jsonv(string, NULL, NULL); } /* @@ -61,7 +65,7 @@ QObject *qobject_from_jsonf(const char *string, ...) va_list ap; va_start(ap, string); - obj = qobject_from_jsonv(string, &ap); + obj = qobject_from_jsonv(string, &ap, NULL); va_end(ap); assert(obj != NULL); diff --git a/tests/libqtest.c b/tests/libqtest.c index ca6b641963..9033c5f82c 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -442,7 +442,7 @@ void qmp_fd_sendv(int fd, const char *fmt, va_list ap) * is an array type. */ va_copy(ap_copy, ap); - qobj = qobject_from_jsonv(fmt, &ap_copy); + qobj = qobject_from_jsonv(fmt, &ap_copy, NULL); va_end(ap_copy); /* No need to send anything for an empty QObject. */ diff --git a/tests/test-qobject-input-visitor.c b/tests/test-qobject-input-visitor.c index 32ba492a1a..36cc4b539e 100644 --- a/tests/test-qobject-input-visitor.c +++ b/tests/test-qobject-input-visitor.c @@ -51,7 +51,7 @@ static Visitor *visitor_input_test_init_internal(TestInputVisitorData *data, { visitor_input_teardown(data, NULL); - data->obj = qobject_from_jsonv(json_string, ap); + data->obj = qobject_from_jsonv(json_string, ap, NULL); g_assert(data->obj); if (keyval) {