From nobody Wed Nov 5 16:42:15 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1535139664748865.8838552294246; Fri, 24 Aug 2018 12:41:04 -0700 (PDT) Received: from localhost ([::1]:43228 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ftHx0-0002Wg-Je for importer@patchew.org; Fri, 24 Aug 2018 15:40:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33161) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ftHoh-0002HO-Js for qemu-devel@nongnu.org; Fri, 24 Aug 2018 15:32:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ftHoe-0001dw-14 for qemu-devel@nongnu.org; Fri, 24 Aug 2018 15:32:19 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:41646 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ftHob-0001a6-Ua for qemu-devel@nongnu.org; Fri, 24 Aug 2018 15:32:14 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B9CFC804BCF4 for ; Fri, 24 Aug 2018 19:32:10 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-97.ams2.redhat.com [10.36.116.97]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 77FE52156714 for ; Fri, 24 Aug 2018 19:32:10 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 43CCB110E7FA; Fri, 24 Aug 2018 21:32:07 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 24 Aug 2018 21:31:41 +0200 Message-Id: <20180824193206.25475-34-armbru@redhat.com> In-Reply-To: <20180824193206.25475-1-armbru@redhat.com> References: <20180824193206.25475-1-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 24 Aug 2018 19:32:10 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 24 Aug 2018 19:32:10 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'armbru@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 33/58] json: Have lexer call streamer directly 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" json_lexer_init() takes the function to process a token as an argument. It's always json_message_process_token(). Makes the code harder to understand for no actual gain. Drop the indirection. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <20180823164025.12553-34-armbru@redhat.com> --- include/qapi/qmp/json-lexer.h | 13 +++---------- include/qapi/qmp/json-streamer.h | 3 +++ qobject/json-lexer.c | 13 ++++++++----- qobject/json-streamer.c | 6 +++--- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/include/qapi/qmp/json-lexer.h b/include/qapi/qmp/json-lexer.h index 66ccf0357c..44bcf2ca64 100644 --- a/include/qapi/qmp/json-lexer.h +++ b/include/qapi/qmp/json-lexer.h @@ -32,20 +32,13 @@ typedef enum json_token_type { JSON_ERROR, } JSONTokenType; =20 -typedef struct JSONLexer JSONLexer; - -typedef void (JSONLexerEmitter)(JSONLexer *, GString *, - JSONTokenType, int x, int y); - -struct JSONLexer -{ - JSONLexerEmitter *emit; +typedef struct JSONLexer { int state; GString *token; int x, y; -}; +} JSONLexer; =20 -void json_lexer_init(JSONLexer *lexer, JSONLexerEmitter func); +void json_lexer_init(JSONLexer *lexer); =20 void json_lexer_feed(JSONLexer *lexer, const char *buffer, size_t size); =20 diff --git a/include/qapi/qmp/json-streamer.h b/include/qapi/qmp/json-strea= mer.h index cb808cf27d..7922e185a5 100644 --- a/include/qapi/qmp/json-streamer.h +++ b/include/qapi/qmp/json-streamer.h @@ -33,6 +33,9 @@ typedef struct JSONMessageParser uint64_t token_size; } JSONMessageParser; =20 +void json_message_process_token(JSONLexer *lexer, GString *input, + JSONTokenType type, int x, int y); + void json_message_parser_init(JSONMessageParser *parser, void (*func)(JSONMessageParser *, GQueue *)); =20 diff --git a/qobject/json-lexer.c b/qobject/json-lexer.c index d9701f857b..17272a3874 100644 --- a/qobject/json-lexer.c +++ b/qobject/json-lexer.c @@ -14,6 +14,7 @@ #include "qemu/osdep.h" #include "qemu-common.h" #include "qapi/qmp/json-lexer.h" +#include "qapi/qmp/json-streamer.h" =20 #define MAX_TOKEN_SIZE (64ULL << 20) =20 @@ -278,9 +279,8 @@ static const uint8_t json_lexer[][256] =3D { }, }; =20 -void json_lexer_init(JSONLexer *lexer, JSONLexerEmitter func) +void json_lexer_init(JSONLexer *lexer) { - lexer->emit =3D func; lexer->state =3D IN_START; lexer->token =3D g_string_sized_new(3); lexer->x =3D lexer->y =3D 0; @@ -316,7 +316,8 @@ static void json_lexer_feed_char(JSONLexer *lexer, char= ch, bool flush) case JSON_FLOAT: case JSON_KEYWORD: case JSON_STRING: - lexer->emit(lexer, lexer->token, new_state, lexer->x, lexer->y= ); + json_message_process_token(lexer, lexer->token, new_state, + lexer->x, lexer->y); /* fall through */ case JSON_SKIP: g_string_truncate(lexer->token, 0); @@ -336,7 +337,8 @@ static void json_lexer_feed_char(JSONLexer *lexer, char= ch, bool flush) * never a valid ASCII/UTF-8 sequence, so this should reliably * induce an error/flush state. */ - lexer->emit(lexer, lexer->token, JSON_ERROR, lexer->x, lexer->= y); + json_message_process_token(lexer, lexer->token, JSON_ERROR, + lexer->x, lexer->y); g_string_truncate(lexer->token, 0); new_state =3D IN_START; lexer->state =3D new_state; @@ -351,7 +353,8 @@ static void json_lexer_feed_char(JSONLexer *lexer, char= ch, bool flush) * this is a security consideration. */ if (lexer->token->len > MAX_TOKEN_SIZE) { - lexer->emit(lexer, lexer->token, lexer->state, lexer->x, lexer->y); + json_message_process_token(lexer, lexer->token, lexer->state, + lexer->x, lexer->y); g_string_truncate(lexer->token, 0); lexer->state =3D IN_START; } diff --git a/qobject/json-streamer.c b/qobject/json-streamer.c index 78dfff2aa0..9f57ebf2bd 100644 --- a/qobject/json-streamer.c +++ b/qobject/json-streamer.c @@ -34,8 +34,8 @@ static void json_message_free_tokens(JSONMessageParser *p= arser) } } =20 -static void json_message_process_token(JSONLexer *lexer, GString *input, - JSONTokenType type, int x, int y) +void json_message_process_token(JSONLexer *lexer, GString *input, + JSONTokenType type, int x, int y) { JSONMessageParser *parser =3D container_of(lexer, JSONMessageParser, l= exer); JSONToken *token; @@ -115,7 +115,7 @@ void json_message_parser_init(JSONMessageParser *parser, parser->tokens =3D g_queue_new(); parser->token_size =3D 0; =20 - json_lexer_init(&parser->lexer, json_message_process_token); + json_lexer_init(&parser->lexer); } =20 void json_message_parser_feed(JSONMessageParser *parser, --=20 2.17.1