[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 3/9] tests: Avoid qobject_from_jsonf("%"PRId64)
From: |
Markus Armbruster |
Subject: |
[Qemu-devel] [PULL 3/9] tests: Avoid qobject_from_jsonf("%"PRId64) |
Date: |
Mon, 5 Dec 2016 17:45:07 +0100 |
From: Eric Blake <address@hidden>
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 <address@hidden>
Signed-off-by: Eric Blake <address@hidden>
Message-Id: <address@hidden>
Reviewed-by: Markus Armbruster <address@hidden>
[Rename value64 to value_ll]
Signed-off-by: Markus Armbruster <address@hidden>
---
tests/check-qjson.c | 6 +++---
tests/test-qobject-input-visitor.c | 5 +++--
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/tests/check-qjson.c b/tests/check-qjson.c
index 8595574..0b21a22 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 value_ll = 0x2342342343LL;
double valuef = 2.323423423;
obj = qobject_from_jsonf("%d", value);
@@ -976,12 +976,12 @@ static void vararg_number(void)
QDECREF(qint);
- obj = qobject_from_jsonf("%" PRId64, value64);
+ obj = qobject_from_jsonf("%lld", value_ll);
g_assert(obj != NULL);
g_assert(qobject_type(obj) == QTYPE_QINT);
qint = qobject_to_qint(obj);
- g_assert(qint_get_int(qint) == value64);
+ g_assert(qint_get_int(qint) == value_ll);
QDECREF(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);
--
2.5.5
- [Qemu-devel] [PULL 0/9] QAPI patches for 2016-12-05, Markus Armbruster, 2016/12/05
- [Qemu-devel] [PULL 5/9] qapi: fix schema symbol sections, Markus Armbruster, 2016/12/05
- [Qemu-devel] [PULL 6/9] qapi: fix missing symbol @prefix, Markus Armbruster, 2016/12/05
- [Qemu-devel] [PULL 3/9] tests: Avoid qobject_from_jsonf("%"PRId64),
Markus Armbruster <=
- [Qemu-devel] [PULL 8/9] qapi: use one symbol per line, Markus Armbruster, 2016/12/05
- [Qemu-devel] [PULL 4/9] qga/schema: fix double-return in doc, Markus Armbruster, 2016/12/05
- [Qemu-devel] [PULL 2/9] test-qga: Avoid qobject_from_jsonv("%"PRId64), Markus Armbruster, 2016/12/05
- [Qemu-devel] [PULL 7/9] qapi: fix various symbols mismatch in documentation, Markus Armbruster, 2016/12/05
- [Qemu-devel] [PULL 1/9] qmp-event: Avoid qobject_from_jsonf("%"PRId64), Markus Armbruster, 2016/12/05
- [Qemu-devel] [PULL 9/9] qapi: add missing colon-ending for section name, Markus Armbruster, 2016/12/05
- Re: [Qemu-devel] [PULL 0/9] QAPI patches for 2016-12-05, Stefan Hajnoczi, 2016/12/06