From: Markus Armbruster <armbru@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [PATCH v3 3/7] json-streamer: reuse parser
Date: Mon, 15 Jun 2026 09:56:07 +0200 [thread overview]
Message-ID: <87fr2os0dk.fsf@pond.sub.org> (raw)
In-Reply-To: <20260525150503.393743-4-pbonzini@redhat.com> (Paolo Bonzini's message of "Mon, 25 May 2026 17:04:59 +0200")
Paolo Bonzini <pbonzini@redhat.com> writes:
> The push parser can be reset, so reuse it when the json-streamer
> detects a completed toplevel object.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> include/qobject/json-parser.h | 2 +-
> qobject/json-streamer.c | 11 ++++-------
> 2 files changed, 5 insertions(+), 8 deletions(-)
>
> diff --git a/include/qobject/json-parser.h b/include/qobject/json-parser.h
> index 05346fa816b..4c3d89f751f 100644
> --- a/include/qobject/json-parser.h
> +++ b/include/qobject/json-parser.h
> @@ -29,8 +29,8 @@ typedef struct JSONParserContext {
> typedef struct JSONMessageParser {
> void (*emit)(void *opaque, QObject *json, Error *err);
> void *opaque;
> - va_list *ap;
> JSONLexer lexer;
> + JSONParserContext parser;
> int brace_count;
> int bracket_count;
> GQueue tokens;
> diff --git a/qobject/json-streamer.c b/qobject/json-streamer.c
> index 6c93e6fd78d..f3dfdcaea12 100644
> --- a/qobject/json-streamer.c
> +++ b/qobject/json-streamer.c
> @@ -32,7 +32,6 @@ void json_message_process_token(JSONLexer *lexer, GString *input,
> JSONTokenType type, int x, int y)
> {
> JSONMessageParser *parser = container_of(lexer, JSONMessageParser, lexer);
> - JSONParserContext ctxt;
> QObject *json = NULL;
> Error *err = NULL;
> JSONToken *token;
> @@ -90,26 +89,23 @@ void json_message_process_token(JSONLexer *lexer, GString *input,
> return;
> }
>
> - json_parser_init(&ctxt, parser->ap);
> -
> /* Process all tokens in the queue */
> while (!g_queue_is_empty(&parser->tokens)) {
> token = g_queue_pop_head(&parser->tokens);
> - json = json_parser_feed(&ctxt, token, &err);
> + json = json_parser_feed(&parser->parser, token, &err);
> g_free(token);
> if (json || err) {
> break;
> }
> }
>
> - json_parser_destroy(&ctxt);
> -
> out_emit:
> parser->brace_count = 0;
> parser->bracket_count = 0;
> json_message_free_tokens(parser);
> parser->token_size = 0;
> parser->emit(parser->opaque, json, err);
> + json_parser_reset(&parser->parser);
> }
This made me stop and think.
I figure the more obvious *delta* would be to json_parser_reset() right
where json_parser_destroy() was.
But putting it here makes the code more obviously correct, I think.
No objection. A hint in the commit message could've saved me a minute
or two.
>
> void json_message_parser_init(JSONMessageParser *parser,
> @@ -119,12 +115,12 @@ void json_message_parser_init(JSONMessageParser *parser,
> {
> parser->emit = emit;
> parser->opaque = opaque;
> - parser->ap = ap;
> parser->brace_count = 0;
> parser->bracket_count = 0;
> g_queue_init(&parser->tokens);
> parser->token_size = 0;
>
> + json_parser_init(&parser->parser, ap);
> json_lexer_init(&parser->lexer, !!ap);
> }
>
> @@ -144,4 +140,5 @@ void json_message_parser_destroy(JSONMessageParser *parser)
> {
> json_lexer_destroy(&parser->lexer);
> json_message_free_tokens(parser);
> + json_parser_destroy(&parser->parser);
> }
Reviewed-by: Markus Armbruster <armbru@redhat.com>
next prev parent reply other threads:[~2026-06-15 7:56 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-25 15:04 [PATCH v3 0/7] qobject: switch JSON parser to push Paolo Bonzini
2026-05-25 15:04 ` [PATCH v3 1/7] json-parser: constify JSONToken Paolo Bonzini
2026-05-25 15:04 ` [PATCH v3 2/7] json-parser: replace with a push parser Paolo Bonzini
2026-06-12 14:21 ` Markus Armbruster
2026-06-12 15:08 ` Paolo Bonzini
2026-06-15 7:48 ` Markus Armbruster
2026-06-15 11:06 ` Markus Armbruster
2026-06-15 12:23 ` Markus Armbruster
2026-05-25 15:04 ` [PATCH v3 3/7] json-streamer: reuse parser Paolo Bonzini
2026-06-15 7:56 ` Markus Armbruster [this message]
2026-05-25 15:05 ` [PATCH v3 4/7] json-streamer: make brace/bracket count unsigned Paolo Bonzini
2026-06-15 8:11 ` Markus Armbruster
2026-05-25 15:05 ` [PATCH v3 5/7] json-streamer: remove token queue Paolo Bonzini
2026-06-15 10:58 ` Markus Armbruster
2026-06-15 13:33 ` Paolo Bonzini
2026-06-15 12:29 ` Markus Armbruster
2026-06-15 13:22 ` Paolo Bonzini
2026-05-25 15:05 ` [PATCH v3 6/7] json-streamer: do not heap-allocate JSONToken Paolo Bonzini
2026-05-25 15:05 ` [PATCH v3 7/7] json-parser: add location to JSON parsing errors Paolo Bonzini
2026-06-15 11:35 ` Markus Armbruster
2026-06-15 13:22 ` Paolo Bonzini
2026-06-02 8:58 ` [PATCH v3 0/7] qobject: switch JSON parser to push Paolo Bonzini
2026-06-15 17:01 ` Markus Armbruster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87fr2os0dk.fsf@pond.sub.org \
--to=armbru@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.