[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 04/36] qmp-event: Avoid dynamic JSON
From: |
Eric Blake |
Subject: |
[Qemu-devel] [PATCH 04/36] qmp-event: Avoid dynamic JSON |
Date: |
Wed, 30 Nov 2016 13:44:22 -0600 |
The qobject_from_jsonf() function implements a pseudo-printf
language for creating a QObject through the extension of dynamic
JSON; however, it is hard-coded to only parse a subset of
formats understood by -Wformat and is not a straight synonym to
bare printf(). During a recent cleanup due to problems caused
by PRId64, it was questioned whether the maintenance burden of
keeping the dynamic JSON extension can be counterbalanced by
converting code to use alternative ways of describing QObject.
For this particular use of dynamic JSON, it is just as simple
to open-code the correct QObject creation.
Signed-off-by: Eric Blake <address@hidden>
---
qapi/qmp-event.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/qapi/qmp-event.c b/qapi/qmp-event.c
index ba3029c..57f54d9 100644
--- a/qapi/qmp-event.c
+++ b/qapi/qmp-event.c
@@ -15,6 +15,8 @@
#include "qemu-common.h"
#include "qapi/qmp-event.h"
+#include "qapi/qmp/qdict.h"
+#include "qapi/qmp/qint.h"
#include "qapi/qmp/qstring.h"
#include "qapi/qmp/qjson.h"
@@ -33,15 +35,16 @@ QMPEventFuncEmit qmp_event_get_func_emit(void)
static void timestamp_put(QDict *qdict)
{
int err;
- QObject *obj;
+ QDict *stamp = qdict_new();
qemu_timeval tv;
err = qemu_gettimeofday(&tv);
/* Put -1 to indicate failure of getting host time */
- obj = qobject_from_jsonf("{ 'seconds': %lld, 'microseconds': %lld }",
- err < 0 ? -1LL : (long long)tv.tv_sec,
- err < 0 ? -1LL : (long long)tv.tv_usec);
- qdict_put_obj(qdict, "timestamp", obj);
+ qdict_put_int(stamp, "seconds",
+ err < 0 ? -1LL : (long long)tv.tv_sec);
+ qdict_put_int(stamp, "microseconds",
+ err < 0 ? -1LL : (long long)tv.tv_usec);
+ qdict_put(qdict, "timestamp", stamp);
}
/*
--
2.7.4
- [Qemu-devel] [PATCH 00/36] Rip out dynamic JSON parsing, Eric Blake, 2016/11/30
- [Qemu-devel] [PATCH 01/36] pci: Use struct instead of QDict to pass back parameters, Eric Blake, 2016/11/30
- [Qemu-devel] [PATCH 03/36] qlist: Add convenience helpers for wrapped appends, Eric Blake, 2016/11/30
- [Qemu-devel] [PATCH 08/36] test-qga: Actually test 0xff sync bytes, Eric Blake, 2016/11/30
- [Qemu-devel] [PATCH 10/36] qtest: Avoid dynamic JSON in libqtest, Eric Blake, 2016/11/30
- [Qemu-devel] [PATCH 09/36] qtest: Add a new helper qmp_cmd() and friends, Eric Blake, 2016/11/30
- [Qemu-devel] [PATCH 06/36] qobject-input-visitor: Avoid dynamic JSON in tests, Eric Blake, 2016/11/30
- [Qemu-devel] [PATCH 04/36] qmp-event: Avoid dynamic JSON,
Eric Blake <=
- [Qemu-devel] [PATCH 05/36] qmp-dispatch: Avoid dynamic JSON, Eric Blake, 2016/11/30
- [Qemu-devel] [PATCH 07/36] fdc-test: Avoid deprecated 'change' command, Eric Blake, 2016/11/30
- [Qemu-devel] [PATCH 22/36] qtest: Avoid dynamic JSON in pc-cpu-test, Eric Blake, 2016/11/30
- [Qemu-devel] [PATCH 12/36] nbd: Use simpler QAPI_TO_QOBJECT(), Eric Blake, 2016/11/30
- [Qemu-devel] [PATCH 11/36] qapi: Add QAPI_TO_QOBJECT() convenience macro, Eric Blake, 2016/11/30
- [Qemu-devel] [PATCH 19/36] qtest: Change qmp_discard_response() to drop varargs, Eric Blake, 2016/11/30
- [Qemu-devel] [PATCH 25/36] qtest: Change qmp_fd_send() to drop varags, Eric Blake, 2016/11/30
- [Qemu-devel] [PATCH 13/36] nfs: Use simpler QAPI_TO_QOBJECT(), Eric Blake, 2016/11/30
- [Qemu-devel] [PATCH 16/36] qapi: Promote blockdev-change-medium arguments to QAPI type, Eric Blake, 2016/11/30