From patchwork Mon Feb 27 11:20:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 732758 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vWzvv28ttz9sDC for ; Mon, 27 Feb 2017 22:27:39 +1100 (AEDT) Received: from localhost ([::1]:51800 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciJSq-00041U-Mo for incoming@patchwork.ozlabs.org; Mon, 27 Feb 2017 06:27:36 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44729) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciJMY-00069P-E9 for qemu-devel@nongnu.org; Mon, 27 Feb 2017 06:21:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ciJMT-00010L-2P for qemu-devel@nongnu.org; Mon, 27 Feb 2017 06:21:06 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57622) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ciJMM-0000td-Ka; Mon, 27 Feb 2017 06:20:54 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D1CAD7FB70; Mon, 27 Feb 2017 11:20:54 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-55.ams2.redhat.com [10.36.116.55]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1RBKrkP021120 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 27 Feb 2017 06:20:54 -0500 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 270F611385E1; Mon, 27 Feb 2017 12:20:50 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 27 Feb 2017 12:20:34 +0100 Message-Id: <1488194450-28056-9-git-send-email-armbru@redhat.com> In-Reply-To: <1488194450-28056-1-git-send-email-armbru@redhat.com> References: <1488194450-28056-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 27 Feb 2017 11:20:54 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 08/24] qobject: Propagate parse errors through qobject_from_jsonv() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, "mdroth@linux.vnet.ibm.commdroth"@linux.vnet.ibm.com, pkrempa@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Markus Armbruster Reviewed-by: Kevin Wolf --- 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 02b1f2c..6fe42d0 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 9a0de89..339c9f7 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 cf27afc..683d5e3 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 650637e..44885ee 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) {