JSON: add %I64d support (Was: Re: [Qemu-devel] system_reset command cause assert failed)
PATCH 1/1 JSON: add %I64d support (Was: Re: [Qemu-devel] system_reset command cause assert failed)
2010/2/4 Roy Tam <[email protected]>:
Quoted 1 line
2010/2/3 Luiz Capitulino <[email protected]>:
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.
json-lexer.c +16 -0
@@ -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 */
json-parser.c +0 -0
@@ -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 *)));2010/2/4 Roy Tam <[email protected]>:
Quoted 9 lines
2010/2/4 Roy Tam <[email protected]>:
Quoted 1 line
2010/2/3 Luiz Capitulino <[email protected]>:
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.
Quoted 3 lines
P.S.: an assert(state.result != NULL) statement inqobject_from_jsonv()will be good for asserting failure of parsing JSON strings.
json-lexer.c +16 -0
@@ -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 */
json-parser.c +0 -0
@@ -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 *)));Quoted 8 lines · On Thu, 4 Feb 2010 10:30:30 +0800 Roy Tam <[email protected]> wrote:
2010/2/4 Roy Tam <[email protected]>:
Quoted 1 line
2010/2/3 Luiz Capitulino <[email protected]>:
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.
Hm, I guess this has been suggested before... Anthony?
Quoted 3 lines
P.S.: an assert(state.result != NULL) statement inqobject_from_jsonv()will be good for asserting failure of parsing JSON strings.
Yes, this change is already in a series I plan to send shortly.
Thanks a lot for tracking this down.
2010/2/4 Luiz Capitulino <[email protected]>:
Quoted 6 lines
Quoted 3 lines · On Thu, 4 Feb 2010 10:30:30 +0800 Roy Tam <[email protected]> wrote:
2010/2/4 Roy Tam <[email protected]>:
Quoted 1 line
2010/2/3 Luiz Capitulino <[email protected]>:
Quoted 8 lines
Quoted 5 lines
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.Hm, I guess this has been suggested before... Anthony?
OK I just missed this. And the wheel was reinvented. :-S
http://www.mail-archive.com/[email protected]/msg23983.html
Quoted 8 lines
Quoted 3 lines
P.S.: an assert(state.result != NULL) statement inqobject_from_jsonv()will be good for asserting failure of parsing JSON strings.Yes, this change is already in a series I plan to send shortly.
Thanks a lot for tracking this down.
Quoted 16 lines · Roy Tam
2010/2/4 Luiz Capitulino<[email protected]>:
Quoted 14 lines
Quoted 10 lines · On Thu, 4 Feb 2010 10:30:30 +0800 Roy Tam<[email protected]> wrote:
2010/2/4 Roy Tam<[email protected]>:
Quoted 2 lines
2010/2/3 Luiz Capitulino<[email protected]>:
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.
Quoted 6 lines
Quoted 3 lines
Hm, I guess this has been suggested before... Anthony?
OK I just missed this. And the wheel was reinvented. :-S
http://www.mail-archive.com/[email protected]/msg23983.html
I asked for the json parser changes to be split from the PRId64 changes. It was never resubmitted. I'll apply your patch.
Regards,
Anthony Liguori
Anthony Liguori
AppliedQuoted 10 lines · Roy Tam
2010/2/4 Roy Tam<[email protected]>:
Quoted 2 lines
2010/2/3 Luiz Capitulino<[email protected]>:
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.
Quoted 4 lines
P.S.: an assert(state.result != NULL) statement inqobject_from_jsonv()will be good for asserting failure of parsing JSON strings.
Applied. Thanks.
Regards,
Anthony Liguori
Quoted 60 lines
json-lexer.c +16
-0@@ -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 */ json-parser.c +1
-1@@ -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 *)));