qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 27/36] qtest: Avoid dynamic JSON in qmp_cmd()


From: Eric Blake
Subject: [Qemu-devel] [PATCH 27/36] qtest: Avoid dynamic JSON in qmp_cmd()
Date: Wed, 30 Nov 2016 13:44:45 -0600

When qmp_cmd() was first added, we used a shortcut of a format
string of "%p" to pass the QObject intact through the varargs.
But now that we have a way to directly invoke strings, we can
altogether avoid the no-op trip through the parser by just
flattening to a string ourselves.

Signed-off-by: Eric Blake <address@hidden>
---
 tests/libqtest.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/tests/libqtest.c b/tests/libqtest.c
index ba329c0..22bf0ad 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -493,13 +493,22 @@ QDict *qtest_qmp(QTestState *s, const char *fmt, ...)
 QDict *qtest_qmp_cmd(QTestState *s, const char *cmd, QDict *args)
 {
     QDict *dict = qdict_new();
+    QString *qstr;
+    QDict *result;

     if (!args) {
         args = qdict_new();
     }
     qdict_put_str(dict, "execute", cmd);
     qdict_put(dict, "arguments", args);
-    return qtest_qmp(s, "%p", QOBJECT(dict));
+    qstr = qobject_to_json(QOBJECT(dict));
+
+    qmp_fd_send(s->qmp_fd, qstring_get_str(qstr));
+    result = qtest_qmp_receive(s);
+
+    QDECREF(dict);
+    QDECREF(qstr);
+    return result;
 }

 void qtest_qmp_discard_response(QTestState *s, const char *json)
-- 
2.7.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]