[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 40/56] json: Replace %I64d, %I64u by %PRId64, %P

From: Eric Blake
Subject: Re: [Qemu-devel] [PATCH 40/56] json: Replace %I64d, %I64u by %PRId64, %PRIu64
Date: Mon, 13 Aug 2018 11:18:48 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0

On 08/08/2018 07:03 AM, Markus Armbruster wrote:
Support for %I64d got addded in commit 2c0d4b36e7f "json: fix PRId64


on Win32".  We had to hard-code I64d because we used the lexer's
finite state machine to check interpolations.  No more, so clean this

Additional conversion specifications would be easy enough to implement
when needed.

Signed-off-by: Markus Armbruster <address@hidden>
  qobject/json-parser.c | 10 ++++++----
  tests/check-qjson.c   | 10 ++++++++++
  2 files changed, 16 insertions(+), 4 deletions(-)

Reviewed-by: Eric Blake <address@hidden>

         return QOBJECT(qnum_from_int(va_arg(*ap, long)));
-    } else if (!strcmp(token->str, "%lld") ||
-               !strcmp(token->str, "%I64d")) {
+    } else if (!strcmp(token->str, "%lld")) {
         return QOBJECT(qnum_from_int(va_arg(*ap, long long)));
+    } else if (!strcmp(token->str, "%" PRId64)) {
+        return QOBJECT(qnum_from_int(va_arg(*ap, int64_t)));

I had a double-take to make sure this still works on mingw. The trick used to be that the lexer had to parse the union of all forms understood by any libc (making Linux understand %I64d even though only mingw would generate it) then the parser had to accept all forms allowed through by the lexer. Now the lexer accepts all forms with no effort (because it is no longer validates), and the parser is made stricter (%I64d no longer works on Linux, where we have two redundant 'if' clauses; but mingw has two distinct 'if' clauses and works as desired).

Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

reply via email to

[Prev in Thread] Current Thread [Next in Thread]