Received: from eggs.gnu.org ([2001:4830:134:3::10]:36424) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c9rp0-0000Sv-4q for qemu-devel@nongnu.org; Thu, 24 Nov 2016 06:04:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c9row-00053y-2S for qemu-devel@nongnu.org; Thu, 24 Nov 2016 06:04:06 -0500 Received: from mx1.redhat.com ([209.132.183.28]:32954) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c9rov-00053A-R1 for qemu-devel@nongnu.org; Thu, 24 Nov 2016 06:04:02 -0500 From: Markus Armbruster References: <1479922617-4400-1-git-send-email-eblake@redhat.com> <1479922617-4400-4-git-send-email-eblake@redhat.com> Date: Thu, 24 Nov 2016 12:03:58 +0100 In-Reply-To: <1479922617-4400-4-git-send-email-eblake@redhat.com> (Eric Blake's message of "Wed, 23 Nov 2016 11:36:56 -0600") Message-ID: <87twaxi1gh.fsf@dusky.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH v2 3/4] tests: Avoid qobject_from_jsonf("%"PRId64) List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: qemu-devel@nongnu.org, Michael Roth , programmingkidx@gmail.com, pbonzini@redhat.com Eric Blake writes: > The qobject_from_jsonf() function implements a pseudo-printf > language for creating a QObject; however, it is hard-coded to > only parse a subset of formats understood by -Wformat, and is > not a straight synonym to bare printf(). In particular, any > use of an int64_t integer works only if the system's > definition of PRId64 matches what the parser expects; which > works on glibc (%lld or %ld depending on 32- vs. 64-bit) and > mingw (%I64d), but not on Mac OS (%qd). Rather than enhance > the parser, it is just as easy to force the use of int (where > the value is small enough) or long long instead of int64_t, > which we know always works. > > This should cover all remaining testsuite uses of > qobject_from_json[fv]() that were trying to rely on PRId64, > although my proof for that was done by adding in asserts and > checking that 'make check' still passed, where such asserts > are inappropriate during hard freeze. A later series in 2.9 > may remove all dynamic JSON parsing, but that's a bigger task. > > Reported by: G 3 > Signed-off-by: Eric Blake > --- > tests/check-qjson.c | 4 ++-- > tests/test-qobject-input-visitor.c | 5 +++-- > 2 files changed, 5 insertions(+), 4 deletions(-) > > diff --git a/tests/check-qjson.c b/tests/check-qjson.c > index 8595574..b03a2e1 100644 > --- a/tests/check-qjson.c > +++ b/tests/check-qjson.c > @@ -964,7 +964,7 @@ static void vararg_number(void) > QInt *qint; > QFloat *qfloat; > int value = 0x2342; > - int64_t value64 = 0x2342342343LL; > + long long value64 = 0x2342342343LL; The name value64 isn't quite right anymore. value_ll? > double valuef = 2.323423423; > > obj = qobject_from_jsonf("%d", value); > @@ -976,7 +976,7 @@ static void vararg_number(void) > > QDECREF(qint); > > - obj = qobject_from_jsonf("%" PRId64, value64); > + obj = qobject_from_jsonf("%lld", value64); > g_assert(obj != NULL); > g_assert(qobject_type(obj) == QTYPE_QINT); > > diff --git a/tests/test-qobject-input-visitor.c b/tests/test-qobject-input-visitor.c > index 26c5012..945404a 100644 > --- a/tests/test-qobject-input-visitor.c > +++ b/tests/test-qobject-input-visitor.c > @@ -83,10 +83,11 @@ static Visitor *visitor_input_test_init_raw(TestInputVisitorData *data, > static void test_visitor_in_int(TestInputVisitorData *data, > const void *unused) > { > - int64_t res = 0, value = -42; > + int64_t res = 0; > + int value = -42; > Visitor *v; > > - v = visitor_input_test_init(data, "%" PRId64, value); > + v = visitor_input_test_init(data, "%d", value); > > visit_type_int(v, NULL, &res, &error_abort); > g_assert_cmpint(res, ==, value);