From patchwork Tue Nov 17 19:43:48 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 38690 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id AEA50B6F1A for ; Wed, 18 Nov 2009 10:34:22 +1100 (EST) Received: from localhost ([127.0.0.1]:56249 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NAU1r-0000DU-0V for incoming@patchwork.ozlabs.org; Tue, 17 Nov 2009 14:47:55 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NATyH-0004mL-0C for qemu-devel@nongnu.org; Tue, 17 Nov 2009 14:44:13 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NATyC-0004hW-Rm for qemu-devel@nongnu.org; Tue, 17 Nov 2009 14:44:12 -0500 Received: from [199.232.76.173] (port=51039 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NATyC-0004h0-JQ for qemu-devel@nongnu.org; Tue, 17 Nov 2009 14:44:08 -0500 Received: from mx1.redhat.com ([209.132.183.28]:12922) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NATyC-0000kQ-2h for qemu-devel@nongnu.org; Tue, 17 Nov 2009 14:44:08 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nAHJi7pk012575 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 17 Nov 2009 14:44:07 -0500 Received: from localhost (vpn-11-203.rdu.redhat.com [10.11.11.203]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nAHJi5VA010468; Tue, 17 Nov 2009 14:44:06 -0500 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Tue, 17 Nov 2009 17:43:48 -0200 Message-Id: <1258487037-24950-2-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1258487037-24950-1-git-send-email-lcapitulino@redhat.com> References: <1258487037-24950-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: aliguori@us.ibm.com, armbru@redhat.com, kraxel@redhat.com Subject: [Qemu-devel] [PATCH 01/10] QJSON: Introduce qobject_from_jsonv() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org It accepts a va_list and will be used by QError. Also simplifies the code a little, as the other qobject_from_() functions can use it. Signed-off-by: Luiz Capitulino --- qjson.c | 21 +++++++++++---------- qjson.h | 2 ++ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/qjson.c b/qjson.c index 7270909..12e6cf0 100644 --- a/qjson.c +++ b/qjson.c @@ -34,10 +34,12 @@ static void parse_json(JSONMessageParser *parser, QList *tokens) s->result = json_parser_parse(tokens, s->ap); } -QObject *qobject_from_json(const char *string) +QObject *qobject_from_jsonv(const char *string, va_list *ap) { JSONParsingState state = {}; + state.ap = ap; + json_message_parser_init(&state.parser, parse_json); json_message_parser_feed(&state.parser, string, strlen(string)); json_message_parser_flush(&state.parser); @@ -46,22 +48,21 @@ QObject *qobject_from_json(const char *string) return state.result; } +QObject *qobject_from_json(const char *string) +{ + return qobject_from_jsonv(string, NULL); +} + QObject *qobject_from_jsonf(const char *string, ...) { - JSONParsingState state = {}; + QObject *obj; va_list ap; va_start(ap, string); - state.ap = ≈ - - json_message_parser_init(&state.parser, parse_json); - json_message_parser_feed(&state.parser, string, strlen(string)); - json_message_parser_flush(&state.parser); - json_message_parser_destroy(&state.parser); - + obj = qobject_from_jsonv(string, &ap); va_end(ap); - return state.result; + return obj; } typedef struct ToJsonIterState diff --git a/qjson.h b/qjson.h index 7fce742..7afec2e 100644 --- a/qjson.h +++ b/qjson.h @@ -14,12 +14,14 @@ #ifndef QJSON_H #define QJSON_H +#include #include "qobject.h" #include "qstring.h" QObject *qobject_from_json(const char *string); QObject *qobject_from_jsonf(const char *string, ...) __attribute__((__format__ (__printf__, 1, 2))); +QObject *qobject_from_jsonv(const char *string, va_list *ap); QString *qobject_to_json(const QObject *obj);