Received: from eggs.gnu.org ([2001:4830:134:3::10]:35469) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cCAoi-0003pZ-Sc for qemu-devel@nongnu.org; Wed, 30 Nov 2016 14:45:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cCAoc-0001px-Sd for qemu-devel@nongnu.org; Wed, 30 Nov 2016 14:45:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:14549) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cCAoc-0001pI-MS for qemu-devel@nongnu.org; Wed, 30 Nov 2016 14:45:14 -0500 From: Eric Blake Date: Wed, 30 Nov 2016 13:44:22 -0600 Message-Id: <1480535094-23831-5-git-send-email-eblake@redhat.com> In-Reply-To: <1480535094-23831-1-git-send-email-eblake@redhat.com> References: <1480535094-23831-1-git-send-email-eblake@redhat.com> Subject: [Qemu-devel] [PATCH 04/36] qmp-event: Avoid dynamic JSON List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: armbru@redhat.com, pbonzini@redhat.com, Michael Roth 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 --- 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