From nobody Mon Feb 9 09:52:58 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608375736; cv=none; d=zohomail.com; s=zohoarc; b=JGE5qIQgelxwhAQ4J95iiZDe+kn+izxYeU4fFCF2SSUolt7AtUFn2Dr09QmhA1lHmghl1AdXQyWQrdsYMtc3vrcoWvCrn5TVmLNnxhND/Ihckg/YxDmxXJpjgHWTSRGzdiC38N6QWUEP4Houcef/ZQBR1QbWZiIJqm8KtmeehEQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608375736; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=CSR8pLDsCVa+LOllTgMzAE5XMpBg9MNk2R2Ap0rd4Jo=; b=D5I4lnzSosT/OKZklBDdWKUhAdvp4kMm+N+pA6iG4FmZ9kvZNHkvbDOSwx7ZB66IMrYs85qYrs7BPdJFSRdNRGE2yf1JTDKEf5RSOy+PqyuMgIXyviLyDS8eiNqoqIGF/cGSTC9wtxJNOcGb2ESJE5E84WUhM2v5iWhnJVS7PgU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1608375736673396.82638151119795; Sat, 19 Dec 2020 03:02:16 -0800 (PST) Received: from localhost ([::1]:58804 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqa07-00053B-Gc for importer@patchew.org; Sat, 19 Dec 2020 06:02:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50690) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqZtq-0004mB-Om for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:46 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:39087) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqZtl-0007GT-1F for qemu-devel@nongnu.org; Sat, 19 Dec 2020 05:55:46 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-68-aW5r6wddOp6QRHQ8_tQa9Q-1; Sat, 19 Dec 2020 05:55:38 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0E47B800D55; Sat, 19 Dec 2020 10:55:37 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AFC6457; Sat, 19 Dec 2020 10:55:36 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 916811126898; Sat, 19 Dec 2020 11:55:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608375340; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CSR8pLDsCVa+LOllTgMzAE5XMpBg9MNk2R2Ap0rd4Jo=; b=hisIbMOskWTx0nwqSxHHR4FptIg5Hp4bPeENfTzZKzrjXcrhLEHb9AwwZcKD/tQgztqLl5 to3mhbcQqzV1Hzfk4D6NfmQOZkwWLgy2JnHnIRKNqQSNg+Y4AnV6RqZAwAzRhH5fhhyyan kF1RFPlP17wLhUiDv6CzEaOlaPjHiNE= X-MC-Unique: aW5r6wddOp6QRHQ8_tQa9Q-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 16/33] qobject: Make qobject_to_json_pretty() take a pretty argument Date: Sat, 19 Dec 2020 11:55:15 +0100 Message-Id: <20201219105532.1734134-17-armbru@redhat.com> In-Reply-To: <20201219105532.1734134-1-armbru@redhat.com> References: <20201219105532.1734134-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Markus Armbruster Message-Id: <20201211171152.146877-4-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); =20 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); =20 #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 *rs= p) const QObject *data =3D QOBJECT(rsp); QString *json; =20 - json =3D mon->pretty ? qobject_to_json_pretty(data) : qobject_to_json(= data); + json =3D qobject_to_json_pretty(data, mon->pretty); assert(json !=3D NULL); =20 qstring_append_chr(json, '\n'); diff --git a/qemu-img.c b/qemu-img.c index d599659c7f..1a59dfd3f3 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -633,7 +633,7 @@ static void dump_json_image_check(ImageCheck *check, bo= ol quiet) =20 visit_type_ImageCheck(v, NULL, &check, &error_abort); visit_complete(v, &obj); - str =3D qobject_to_json_pretty(obj); + str =3D qobject_to_json_pretty(obj, true); assert(str !=3D NULL); qprintf(quiet, "%s\n", qstring_get_str(str)); qobject_unref(obj); @@ -2795,7 +2795,7 @@ static void dump_json_image_info_list(ImageInfoList *= list) =20 visit_type_ImageInfoList(v, NULL, &list, &error_abort); visit_complete(v, &obj); - str =3D qobject_to_json_pretty(obj); + str =3D qobject_to_json_pretty(obj, true); assert(str !=3D NULL); printf("%s\n", qstring_get_str(str)); qobject_unref(obj); @@ -2811,7 +2811,7 @@ static void dump_json_image_info(ImageInfo *info) =20 visit_type_ImageInfo(v, NULL, &info, &error_abort); visit_complete(v, &obj); - str =3D qobject_to_json_pretty(obj); + str =3D qobject_to_json_pretty(obj, true); assert(str !=3D NULL); printf("%s\n", qstring_get_str(str)); qobject_unref(obj); @@ -5242,7 +5242,7 @@ static void dump_json_block_measure_info(BlockMeasure= Info *info) =20 visit_type_BlockMeasureInfo(v, NULL, &info, &error_abort); visit_complete(v, &obj); - str =3D qobject_to_json_pretty(obj); + str =3D qobject_to_json_pretty(obj, true); assert(str !=3D 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; } =20 -static void to_json(const QObject *obj, QString *str, int pretty, int inde= nt); - 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 pret= ty, int indent) } } =20 -static void to_json(const QObject *obj, QString *str, int pretty, int inde= nt) +static void to_json(const QObject *obj, QString *str, bool pretty, int ind= ent) { switch (qobject_type(obj)) { case QTYPE_QNULL: @@ -294,20 +292,16 @@ static void to_json(const QObject *obj, QString *str,= int pretty, int indent) } } =20 +QString *qobject_to_json_pretty(const QObject *obj, bool pretty) +{ + QString *str =3D qstring_new(); + + to_json(obj, str, pretty, 0); + + return str; +} + QString *qobject_to_json(const QObject *obj) { - QString *str =3D qstring_new(); - - to_json(obj, str, 0, 0); - - return str; -} - -QString *qobject_to_json_pretty(const QObject *obj) -{ - QString *str =3D 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 =3D qmp_qom_get(path, property, &err); =20 if (err =3D=3D NULL) { - QString *str =3D qobject_to_json_pretty(obj); + QString *str =3D 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, ...) =20 g_assert(response); if (!qdict_haskey(response, "return")) { - QString *s =3D qobject_to_json_pretty(QOBJECT(response)); + QString *s =3D qobject_to_json_pretty(QOBJECT(response), true); g_test_message("%s", qstring_get_str(s)); qobject_unref(s); } --=20 2.26.2