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 these two conversions, the open-coded QObject creation is a bit more verbose, but performs slightly faster than going through a parse; futhermore, there is no correpsonding QAPI C type to make for an easier representation than open-coding. Signed-off-by: Eric Blake <ebl...@redhat.com> --- monitor.c | 10 +++++++--- qapi/qmp-dispatch.c | 8 +++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/monitor.c b/monitor.c index 2a877ef..f86a855 100644 --- a/monitor.c +++ b/monitor.c @@ -3839,11 +3839,15 @@ void monitor_resume(Monitor *mon) static QObject *get_qmp_greeting(void) { QObject *ver = NULL; + QDict *sub, *ret; qmp_marshal_query_version(NULL, &ver, NULL); - - return qobject_from_jsonf("{'QMP': {'version': %p, 'capabilities': []}}", - ver); + sub = qdict_new(); + qdict_put_obj(sub, "version", ver); + qdict_put(sub, "capabilities", qlist_new()); + ret = qdict_new(); + qdict_put(ret, "QMP", sub); + return QOBJECT(ret); } static void monitor_qmp_event(void *opaque, int event) diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index 505eb41..483ea68 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -111,9 +111,11 @@ static QObject *do_qmp_dispatch(QObject *request, Error **errp) QObject *qmp_build_error_object(Error *err) { - return qobject_from_jsonf("{ 'class': %s, 'desc': %s }", - QapiErrorClass_lookup[error_get_class(err)], - error_get_pretty(err)); + QDict *ret = qdict_new(); + + qdict_put_str(ret, "class", QapiErrorClass_lookup[error_get_class(err)]); + qdict_put_str(ret, "desc", error_get_pretty(err)); + return QOBJECT(ret); } QObject *qmp_dispatch(QObject *request) -- 2.7.4