From nobody Wed Nov 5 10:30:09 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1535045247217123.33451968292093; Thu, 23 Aug 2018 10:27:27 -0700 (PDT) Received: from localhost ([::1]:37954 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fstOH-0008G1-De for importer@patchew.org; Thu, 23 Aug 2018 13:27:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35554) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fsskS-0000Vx-Ax for qemu-devel@nongnu.org; Thu, 23 Aug 2018 12:46:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fsskL-0006LP-Er for qemu-devel@nongnu.org; Thu, 23 Aug 2018 12:46:12 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:45000 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 1fsskL-0006KQ-4Y for qemu-devel@nongnu.org; Thu, 23 Aug 2018 12:46:09 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B2DA940216E9; Thu, 23 Aug 2018 16:46:08 +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 6F2DBA9EF6; Thu, 23 Aug 2018 16:46:08 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 87680110E364; Thu, 23 Aug 2018 18:40:26 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 23 Aug 2018 18:40:17 +0200 Message-Id: <20180823164025.12553-51-armbru@redhat.com> In-Reply-To: <20180823164025.12553-1-armbru@redhat.com> References: <20180823164025.12553-1-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 23 Aug 2018 16:46:08 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 23 Aug 2018 16:46:08 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.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] [PATCH v3 50/58] json: Unbox tokens queue in JSONMessageParser 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: marcandre.lureau@redhat.com, mdroth@linux.vnet.ibm.com 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" Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- include/qapi/qmp/json-streamer.h | 2 +- qobject/json-parser.c | 1 - qobject/json-streamer.c | 30 +++++++++++------------------- 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/include/qapi/qmp/json-streamer.h b/include/qapi/qmp/json-strea= mer.h index e162fd01da..d1d7fe2595 100644 --- a/include/qapi/qmp/json-streamer.h +++ b/include/qapi/qmp/json-streamer.h @@ -31,7 +31,7 @@ typedef struct JSONMessageParser JSONLexer lexer; int brace_count; int bracket_count; - GQueue *tokens; + GQueue tokens; uint64_t token_size; } JSONMessageParser; =20 diff --git a/qobject/json-parser.c b/qobject/json-parser.c index 685e9dac24..e9a9f937f3 100644 --- a/qobject/json-parser.c +++ b/qobject/json-parser.c @@ -552,7 +552,6 @@ QObject *json_parser_parse(GQueue *tokens, va_list *ap,= Error **errp) parser_context_pop_token(&ctxt); } g_free(ctxt.current); - g_queue_free(ctxt.buf); =20 return result; } diff --git a/qobject/json-streamer.c b/qobject/json-streamer.c index 954bf9d468..9210281a65 100644 --- a/qobject/json-streamer.c +++ b/qobject/json-streamer.c @@ -22,17 +22,12 @@ #define MAX_TOKEN_COUNT (2ULL << 20) #define MAX_NESTING (1 << 10) =20 -static void json_message_free_token(void *token, void *opaque) -{ - g_free(token); -} - static void json_message_free_tokens(JSONMessageParser *parser) { - if (parser->tokens) { - g_queue_foreach(parser->tokens, json_message_free_token, NULL); - g_queue_free(parser->tokens); - parser->tokens =3D NULL; + JSONToken *token; + + while ((token =3D g_queue_pop_head(&parser->tokens))) { + g_free(token); } } =20 @@ -61,11 +56,10 @@ void json_message_process_token(JSONLexer *lexer, GStri= ng *input, error_setg(&err, "JSON parse error, stray '%s'", input->str); goto out_emit; case JSON_END_OF_INPUT: - if (g_queue_is_empty(parser->tokens)) { + if (g_queue_is_empty(&parser->tokens)) { return; } - json =3D json_parser_parse(parser->tokens, parser->ap, &err); - parser->tokens =3D NULL; + json =3D json_parser_parse(&parser->tokens, parser->ap, &err); goto out_emit; default: break; @@ -79,7 +73,7 @@ void json_message_process_token(JSONLexer *lexer, GString= *input, error_setg(&err, "JSON token size limit exceeded"); goto out_emit; } - if (g_queue_get_length(parser->tokens) + 1 > MAX_TOKEN_COUNT) { + if (g_queue_get_length(&parser->tokens) + 1 > MAX_TOKEN_COUNT) { error_setg(&err, "JSON token count limit exceeded"); goto out_emit; } @@ -97,21 +91,19 @@ void json_message_process_token(JSONLexer *lexer, GStri= ng *input, =20 parser->token_size +=3D input->len; =20 - g_queue_push_tail(parser->tokens, token); + g_queue_push_tail(&parser->tokens, token); =20 if ((parser->brace_count > 0 || parser->bracket_count > 0) && parser->bracket_count >=3D 0 && parser->bracket_count >=3D 0) { return; } =20 - json =3D json_parser_parse(parser->tokens, parser->ap, &err); - parser->tokens =3D NULL; + json =3D json_parser_parse(&parser->tokens, parser->ap, &err); =20 out_emit: parser->brace_count =3D 0; parser->bracket_count =3D 0; json_message_free_tokens(parser); - parser->tokens =3D g_queue_new(); parser->token_size =3D 0; parser->emit(parser->opaque, json, err); } @@ -126,7 +118,7 @@ void json_message_parser_init(JSONMessageParser *parser, parser->ap =3D ap; parser->brace_count =3D 0; parser->bracket_count =3D 0; - parser->tokens =3D g_queue_new(); + g_queue_init(&parser->tokens); parser->token_size =3D 0; =20 json_lexer_init(&parser->lexer, !!ap); @@ -141,7 +133,7 @@ void json_message_parser_feed(JSONMessageParser *parser, void json_message_parser_flush(JSONMessageParser *parser) { json_lexer_flush(&parser->lexer); - assert(g_queue_is_empty(parser->tokens)); + assert(g_queue_is_empty(&parser->tokens)); } =20 void json_message_parser_destroy(JSONMessageParser *parser) --=20 2.17.1