All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: mdroth@linux.vnet.ibm.com
Subject: [PATCH 03/20] qobject: Make qobject_to_json_pretty() take a pretty argument
Date: Fri, 11 Dec 2020 18:11:35 +0100	[thread overview]
Message-ID: <20201211171152.146877-4-armbru@redhat.com> (raw)
In-Reply-To: <20201211171152.146877-1-armbru@redhat.com>

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 include/qapi/qmp/qjson.h |  2 +-
 monitor/qmp.c            |  2 +-
 qemu-img.c               |  8 ++++----
 qobject/qjson.c          | 28 +++++++++++-----------------
 qom/qom-hmp-cmds.c       |  2 +-
 tests/qtest/libqtest.c   |  2 +-
 6 files changed, 19 insertions(+), 25 deletions(-)

diff --git a/include/qapi/qmp/qjson.h b/include/qapi/qmp/qjson.h
index 5ebbe5a118..82f4534f16 100644
--- a/include/qapi/qmp/qjson.h
+++ b/include/qapi/qmp/qjson.h
@@ -26,6 +26,6 @@ QDict *qdict_from_jsonf_nofail(const char *string, ...)
     GCC_FMT_ATTR(1, 2);
 
 QString *qobject_to_json(const QObject *obj);
-QString *qobject_to_json_pretty(const QObject *obj);
+QString *qobject_to_json_pretty(const QObject *obj, bool pretty);
 
 #endif /* QJSON_H */
diff --git a/monitor/qmp.c b/monitor/qmp.c
index b42f8c6af3..1197c50b20 100644
--- a/monitor/qmp.c
+++ b/monitor/qmp.c
@@ -112,7 +112,7 @@ void qmp_send_response(MonitorQMP *mon, const QDict *rsp)
     const QObject *data = QOBJECT(rsp);
     QString *json;
 
-    json = mon->pretty ? qobject_to_json_pretty(data) : qobject_to_json(data);
+    json = qobject_to_json_pretty(data, mon->pretty);
     assert(json != NULL);
 
     qstring_append_chr(json, '\n');
diff --git a/qemu-img.c b/qemu-img.c
index 8bdea40b58..59ccd4fdd2 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -633,7 +633,7 @@ static void dump_json_image_check(ImageCheck *check, bool quiet)
 
     visit_type_ImageCheck(v, NULL, &check, &error_abort);
     visit_complete(v, &obj);
-    str = qobject_to_json_pretty(obj);
+    str = qobject_to_json_pretty(obj, true);
     assert(str != NULL);
     qprintf(quiet, "%s\n", qstring_get_str(str));
     qobject_unref(obj);
@@ -2796,7 +2796,7 @@ static void dump_json_image_info_list(ImageInfoList *list)
 
     visit_type_ImageInfoList(v, NULL, &list, &error_abort);
     visit_complete(v, &obj);
-    str = qobject_to_json_pretty(obj);
+    str = qobject_to_json_pretty(obj, true);
     assert(str != NULL);
     printf("%s\n", qstring_get_str(str));
     qobject_unref(obj);
@@ -2812,7 +2812,7 @@ static void dump_json_image_info(ImageInfo *info)
 
     visit_type_ImageInfo(v, NULL, &info, &error_abort);
     visit_complete(v, &obj);
-    str = qobject_to_json_pretty(obj);
+    str = qobject_to_json_pretty(obj, true);
     assert(str != NULL);
     printf("%s\n", qstring_get_str(str));
     qobject_unref(obj);
@@ -5243,7 +5243,7 @@ static void dump_json_block_measure_info(BlockMeasureInfo *info)
 
     visit_type_BlockMeasureInfo(v, NULL, &info, &error_abort);
     visit_complete(v, &obj);
-    str = qobject_to_json_pretty(obj);
+    str = qobject_to_json_pretty(obj, true);
     assert(str != NULL);
     printf("%s\n", qstring_get_str(str));
     qobject_unref(obj);
diff --git a/qobject/qjson.c b/qobject/qjson.c
index f1f2c69704..523a4ab8de 100644
--- a/qobject/qjson.c
+++ b/qobject/qjson.c
@@ -149,8 +149,6 @@ QDict *qdict_from_jsonf_nofail(const char *string, ...)
     return qdict;
 }
 
-static void to_json(const QObject *obj, QString *str, int pretty, int indent);
-
 static void json_pretty_newline(QString *str, bool pretty, int indent)
 {
     int i;
@@ -163,7 +161,7 @@ static void json_pretty_newline(QString *str, bool pretty, int indent)
     }
 }
 
-static void to_json(const QObject *obj, QString *str, int pretty, int indent)
+static void to_json(const QObject *obj, QString *str, bool pretty, int indent)
 {
     switch (qobject_type(obj)) {
     case QTYPE_QNULL:
@@ -294,20 +292,16 @@ static void to_json(const QObject *obj, QString *str, int pretty, int indent)
     }
 }
 
+QString *qobject_to_json_pretty(const QObject *obj, bool pretty)
+{
+    QString *str = qstring_new();
+
+    to_json(obj, str, pretty, 0);
+
+    return str;
+}
+
 QString *qobject_to_json(const QObject *obj)
 {
-    QString *str = qstring_new();
-
-    to_json(obj, str, 0, 0);
-
-    return str;
-}
-
-QString *qobject_to_json_pretty(const QObject *obj)
-{
-    QString *str = qstring_new();
-
-    to_json(obj, str, 1, 0);
-
-    return str;
+    return qobject_to_json_pretty(obj, false);
 }
diff --git a/qom/qom-hmp-cmds.c b/qom/qom-hmp-cmds.c
index 8861a109d5..6b96dbe906 100644
--- a/qom/qom-hmp-cmds.c
+++ b/qom/qom-hmp-cmds.c
@@ -78,7 +78,7 @@ void hmp_qom_get(Monitor *mon, const QDict *qdict)
     QObject *obj = qmp_qom_get(path, property, &err);
 
     if (err == NULL) {
-        QString *str = qobject_to_json_pretty(obj);
+        QString *str = qobject_to_json_pretty(obj, true);
         monitor_printf(mon, "%s\n", qstring_get_str(str));
         qobject_unref(str);
     }
diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index e49f3a1e45..213fa4f8fe 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -1197,7 +1197,7 @@ void qtest_qmp_assert_success(QTestState *qts, const char *fmt, ...)
 
     g_assert(response);
     if (!qdict_haskey(response, "return")) {
-        QString *s = qobject_to_json_pretty(QOBJECT(response));
+        QString *s = qobject_to_json_pretty(QOBJECT(response), true);
         g_test_message("%s", qstring_get_str(s));
         qobject_unref(s);
     }
-- 
2.26.2



  parent reply	other threads:[~2020-12-11 17:55 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-11 17:11 [PATCH 00/20] Immutable QString, and also one JSON writer less Markus Armbruster
2020-12-11 17:11 ` [PATCH 01/20] hmp: Simplify how qmp_human_monitor_command() gets output Markus Armbruster
2020-12-16 18:53   ` Dr. David Alan Gilbert
2020-12-11 17:11 ` [PATCH 02/20] monitor: Use GString instead of QString for output buffer Markus Armbruster
2020-12-16 19:36   ` Dr. David Alan Gilbert
2020-12-11 17:11 ` Markus Armbruster [this message]
2020-12-11 17:11 ` [PATCH 04/20] qobject: Use GString instead of QString to accumulate JSON Markus Armbruster
2020-12-11 17:11 ` [PATCH 05/20] qobject: Change qobject_to_json()'s value to GString Markus Armbruster
2021-03-24  7:16   ` Thomas Huth
2021-03-24  8:14     ` Markus Armbruster
2020-12-11 17:11 ` [PATCH 06/20] Revert "qstring: add qstring_free()" Markus Armbruster
2020-12-11 17:11 ` [PATCH 07/20] hw/rdma: Replace QList by GQueue Markus Armbruster
2020-12-11 17:11 ` [PATCH 08/20] qobject: Move internals to qobject-internal.h Markus Armbruster
2020-12-11 17:11 ` [PATCH 09/20] qmp: Fix tracing of non-string command IDs Markus Armbruster
2020-12-11 17:11 ` [PATCH 10/20] block: Avoid qobject_get_try_str() Markus Armbruster
2020-12-11 18:28   ` Vladimir Sementsov-Ogievskiy
2020-12-11 17:11 ` [PATCH 11/20] Revert "qobject: let object_property_get_str() use new API" Markus Armbruster
2020-12-11 19:48   ` Eduardo Habkost
2020-12-11 17:11 ` [PATCH 12/20] qobject: Drop qobject_get_try_str() Markus Armbruster
2020-12-11 17:11 ` [PATCH 13/20] qobject: Drop qstring_get_try_str() Markus Armbruster
2020-12-11 17:11 ` [PATCH 14/20] qobject: Factor quoted_str() out of to_json() Markus Armbruster
2020-12-11 17:11 ` [PATCH 15/20] qobject: Factor JSON writer out of qobject_to_json() Markus Armbruster
2020-12-11 17:11 ` [PATCH 16/20] migration: Replace migration's JSON writer by the general one Markus Armbruster
2020-12-16 19:46   ` Dr. David Alan Gilbert
2020-12-17  7:10     ` Markus Armbruster
2020-12-17  9:38       ` Dr. David Alan Gilbert
2020-12-17 10:32       ` Dr. David Alan Gilbert
2020-12-11 17:11 ` [PATCH 17/20] json: Use GString instead of QString to accumulate strings Markus Armbruster
2020-12-11 17:11 ` [PATCH 18/20] keyval: Use GString to accumulate value strings Markus Armbruster
2020-12-22  9:56   ` Paolo Bonzini
2021-01-11 13:05     ` Markus Armbruster
2021-01-11 13:51       ` Paolo Bonzini
2020-12-11 17:11 ` [PATCH 19/20] block: Use GString instead of QString to build filenames Markus Armbruster
2020-12-11 18:47   ` Vladimir Sementsov-Ogievskiy
2020-12-11 17:11 ` [PATCH 20/20] qobject: Make QString immutable Markus Armbruster
2020-12-22  9:59 ` [PATCH 00/20] Immutable QString, and also one JSON writer less Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201211171152.146877-4-armbru@redhat.com \
    --to=armbru@redhat.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.