From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NfIF2-0001pP-FB for qemu-devel@nongnu.org; Wed, 10 Feb 2010 14:28:52 -0500 Received: from [199.232.76.173] (port=34081 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NfIF1-0001p3-Pr for qemu-devel@nongnu.org; Wed, 10 Feb 2010 14:28:51 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NfIEz-0005KE-Ti for qemu-devel@nongnu.org; Wed, 10 Feb 2010 14:28:51 -0500 Received: from mail-iw0-f194.google.com ([209.85.223.194]:55466) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NfIEz-0005Hu-J7 for qemu-devel@nongnu.org; Wed, 10 Feb 2010 14:28:49 -0500 Received: by mail-iw0-f194.google.com with SMTP id 32so636896iwn.14 for ; Wed, 10 Feb 2010 11:28:49 -0800 (PST) Message-ID: <4B7308EA.3080400@codemonkey.ws> Date: Wed, 10 Feb 2010 13:28:42 -0600 From: Anthony Liguori MIME-Version: 1.0 Subject: Re: [PATCH] JSON: add %I64d support (Was: Re: [Qemu-devel] system_reset command cause assert failed) References: <473191351002031830w7876c367vf534508e292c4f04@mail.gmail.com> In-Reply-To: <473191351002031830w7876c367vf534508e292c4f04@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Roy Tam Cc: qemu-devel , Luiz Capitulino On 02/03/2010 08:30 PM, Roy Tam wrote: > 2010/2/4 Roy Tam: > >> 2010/2/3 Luiz Capitulino: >> > OK we are fooled by the json lexer and parser. As we use %I64d to > print 'long long' variables in Win32, but lexer and parser only deal > with %lld but not %I64d, this patch add support for %I64d and solve > 'info pci', 'powser_reset' and 'power_powerdown' assert failure in > Win32. > > P.S.: an assert(state.result != NULL) statement in > qobject_from_jsonv() will be good for asserting failure of parsing > JSON strings. > Applied. Thanks. Regards, Anthony Liguori > diff --git a/json-lexer.c b/json-lexer.c > index 53697c5..9d64920 100644 > --- a/json-lexer.c > +++ b/json-lexer.c > @@ -54,6 +54,9 @@ enum json_lexer_state { > IN_ESCAPE, > IN_ESCAPE_L, > IN_ESCAPE_LL, > + IN_ESCAPE_I, > + IN_ESCAPE_I6, > + IN_ESCAPE_I64, > IN_ESCAPE_DONE, > IN_WHITESPACE, > IN_OPERATOR_DONE, > @@ -223,6 +226,18 @@ static const uint8_t json_lexer[][256] = { > ['l'] = IN_ESCAPE_LL, > }, > > + [IN_ESCAPE_I64] = { > + ['d'] = IN_ESCAPE_DONE, > + }, > + > + [IN_ESCAPE_I6] = { > + ['4'] = IN_ESCAPE_I64, > + }, > + > + [IN_ESCAPE_I] = { > + ['6'] = IN_ESCAPE_I6, > + }, > + > [IN_ESCAPE] = { > ['d'] = IN_ESCAPE_DONE, > ['i'] = IN_ESCAPE_DONE, > @@ -230,6 +245,7 @@ static const uint8_t json_lexer[][256] = { > ['s'] = IN_ESCAPE_DONE, > ['f'] = IN_ESCAPE_DONE, > ['l'] = IN_ESCAPE_L, > + ['I'] = IN_ESCAPE_I, > }, > > /* top level rule */ > diff --git a/json-parser.c b/json-parser.c > index e04932f..40a5d15 100644 > --- a/json-parser.c > +++ b/json-parser.c > @@ -474,7 +474,7 @@ static QObject *parse_escape(JSONParserContext > *ctxt, QList **tokens, va_list *a > obj = QOBJECT(qint_from_int(va_arg(*ap, int))); > } else if (token_is_escape(token, "%ld")) { > obj = QOBJECT(qint_from_int(va_arg(*ap, long))); > - } else if (token_is_escape(token, "%lld")) { > + } else if (token_is_escape(token, "%lld") || > token_is_escape(token, "%I64d")) { > obj = QOBJECT(qint_from_int(va_arg(*ap, long long))); > } else if (token_is_escape(token, "%s")) { > obj = QOBJECT(qstring_from_str(va_arg(*ap, const char *))); > > > >