[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 2/4] qjson: do not save/restore contexts
From: |
Eric Blake |
Subject: |
Re: [Qemu-devel] [PATCH 2/4] qjson: do not save/restore contexts |
Date: |
Fri, 20 Nov 2015 11:28:09 -0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 |
On 11/20/2015 02:04 AM, Paolo Bonzini wrote:
> JSON is LL(1) and our parser indeed needs only 1 token lookahead.
> Saving the parser context is mostly unnecessary; we can replace it
> with peeking at the next token, or remove it altogether when the
> restore only happens on errors. The token list is destroyed anyway
> on errors.
>
> The only interesting thing is that parse_keyword always eats
> a TOKEN_KEYWORD, even if it is invalid, so it must come last in
> parse_value (otherwise, NULL is returned, parse_literal is invoked
> and it tries to peek beyond end of input). This is caught by
> /errors/unterminated/literal, which actually checks for an unterminated
> keyword. ಠ_ಠ
>
> Signed-off-by: Paolo Bonzini <address@hidden>
> ---
> qobject/json-parser.c | 59
> ++++++++++++++++++---------------------------------
> 1 file changed, 21 insertions(+), 38 deletions(-)
>
> @@ -578,17 +556,21 @@ out:
> static QObject *parse_escape(JSONParserContext *ctxt, va_list *ap)
> {
> QObject *token = NULL, *obj;
> - JSONParserContext saved_ctxt = parser_context_save(ctxt);
>
> if (ap == NULL) {
> goto out;
> }
>
> - token = parser_context_pop_token(ctxt);
> + token = parser_context_peek_token(ctxt);
> if (token == NULL) {
> goto out;
> }
>
> + if (token_get_type(token) != JSON_ESCAPE) {
> + goto out;
> + }
Could merge these two conditionals.
Otherwise, makes sense to me, and a lot less complicated.
Reviewed-by: Eric Blake <address@hidden>
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
- [Qemu-devel] [PATCH 0/4] qjson: save a lot of memory, Paolo Bonzini, 2015/11/20
- [Qemu-devel] [PATCH 2/4] qjson: do not save/restore contexts, Paolo Bonzini, 2015/11/20
- Re: [Qemu-devel] [PATCH 2/4] qjson: do not save/restore contexts,
Eric Blake <=
- [Qemu-devel] [PATCH 3/4] qjson: store tokens in a GQueue, Paolo Bonzini, 2015/11/20
- [Qemu-devel] [PATCH 1/4] qjson: replace QString in JSONLexer with GString, Paolo Bonzini, 2015/11/20
- [Qemu-devel] [PATCH 4/4] qjson: surprise, allocating 6 QObjects per token is expensive, Paolo Bonzini, 2015/11/20