提交 99dbfd1d 编写于 作者: M Markus Armbruster

qobject: Propagate parse errors through qobject_from_jsonv()

The next few commits will put the errors to use where appropriate.
Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
Reviewed-by: NKevin Wolf <kwolf@redhat.com>
Message-Id: <1488317230-26248-9-git-send-email-armbru@redhat.com>
上级 e3934b42
......@@ -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);
......
......@@ -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);
......
......@@ -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. */
......
......@@ -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) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册