From nobody Sun Apr 28 04:42:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487364824241828.6477999290449; Fri, 17 Feb 2017 12:53:44 -0800 (PST) Received: from localhost ([::1]:55859 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cepXC-0007vg-UY for importer@patchew.org; Fri, 17 Feb 2017 15:53:42 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58978) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cepIU-0002YY-Px for qemu-devel@nongnu.org; Fri, 17 Feb 2017 15:38:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cepIS-0004Ol-5s for qemu-devel@nongnu.org; Fri, 17 Feb 2017 15:38:30 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52836) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cepIR-0004OB-WC for qemu-devel@nongnu.org; Fri, 17 Feb 2017 15:38:28 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0D640C04B924 for ; Fri, 17 Feb 2017 20:38:28 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-50.ams2.redhat.com [10.36.116.50]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1HKcQB5019357 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Fri, 17 Feb 2017 15:38:27 -0500 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 396FE11384AC; Fri, 17 Feb 2017 21:38:25 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 17 Feb 2017 21:38:12 +0100 Message-Id: <1487363905-9480-2-git-send-email-armbru@redhat.com> In-Reply-To: <1487363905-9480-1-git-send-email-armbru@redhat.com> References: <1487363905-9480-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 17 Feb 2017 20:38:28 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 01/14] qdict: Make qdict_get_qlist() safe like qdict_get_qdict() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Commit 89cad9f changed qdict_get_qdict() to return NULL instead of crash when the key doesn't exist or its value isn't a QDict. Commit 2d6421a neglected to do the same for qdict_get_qlist(). Correct that, and update the function comments. qdict_get_obj() is now unused, remove. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- qobject/qdict.c | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/qobject/qdict.c b/qobject/qdict.c index 197b0fb..b0c5364 100644 --- a/qobject/qdict.c +++ b/qobject/qdict.c @@ -178,20 +178,6 @@ size_t qdict_size(const QDict *qdict) } =20 /** - * qdict_get_obj(): Get a QObject of a specific type - */ -static QObject *qdict_get_obj(const QDict *qdict, const char *key, QType t= ype) -{ - QObject *obj; - - obj =3D qdict_get(qdict, key); - assert(obj !=3D NULL); - assert(qobject_type(obj) =3D=3D type); - - return obj; -} - -/** * qdict_get_double(): Get an number mapped by 'key' * * This function assumes that 'key' exists and it stores a @@ -241,25 +227,15 @@ bool qdict_get_bool(const QDict *qdict, const char *k= ey) } =20 /** - * qdict_get_qlist(): Get the QList mapped by 'key' - * - * This function assumes that 'key' exists and it stores a - * QList object. - * - * Return QList mapped by 'key'. + * qdict_get_qlist(): If @qdict maps @key to a QList, return it, else NULL. */ QList *qdict_get_qlist(const QDict *qdict, const char *key) { - return qobject_to_qlist(qdict_get_obj(qdict, key, QTYPE_QLIST)); + return qobject_to_qlist(qdict_get(qdict, key)); } =20 /** - * qdict_get_qdict(): Get the QDict mapped by 'key' - * - * This function assumes that 'key' exists and it stores a - * QDict object. - * - * Return QDict mapped by 'key'. + * qdict_get_qdict(): If @qdict maps @key to a QDict, return it, else NULL. */ QDict *qdict_get_qdict(const QDict *qdict, const char *key) { --=20 2.7.4 From nobody Sun Apr 28 04:42:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487364557109752.8697585580268; Fri, 17 Feb 2017 12:49:17 -0800 (PST) Received: from localhost ([::1]:55837 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cepSs-00044x-Qe for importer@patchew.org; Fri, 17 Feb 2017 15:49:14 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58975) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cepIU-0002YU-Od for qemu-devel@nongnu.org; Fri, 17 Feb 2017 15:38:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cepIS-0004OX-5E for qemu-devel@nongnu.org; Fri, 17 Feb 2017 15:38:30 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52520) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cepIR-0004OC-Vc for qemu-devel@nongnu.org; Fri, 17 Feb 2017 15:38:28 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0E97F81241 for ; Fri, 17 Feb 2017 20:38:28 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-50.ams2.redhat.com [10.36.116.50]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1HKcQ68007984 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Fri, 17 Feb 2017 15:38:27 -0500 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 3CA4511384AE; Fri, 17 Feb 2017 21:38:25 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 17 Feb 2017 21:38:13 +0100 Message-Id: <1487363905-9480-3-git-send-email-armbru@redhat.com> In-Reply-To: <1487363905-9480-1-git-send-email-armbru@redhat.com> References: <1487363905-9480-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 17 Feb 2017 20:38:28 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 02/14] check-qdict: Simplify qdict_crumple_test_recursive() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Use qdict_get_qdict(), qdict_get_qlist() instead of qdict_get() followed by qobject_to_qdict(), qobject_to_qlist(). While there, drop some redundant code. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- tests/check-qdict.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/tests/check-qdict.c b/tests/check-qdict.c index 07b1c79..14e942a 100644 --- a/tests/check-qdict.c +++ b/tests/check-qdict.c @@ -591,7 +591,7 @@ static void qdict_join_test(void) static void qdict_crumple_test_recursive(void) { QDict *src, *dst, *rule, *vnc, *acl, *listen; - QObject *child, *res; + QObject *res; QList *rules; =20 src =3D qdict_new(); @@ -613,23 +613,19 @@ static void qdict_crumple_test_recursive(void) =20 g_assert_cmpint(qdict_size(dst), =3D=3D, 1); =20 - child =3D qdict_get(dst, "vnc"); - g_assert_cmpint(qobject_type(child), =3D=3D, QTYPE_QDICT); - vnc =3D qobject_to_qdict(child); + vnc =3D qdict_get_qdict(dst, "vnc"); + g_assert(vnc); =20 - child =3D qdict_get(vnc, "listen"); - g_assert_cmpint(qobject_type(child), =3D=3D, QTYPE_QDICT); - listen =3D qobject_to_qdict(child); + listen =3D qdict_get_qdict(vnc, "listen"); + g_assert(listen); g_assert_cmpstr("127.0.0.1", =3D=3D, qdict_get_str(listen, "addr")); g_assert_cmpstr("5901", =3D=3D, qdict_get_str(listen, "port")); =20 - child =3D qdict_get(vnc, "acl"); - g_assert_cmpint(qobject_type(child), =3D=3D, QTYPE_QDICT); - acl =3D qobject_to_qdict(child); + acl =3D qdict_get_qdict(vnc, "acl"); + g_assert(acl); =20 - child =3D qdict_get(acl, "rules"); - g_assert_cmpint(qobject_type(child), =3D=3D, QTYPE_QLIST); - rules =3D qobject_to_qlist(child); + rules =3D qdict_get_qlist(acl, "rules"); + g_assert(rules); g_assert_cmpint(qlist_size(rules), =3D=3D, 2); =20 rule =3D qobject_to_qdict(qlist_pop(rules)); @@ -646,9 +642,6 @@ static void qdict_crumple_test_recursive(void) =20 /* With recursive crumpling, we should see all names unescaped */ g_assert_cmpstr("acl0", =3D=3D, qdict_get_str(vnc, "acl.name")); - child =3D qdict_get(vnc, "acl"); - g_assert_cmpint(qobject_type(child), =3D=3D, QTYPE_QDICT); - acl =3D qdict_get_qdict(vnc, "acl"); g_assert_cmpstr("acl0", =3D=3D, qdict_get_str(acl, "rule.name")); =20 QDECREF(src); --=20 2.7.4 From nobody Sun Apr 28 04:42:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 14873640281031002.6459103204731; Fri, 17 Feb 2017 12:40:28 -0800 (PST) Received: from localhost ([::1]:55780 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cepKL-0003k8-Qn for importer@patchew.org; Fri, 17 Feb 2017 15:40:25 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58976) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cepIU-0002YW-PI for qemu-devel@nongnu.org; Fri, 17 Feb 2017 15:38:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cepIS-0004OY-4n for qemu-devel@nongnu.org; Fri, 17 Feb 2017 15:38:30 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52522) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cepIR-0004OE-VV for qemu-devel@nongnu.org; Fri, 17 Feb 2017 15:38:28 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 121027FB77 for ; Fri, 17 Feb 2017 20:38:28 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-50.ams2.redhat.com [10.36.116.50]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1HKcQHe018312 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Fri, 17 Feb 2017 15:38:27 -0500 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 3F4F111384AF; Fri, 17 Feb 2017 21:38:25 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 17 Feb 2017 21:38:14 +0100 Message-Id: <1487363905-9480-4-git-send-email-armbru@redhat.com> In-Reply-To: <1487363905-9480-1-git-send-email-armbru@redhat.com> References: <1487363905-9480-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 17 Feb 2017 20:38:28 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 03/14] check-qdict: Tighten qdict_crumple_test_recursive() some X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Consistently check for unexpected QDict entries, and qdict_get_qdict() success. The latter doesn't tighten the test, it only makes it fail more nicely. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- tests/check-qdict.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/check-qdict.c b/tests/check-qdict.c index 14e942a..ded3a26 100644 --- a/tests/check-qdict.c +++ b/tests/check-qdict.c @@ -615,26 +615,31 @@ static void qdict_crumple_test_recursive(void) =20 vnc =3D qdict_get_qdict(dst, "vnc"); g_assert(vnc); + g_assert_cmpint(qdict_size(vnc), =3D=3D, 3); =20 listen =3D qdict_get_qdict(vnc, "listen"); g_assert(listen); + g_assert_cmpint(qdict_size(listen), =3D=3D, 2); g_assert_cmpstr("127.0.0.1", =3D=3D, qdict_get_str(listen, "addr")); g_assert_cmpstr("5901", =3D=3D, qdict_get_str(listen, "port")); =20 acl =3D qdict_get_qdict(vnc, "acl"); g_assert(acl); + g_assert_cmpint(qdict_size(acl), =3D=3D, 3); =20 rules =3D qdict_get_qlist(acl, "rules"); g_assert(rules); g_assert_cmpint(qlist_size(rules), =3D=3D, 2); =20 rule =3D qobject_to_qdict(qlist_pop(rules)); + g_assert(rule); g_assert_cmpint(qdict_size(rule), =3D=3D, 2); g_assert_cmpstr("fred", =3D=3D, qdict_get_str(rule, "match")); g_assert_cmpstr("allow", =3D=3D, qdict_get_str(rule, "policy")); QDECREF(rule); =20 rule =3D qobject_to_qdict(qlist_pop(rules)); + g_assert(rule); g_assert_cmpint(qdict_size(rule), =3D=3D, 2); g_assert_cmpstr("bob", =3D=3D, qdict_get_str(rule, "match")); g_assert_cmpstr("deny", =3D=3D, qdict_get_str(rule, "policy")); --=20 2.7.4 From nobody Sun Apr 28 04:42:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487365206525856.7266934140688; Fri, 17 Feb 2017 13:00:06 -0800 (PST) Received: from localhost ([::1]:55891 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cepdN-00066C-6X for importer@patchew.org; Fri, 17 Feb 2017 16:00:05 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58984) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cepIU-0002Yf-R2 for qemu-devel@nongnu.org; Fri, 17 Feb 2017 15:38:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cepIS-0004Ou-7q for qemu-devel@nongnu.org; Fri, 17 Feb 2017 15:38:30 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60612) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cepIR-0004OD-VN for qemu-devel@nongnu.org; Fri, 17 Feb 2017 15:38:28 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 11BBF7E9EA for ; Fri, 17 Feb 2017 20:38:28 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-50.ams2.redhat.com [10.36.116.50]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1HKcQQp019359 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Fri, 17 Feb 2017 15:38:27 -0500 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 4222611384B0; Fri, 17 Feb 2017 21:38:25 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 17 Feb 2017 21:38:15 +0100 Message-Id: <1487363905-9480-5-git-send-email-armbru@redhat.com> In-Reply-To: <1487363905-9480-1-git-send-email-armbru@redhat.com> References: <1487363905-9480-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 17 Feb 2017 20:38:28 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 04/14] check-qjson: Simplify around compare_litqobj_to_qobj() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Make compare_litqobj_to_qobj() cope with null, and drop non-null assertions from callers. compare_litqobj_to_qobj() already checks the QType matches; drop the redundant assertions from callers. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- tests/check-qjson.c | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/tests/check-qjson.c b/tests/check-qjson.c index 0b21a22..49e02591 100644 --- a/tests/check-qjson.c +++ b/tests/check-qjson.c @@ -1110,7 +1110,7 @@ static void compare_helper(QObject *obj, void *opaque) =20 static int compare_litqobj_to_qobj(LiteralQObject *lhs, QObject *rhs) { - if (lhs->type !=3D qobject_type(rhs)) { + if (!rhs || lhs->type !=3D qobject_type(rhs)) { return 0; } =20 @@ -1184,18 +1184,12 @@ static void simple_dict(void) QString *str; =20 obj =3D qobject_from_json(test_cases[i].encoded); - g_assert(obj !=3D NULL); - g_assert(qobject_type(obj) =3D=3D QTYPE_QDICT); - g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) =3D= =3D 1); =20 str =3D qobject_to_json(obj); qobject_decref(obj); =20 obj =3D qobject_from_json(qstring_get_str(str)); - g_assert(obj !=3D NULL); - g_assert(qobject_type(obj) =3D=3D QTYPE_QDICT); - g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) =3D= =3D 1); qobject_decref(obj); QDECREF(str); @@ -1299,18 +1293,12 @@ static void simple_list(void) QString *str; =20 obj =3D qobject_from_json(test_cases[i].encoded); - g_assert(obj !=3D NULL); - g_assert(qobject_type(obj) =3D=3D QTYPE_QLIST); - g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) =3D= =3D 1); =20 str =3D qobject_to_json(obj); qobject_decref(obj); =20 obj =3D qobject_from_json(qstring_get_str(str)); - g_assert(obj !=3D NULL); - g_assert(qobject_type(obj) =3D=3D QTYPE_QLIST); - g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) =3D= =3D 1); qobject_decref(obj); QDECREF(str); @@ -1367,18 +1355,12 @@ static void simple_whitespace(void) QString *str; =20 obj =3D qobject_from_json(test_cases[i].encoded); - g_assert(obj !=3D NULL); - g_assert(qobject_type(obj) =3D=3D QTYPE_QLIST); - g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) =3D= =3D 1); =20 str =3D qobject_to_json(obj); qobject_decref(obj); =20 obj =3D qobject_from_json(qstring_get_str(str)); - g_assert(obj !=3D NULL); - g_assert(qobject_type(obj) =3D=3D QTYPE_QLIST); - g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) =3D= =3D 1); =20 qobject_decref(obj); @@ -1403,8 +1385,6 @@ static void simple_varargs(void) g_assert(embedded_obj !=3D NULL); =20 obj =3D qobject_from_jsonf("[%d, 2, %p]", 1, embedded_obj); - g_assert(obj !=3D NULL); - g_assert(compare_litqobj_to_qobj(&decoded, obj) =3D=3D 1); =20 qobject_decref(obj); --=20 2.7.4 From nobody Sun Apr 28 04:42:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487364696326950.2187201258778; Fri, 17 Feb 2017 12:51:36 -0800 (PST) Received: from localhost ([::1]:55851 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cepV7-0005zG-2B for importer@patchew.org; Fri, 17 Feb 2017 15:51:33 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58983) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cepIU-0002Yd-Qh for qemu-devel@nongnu.org; Fri, 17 Feb 2017 15:38:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cepIT-0004Pz-Kj for qemu-devel@nongnu.org; Fri, 17 Feb 2017 15:38:30 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43206) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cepIT-0004PG-FK for qemu-devel@nongnu.org; Fri, 17 Feb 2017 15:38:29 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9661F4DD4C for ; Fri, 17 Feb 2017 20:38:29 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-50.ams2.redhat.com [10.36.116.50]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1HKcSY6018328 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Fri, 17 Feb 2017 15:38:29 -0500 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 44C9F11384B1; Fri, 17 Feb 2017 21:38:25 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 17 Feb 2017 21:38:16 +0100 Message-Id: <1487363905-9480-6-git-send-email-armbru@redhat.com> In-Reply-To: <1487363905-9480-1-git-send-email-armbru@redhat.com> References: <1487363905-9480-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 17 Feb 2017 20:38:29 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 05/14] libqtest: Clean up qmp_response() a bit X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Use qobject_to_qdict() instead of a type cast. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- tests/libqtest.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/libqtest.c b/tests/libqtest.c index d8fba66..e54354d 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -379,9 +379,9 @@ static void qmp_response(JSONMessageParser *parser, GQu= eue *tokens) exit(1); } =20 - g_assert(qobject_type(obj) =3D=3D QTYPE_QDICT); g_assert(!qmp->response); - qmp->response =3D (QDict *)obj; + qmp->response =3D qobject_to_qdict(obj); + g_assert(qmp->response); } =20 QDict *qmp_fd_receive(int fd) --=20 2.7.4 From nobody Sun Apr 28 04:42:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 148736455606894.91035188304477; Fri, 17 Feb 2017 12:49:16 -0800 (PST) Received: from localhost ([::1]:55836 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cepSr-00043L-Kh for importer@patchew.org; Fri, 17 Feb 2017 15:49:13 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58980) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cepIU-0002Ya-QA for qemu-devel@nongnu.org; Fri, 17 Feb 2017 15:38:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cepIT-0004Pu-Jv for qemu-devel@nongnu.org; Fri, 17 Feb 2017 15:38:30 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38896) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cepIT-0004PF-Eu for qemu-devel@nongnu.org; Fri, 17 Feb 2017 15:38:29 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9612661BA6 for ; Fri, 17 Feb 2017 20:38:29 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-50.ams2.redhat.com [10.36.116.50]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1HKcSPL001082 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Fri, 17 Feb 2017 15:38:29 -0500 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 4776511384B2; Fri, 17 Feb 2017 21:38:25 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 17 Feb 2017 21:38:17 +0100 Message-Id: <1487363905-9480-7-git-send-email-armbru@redhat.com> In-Reply-To: <1487363905-9480-1-git-send-email-armbru@redhat.com> References: <1487363905-9480-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 17 Feb 2017 20:38:29 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 06/14] test-qmp-event: Simplify and tighten event_test_emit() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Use qdict_get_qdict() and qdict_get_try_int() to simplify. While there, add a sanity check for seconds. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- tests/test-qmp-event.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/tests/test-qmp-event.c b/tests/test-qmp-event.c index 633dc87..7bb621b 100644 --- a/tests/test-qmp-event.c +++ b/tests/test-qmp-event.c @@ -95,24 +95,18 @@ static bool qdict_cmp_simple(QDict *a, QDict *b) correctness. */ static void event_test_emit(test_QAPIEvent event, QDict *d, Error **errp) { - QObject *obj; QDict *t; int64_t s, ms; =20 /* Verify that we have timestamp, then remove it to compare other fiel= ds */ - obj =3D qdict_get(d, "timestamp"); - g_assert(obj); - t =3D qobject_to_qdict(obj); + t =3D qdict_get_qdict(d, "timestamp"); g_assert(t); - obj =3D qdict_get(t, "seconds"); - g_assert(obj && qobject_type(obj) =3D=3D QTYPE_QINT); - s =3D qint_get_int(qobject_to_qint(obj)); - obj =3D qdict_get(t, "microseconds"); - g_assert(obj && qobject_type(obj) =3D=3D QTYPE_QINT); - ms =3D qint_get_int(qobject_to_qint(obj)); + s =3D qdict_get_try_int(t, "seconds", -2); + ms =3D qdict_get_try_int(t, "microseconds", -2); if (s =3D=3D -1) { g_assert(ms =3D=3D -1); } else { + g_assert(s >=3D 0); g_assert(ms >=3D 0 && ms <=3D 999999); } g_assert(qdict_size(t) =3D=3D 2); --=20 2.7.4 From nobody Sun Apr 28 04:42:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487365728642959.3915916454822; Fri, 17 Feb 2017 13:08:48 -0800 (PST) Received: from localhost ([::1]:55971 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cepln-0005sa-3a for importer@patchew.org; Fri, 17 Feb 2017 16:08:47 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59088) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cepIX-0002an-2t for qemu-devel@nongnu.org; Fri, 17 Feb 2017 15:38:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cepIT-0004Qq-VL for qemu-devel@nongnu.org; Fri, 17 Feb 2017 15:38:33 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54034) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cepIT-0004Pf-MR for qemu-devel@nongnu.org; Fri, 17 Feb 2017 15:38:29 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CB81AC05AA48 for ; Fri, 17 Feb 2017 20:38:29 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-50.ams2.redhat.com [10.36.116.50]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1HKcSVU005386 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Fri, 17 Feb 2017 15:38:29 -0500 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 4A3E211384B3; Fri, 17 Feb 2017 21:38:25 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 17 Feb 2017 21:38:18 +0100 Message-Id: <1487363905-9480-8-git-send-email-armbru@redhat.com> In-Reply-To: <1487363905-9480-1-git-send-email-armbru@redhat.com> References: <1487363905-9480-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 17 Feb 2017 20:38:29 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 07/14] Don't check qobject_type() before qobject_to_qdict() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" qobject_to_qdict(obj) returns NULL when obj isn't a QDict. Check that instead of qobject_type(obj) =3D=3D QTYPE_QDICT. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- block.c | 4 ++-- hw/pci/pcie_aer.c | 2 +- monitor.c | 10 ++++----- qapi/qmp-dispatch.c | 5 ++--- tests/check-qdict.c | 9 ++------ tests/test-qobject-output-visitor.c | 41 +++++++++++----------------------= ---- 6 files changed, 24 insertions(+), 47 deletions(-) diff --git a/block.c b/block.c index 743c349..3c36af5 100644 --- a/block.c +++ b/block.c @@ -1169,13 +1169,13 @@ static QDict *parse_json_filename(const char *filen= ame, Error **errp) return NULL; } =20 - if (qobject_type(options_obj) !=3D QTYPE_QDICT) { + options =3D qobject_to_qdict(options_obj); + if (!options) { qobject_decref(options_obj); error_setg(errp, "Invalid JSON object given"); return NULL; } =20 - options =3D qobject_to_qdict(options_obj); qdict_flatten(options); =20 return options; diff --git a/hw/pci/pcie_aer.c b/hw/pci/pcie_aer.c index daf1f65..a8c1820 100644 --- a/hw/pci/pcie_aer.c +++ b/hw/pci/pcie_aer.c @@ -1025,8 +1025,8 @@ void hmp_pcie_aer_inject_error(Monitor *mon, const QD= ict *qdict) return; } =20 - assert(qobject_type(data) =3D=3D QTYPE_QDICT); qdict =3D qobject_to_qdict(data); + assert(qdict); =20 devfn =3D (int)qdict_get_int(qdict, "devfn"); monitor_printf(mon, "OK id: %s root bus: %s, bus: %x devfn: %x.%x\n", diff --git a/monitor.c b/monitor.c index 3cd72a9..493bed9 100644 --- a/monitor.c +++ b/monitor.c @@ -3686,12 +3686,12 @@ static QDict *qmp_check_input_obj(QObject *input_ob= j, Error **errp) int has_exec_key =3D 0; QDict *input_dict; =20 - if (qobject_type(input_obj) !=3D QTYPE_QDICT) { - error_setg(errp, QERR_QMP_BAD_INPUT_OBJECT, "object"); - return NULL; - } - input_dict =3D qobject_to_qdict(input_obj); + if (!input_dict) { + error_setg(errp, QERR_QMP_BAD_INPUT_OBJECT, "object"); + return NULL; + } + =20 for (ent =3D qdict_first(input_dict); ent; ent =3D qdict_next(input_di= ct, ent)){ const char *arg_name =3D qdict_entry_key(ent); diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index 505eb41..48bec20 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -28,14 +28,13 @@ static QDict *qmp_dispatch_check_obj(const QObject *req= uest, Error **errp) bool has_exec_key =3D false; QDict *dict =3D NULL; =20 - if (qobject_type(request) !=3D QTYPE_QDICT) { + dict =3D qobject_to_qdict(request); + if (!dict) { error_setg(errp, QERR_QMP_BAD_INPUT_OBJECT, "request is not a dictionary"); return NULL; } =20 - dict =3D qobject_to_qdict(request); - for (ent =3D qdict_first(dict); ent; ent =3D qdict_next(dict, ent)) { arg_name =3D qdict_entry_key(ent); diff --git a/tests/check-qdict.c b/tests/check-qdict.c index ded3a26..81162ee 100644 --- a/tests/check-qdict.c +++ b/tests/check-qdict.c @@ -591,7 +591,6 @@ static void qdict_join_test(void) static void qdict_crumple_test_recursive(void) { QDict *src, *dst, *rule, *vnc, *acl, *listen; - QObject *res; QList *rules; =20 src =3D qdict_new(); @@ -605,12 +604,8 @@ static void qdict_crumple_test_recursive(void) qdict_put(src, "vnc.acl..name", qstring_from_str("acl0")); qdict_put(src, "vnc.acl.rule..name", qstring_from_str("acl0")); =20 - res =3D qdict_crumple(src, &error_abort); - - g_assert_cmpint(qobject_type(res), =3D=3D, QTYPE_QDICT); - - dst =3D qobject_to_qdict(res); - + dst =3D qobject_to_qdict(qdict_crumple(src, &error_abort)); + g_assert(dst); g_assert_cmpint(qdict_size(dst), =3D=3D, 1); =20 vnc =3D qdict_get_qdict(dst, "vnc"); diff --git a/tests/test-qobject-output-visitor.c b/tests/test-qobject-outpu= t-visitor.c index 4e2d79c..a874386 100644 --- a/tests/test-qobject-output-visitor.c +++ b/tests/test-qobject-output-visitor.c @@ -160,15 +160,12 @@ static void test_visitor_out_struct(TestOutputVisitor= Data *data, .boolean =3D false, .string =3D (char *) "foo"}; TestStruct *p =3D &test_struct; - QObject *obj; QDict *qdict; =20 visit_type_TestStruct(data->ov, NULL, &p, &error_abort); =20 - obj =3D visitor_get(data); - g_assert(qobject_type(obj) =3D=3D QTYPE_QDICT); - - qdict =3D qobject_to_qdict(obj); + qdict =3D qobject_to_qdict(visitor_get(data)); + g_assert(qdict); g_assert_cmpint(qdict_size(qdict), =3D=3D, 3); g_assert_cmpint(qdict_get_int(qdict, "integer"), =3D=3D, 42); g_assert_cmpint(qdict_get_bool(qdict, "boolean"), =3D=3D, false); @@ -180,7 +177,6 @@ static void test_visitor_out_struct_nested(TestOutputVi= sitorData *data, { int64_t value =3D 42; UserDefTwo *ud2; - QObject *obj; QDict *qdict, *dict1, *dict2, *dict3, *userdef; const char *string =3D "user def string"; const char *strings[] =3D { "forty two", "forty three", "forty four", @@ -207,10 +203,8 @@ static void test_visitor_out_struct_nested(TestOutputV= isitorData *data, =20 visit_type_UserDefTwo(data->ov, "unused", &ud2, &error_abort); =20 - obj =3D visitor_get(data); - g_assert(qobject_type(obj) =3D=3D QTYPE_QDICT); - - qdict =3D qobject_to_qdict(obj); + qdict =3D qobject_to_qdict(visitor_get(data)); + g_assert(qdict); g_assert_cmpint(qdict_size(qdict), =3D=3D, 2); g_assert_cmpstr(qdict_get_str(qdict, "string0"), =3D=3D, strings[0]); =20 @@ -296,8 +290,8 @@ static void test_visitor_out_list(TestOutputVisitorData= *data, QLIST_FOREACH_ENTRY(qlist, entry) { QDict *qdict; =20 - g_assert(qobject_type(entry->value) =3D=3D QTYPE_QDICT); qdict =3D qobject_to_qdict(entry->value); + g_assert(qdict); g_assert_cmpint(qdict_size(qdict), =3D=3D, 3); g_assert_cmpint(qdict_get_int(qdict, "integer"), =3D=3D, value_int= + i); g_assert_cmpint(qdict_get_bool(qdict, "boolean"), =3D=3D, value_bo= ol); @@ -362,8 +356,7 @@ static void test_visitor_out_any(TestOutputVisitorData = *data, qobj =3D QOBJECT(qdict); visit_type_any(data->ov, NULL, &qobj, &error_abort); qobject_decref(qobj); - obj =3D visitor_get(data); - qdict =3D qobject_to_qdict(obj); + qdict =3D qobject_to_qdict(visitor_get(data)); g_assert(qdict); qobj =3D qdict_get(qdict, "integer"); g_assert(qobj); @@ -385,7 +378,6 @@ static void test_visitor_out_any(TestOutputVisitorData = *data, static void test_visitor_out_union_flat(TestOutputVisitorData *data, const void *unused) { - QObject *arg; QDict *qdict; =20 UserDefFlatUnion *tmp =3D g_malloc0(sizeof(UserDefFlatUnion)); @@ -395,11 +387,8 @@ static void test_visitor_out_union_flat(TestOutputVisi= torData *data, tmp->u.value1.boolean =3D true; =20 visit_type_UserDefFlatUnion(data->ov, NULL, &tmp, &error_abort); - arg =3D visitor_get(data); - - g_assert(qobject_type(arg) =3D=3D QTYPE_QDICT); - qdict =3D qobject_to_qdict(arg); - + qdict =3D qobject_to_qdict(visitor_get(data)); + g_assert(qdict); g_assert_cmpstr(qdict_get_str(qdict, "enum1"), =3D=3D, "value1"); g_assert_cmpstr(qdict_get_str(qdict, "string"), =3D=3D, "str"); g_assert_cmpint(qdict_get_int(qdict, "integer"), =3D=3D, 41); @@ -449,10 +438,8 @@ static void test_visitor_out_alternate(TestOutputVisit= orData *data, tmp->u.udfu.u.value1.boolean =3D true; =20 visit_type_UserDefAlternate(data->ov, NULL, &tmp, &error_abort); - arg =3D visitor_get(data); - - g_assert_cmpint(qobject_type(arg), =3D=3D, QTYPE_QDICT); - qdict =3D qobject_to_qdict(arg); + qdict =3D qobject_to_qdict(visitor_get(data)); + g_assert(qdict); g_assert_cmpint(qdict_size(qdict), =3D=3D, 4); g_assert_cmpint(qdict_get_int(qdict, "integer"), =3D=3D, 1); g_assert_cmpstr(qdict_get_str(qdict, "string"), =3D=3D, "str"); @@ -465,7 +452,6 @@ static void test_visitor_out_alternate(TestOutputVisito= rData *data, static void test_visitor_out_null(TestOutputVisitorData *data, const void *unused) { - QObject *arg; QDict *qdict; QObject *nil; =20 @@ -473,9 +459,8 @@ static void test_visitor_out_null(TestOutputVisitorData= *data, visit_type_null(data->ov, "a", &error_abort); visit_check_struct(data->ov, &error_abort); visit_end_struct(data->ov, NULL); - arg =3D visitor_get(data); - g_assert(qobject_type(arg) =3D=3D QTYPE_QDICT); - qdict =3D qobject_to_qdict(arg); + qdict =3D qobject_to_qdict(visitor_get(data)); + g_assert(qdict); g_assert_cmpint(qdict_size(qdict), =3D=3D, 1); nil =3D qdict_get(qdict, "a"); g_assert(nil); @@ -618,8 +603,6 @@ static void check_native_list(QObject *qobj, QList *qlist; int i; =20 - g_assert(qobj); - g_assert(qobject_type(qobj) =3D=3D QTYPE_QDICT); qdict =3D qobject_to_qdict(qobj); g_assert(qdict); g_assert(qdict_haskey(qdict, "data")); --=20 2.7.4 From nobody Sun Apr 28 04:42:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487364281841749.4458195707115; Fri, 17 Feb 2017 12:44:41 -0800 (PST) Received: from localhost ([::1]:55805 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cepOS-00088g-MC for importer@patchew.org; Fri, 17 Feb 2017 15:44:40 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58979) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cepIU-0002YZ-Py for qemu-devel@nongnu.org; Fri, 17 Feb 2017 15:38:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cepIT-0004Q8-M4 for qemu-devel@nongnu.org; Fri, 17 Feb 2017 15:38:30 -0500 Received: from mx1.redhat.com ([209.132.183.28]:32918) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cepIT-0004PP-GW for qemu-devel@nongnu.org; Fri, 17 Feb 2017 15:38:29 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A19FA42BAC for ; Fri, 17 Feb 2017 20:38:29 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-50.ams2.redhat.com [10.36.116.50]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1HKcSTe018330 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Fri, 17 Feb 2017 15:38:29 -0500 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 4D0AB11384B4; Fri, 17 Feb 2017 21:38:25 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 17 Feb 2017 21:38:19 +0100 Message-Id: <1487363905-9480-9-git-send-email-armbru@redhat.com> In-Reply-To: <1487363905-9480-1-git-send-email-armbru@redhat.com> References: <1487363905-9480-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 17 Feb 2017 20:38:29 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 08/14] tests: Don't check qobject_type() before qobject_to_qlist() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" qobject_to_qlist(obj) returns NULL when obj isn't a QList. Check that instead of qobject_type(obj) =3D=3D QTYPE_QLIST. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- tests/test-qobject-output-visitor.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/test-qobject-output-visitor.c b/tests/test-qobject-outpu= t-visitor.c index a874386..13a0a9b 100644 --- a/tests/test-qobject-output-visitor.c +++ b/tests/test-qobject-output-visitor.c @@ -261,7 +261,6 @@ static void test_visitor_out_list(TestOutputVisitorData= *data, bool value_bool =3D true; int value_int =3D 10; QListEntry *entry; - QObject *obj; QList *qlist; int i; =20 @@ -279,10 +278,8 @@ static void test_visitor_out_list(TestOutputVisitorDat= a *data, =20 visit_type_TestStructList(data->ov, NULL, &head, &error_abort); =20 - obj =3D visitor_get(data); - g_assert(qobject_type(obj) =3D=3D QTYPE_QLIST); - - qlist =3D qobject_to_qlist(obj); + qlist =3D qobject_to_qlist(visitor_get(data)); + g_assert(qlist); g_assert(!qlist_empty(qlist)); =20 /* ...and ensure that the visitor sees it in order */ --=20 2.7.4 From nobody Sun Apr 28 04:42:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487365489607278.22675251909436; Fri, 17 Feb 2017 13:04:49 -0800 (PST) Received: from localhost ([::1]:55927 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cephv-0001th-V7 for importer@patchew.org; Fri, 17 Feb 2017 16:04:48 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59090) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cepIX-0002aq-3q for qemu-devel@nongnu.org; Fri, 17 Feb 2017 15:38:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cepIT-0004Qk-Ut for qemu-devel@nongnu.org; Fri, 17 Feb 2017 15:38:33 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52844) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cepIT-0004Ph-MR for qemu-devel@nongnu.org; Fri, 17 Feb 2017 15:38:29 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D0E8BC04B924 for ; Fri, 17 Feb 2017 20:38:29 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-50.ams2.redhat.com [10.36.116.50]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1HKcSW0005388 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Fri, 17 Feb 2017 15:38:29 -0500 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 4FD7811384B5; Fri, 17 Feb 2017 21:38:25 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 17 Feb 2017 21:38:20 +0100 Message-Id: <1487363905-9480-10-git-send-email-armbru@redhat.com> In-Reply-To: <1487363905-9480-1-git-send-email-armbru@redhat.com> References: <1487363905-9480-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 17 Feb 2017 20:38:29 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 09/14] tests: Don't check qobject_type() before qobject_to_qstring() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" qobject_to_qstring(obj) returns NULL when obj isn't a QString. Check that instead of qobject_type(obj) =3D=3D QTYPE_QSTRING. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- tests/check-qjson.c | 31 ++++++++----------------------- tests/test-qobject-output-visitor.c | 37 +++++++++++++++++----------------= ---- 2 files changed, 25 insertions(+), 43 deletions(-) diff --git a/tests/check-qjson.c b/tests/check-qjson.c index 49e02591..dd080a8 100644 --- a/tests/check-qjson.c +++ b/tests/check-qjson.c @@ -54,11 +54,8 @@ static void escaped_string(void) QString *str; =20 obj =3D qobject_from_json(test_cases[i].encoded); - - g_assert(obj !=3D NULL); - g_assert(qobject_type(obj) =3D=3D QTYPE_QSTRING); - =20 str =3D qobject_to_qstring(obj); + g_assert(str); g_assert_cmpstr(qstring_get_str(str), =3D=3D, test_cases[i].decode= d); =20 if (test_cases[i].skip =3D=3D 0) { @@ -89,11 +86,8 @@ static void simple_string(void) QString *str; =20 obj =3D qobject_from_json(test_cases[i].encoded); - - g_assert(obj !=3D NULL); - g_assert(qobject_type(obj) =3D=3D QTYPE_QSTRING); - =20 str =3D qobject_to_qstring(obj); + g_assert(str); g_assert(strcmp(qstring_get_str(str), test_cases[i].decoded) =3D= =3D 0); =20 str =3D qobject_to_json(obj); @@ -123,11 +117,8 @@ static void single_quote_string(void) QString *str; =20 obj =3D qobject_from_json(test_cases[i].encoded); - - g_assert(obj !=3D NULL); - g_assert(qobject_type(obj) =3D=3D QTYPE_QSTRING); - =20 str =3D qobject_to_qstring(obj); + g_assert(str); g_assert(strcmp(qstring_get_str(str), test_cases[i].decoded) =3D= =3D 0); =20 QDECREF(str); @@ -820,9 +811,8 @@ static void utf8_string(void) =20 obj =3D qobject_from_json(json_in); if (utf8_out) { - g_assert(obj); - g_assert(qobject_type(obj) =3D=3D QTYPE_QSTRING); str =3D qobject_to_qstring(obj); + g_assert(str); g_assert_cmpstr(qstring_get_str(str), =3D=3D, utf8_out); } else { g_assert(!obj); @@ -847,9 +837,8 @@ static void utf8_string(void) */ if (0 && json_out !=3D json_in) { obj =3D qobject_from_json(json_out); - g_assert(obj); - g_assert(qobject_type(obj) =3D=3D QTYPE_QSTRING); str =3D qobject_to_qstring(obj); + g_assert(str); g_assert_cmpstr(qstring_get_str(str), =3D=3D, utf8_out); } } @@ -867,15 +856,11 @@ static void vararg_string(void) }; =20 for (i =3D 0; test_cases[i].decoded; i++) { - QObject *obj; QString *str; =20 - obj =3D qobject_from_jsonf("%s", test_cases[i].decoded); - - g_assert(obj !=3D NULL); - g_assert(qobject_type(obj) =3D=3D QTYPE_QSTRING); - =20 - str =3D qobject_to_qstring(obj); + str =3D qobject_to_qstring(qobject_from_jsonf("%s", + test_cases[i].decoded)= ); + g_assert(str); g_assert(strcmp(qstring_get_str(str), test_cases[i].decoded) =3D= =3D 0); =20 QDECREF(str); diff --git a/tests/test-qobject-output-visitor.c b/tests/test-qobject-outpu= t-visitor.c index 13a0a9b..3e34aa5 100644 --- a/tests/test-qobject-output-visitor.c +++ b/tests/test-qobject-output-visitor.c @@ -97,42 +97,41 @@ static void test_visitor_out_string(TestOutputVisitorDa= ta *data, const void *unused) { char *string =3D (char *) "Q E M U"; - QObject *obj; + QString *qstr; =20 visit_type_str(data->ov, NULL, &string, &error_abort); =20 - obj =3D visitor_get(data); - g_assert(qobject_type(obj) =3D=3D QTYPE_QSTRING); - g_assert_cmpstr(qstring_get_str(qobject_to_qstring(obj)), =3D=3D, stri= ng); + qstr =3D qobject_to_qstring(visitor_get(data)); + g_assert(qstr); + g_assert_cmpstr(qstring_get_str(qstr), =3D=3D, string); } =20 static void test_visitor_out_no_string(TestOutputVisitorData *data, const void *unused) { char *string =3D NULL; - QObject *obj; + QString *qstr; =20 /* A null string should return "" */ visit_type_str(data->ov, NULL, &string, &error_abort); =20 - obj =3D visitor_get(data); - g_assert(qobject_type(obj) =3D=3D QTYPE_QSTRING); - g_assert_cmpstr(qstring_get_str(qobject_to_qstring(obj)), =3D=3D, ""); + qstr =3D qobject_to_qstring(visitor_get(data)); + g_assert(qstr); + g_assert_cmpstr(qstring_get_str(qstr), =3D=3D, ""); } =20 static void test_visitor_out_enum(TestOutputVisitorData *data, const void *unused) { - QObject *obj; EnumOne i; + QString *qstr; =20 for (i =3D 0; i < ENUM_ONE__MAX; i++) { visit_type_EnumOne(data->ov, "unused", &i, &error_abort); =20 - obj =3D visitor_get(data); - g_assert(qobject_type(obj) =3D=3D QTYPE_QSTRING); - g_assert_cmpstr(qstring_get_str(qobject_to_qstring(obj)), =3D=3D, - EnumOne_lookup[i]); + qstr =3D qobject_to_qstring(visitor_get(data)); + g_assert(qstr); + g_assert_cmpstr(qstring_get_str(qstr), =3D=3D, EnumOne_lookup[i]); visitor_reset(data); } } @@ -365,9 +364,7 @@ static void test_visitor_out_any(TestOutputVisitorData = *data, qbool =3D qobject_to_qbool(qobj); g_assert(qbool); g_assert(qbool_get_bool(qbool) =3D=3D true); - qobj =3D qdict_get(qdict, "string"); - g_assert(qobj); - qstring =3D qobject_to_qstring(qobj); + qstring =3D qobject_to_qstring(qdict_get(qdict, "string")); g_assert(qstring); g_assert_cmpstr(qstring_get_str(qstring), =3D=3D, "foo"); } @@ -399,6 +396,7 @@ static void test_visitor_out_alternate(TestOutputVisito= rData *data, { QObject *arg; UserDefAlternate *tmp; + QString *qstr; QDict *qdict; =20 tmp =3D g_new0(UserDefAlternate, 1); @@ -419,10 +417,9 @@ static void test_visitor_out_alternate(TestOutputVisit= orData *data, tmp->u.s =3D g_strdup("hello"); =20 visit_type_UserDefAlternate(data->ov, NULL, &tmp, &error_abort); - arg =3D visitor_get(data); - - g_assert(qobject_type(arg) =3D=3D QTYPE_QSTRING); - g_assert_cmpstr(qstring_get_str(qobject_to_qstring(arg)), =3D=3D, "hel= lo"); + qstr =3D qobject_to_qstring(visitor_get(data)); + g_assert(qstr); + g_assert_cmpstr(qstring_get_str(qstr), =3D=3D, "hello"); =20 qapi_free_UserDefAlternate(tmp); =20 --=20 2.7.4 From nobody Sun Apr 28 04:42:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487366119131596.8730705875604; Fri, 17 Feb 2017 13:15:19 -0800 (PST) Received: from localhost ([::1]:56020 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceps5-0002Wc-SV for importer@patchew.org; Fri, 17 Feb 2017 16:15:17 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59086) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cepIX-0002am-28 for qemu-devel@nongnu.org; Fri, 17 Feb 2017 15:38:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cepIT-0004Qs-VR for qemu-devel@nongnu.org; Fri, 17 Feb 2017 15:38:33 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54032) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cepIT-0004Pe-MN for qemu-devel@nongnu.org; Fri, 17 Feb 2017 15:38:29 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CCB42C05AA4E for ; Fri, 17 Feb 2017 20:38:29 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-50.ams2.redhat.com [10.36.116.50]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1HKcSkh007997 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Fri, 17 Feb 2017 15:38:29 -0500 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 52B1E11384B6; Fri, 17 Feb 2017 21:38:25 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 17 Feb 2017 21:38:21 +0100 Message-Id: <1487363905-9480-11-git-send-email-armbru@redhat.com> In-Reply-To: <1487363905-9480-1-git-send-email-armbru@redhat.com> References: <1487363905-9480-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 17 Feb 2017 20:38:29 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 10/14] tests: Don't check qobject_type() before qobject_to_qint() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" qobject_to_qint(obj) returns NULL when obj isn't a QInt. Check that instead of qobject_type(obj) =3D=3D QTYPE_QINT. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- tests/check-qjson.c | 24 +++++------------------- tests/test-qobject-output-visitor.c | 28 ++++++++++++---------------- 2 files changed, 17 insertions(+), 35 deletions(-) diff --git a/tests/check-qjson.c b/tests/check-qjson.c index dd080a8..aab4e0a 100644 --- a/tests/check-qjson.c +++ b/tests/check-qjson.c @@ -884,19 +884,15 @@ static void simple_number(void) }; =20 for (i =3D 0; test_cases[i].encoded; i++) { - QObject *obj; QInt *qint; =20 - obj =3D qobject_from_json(test_cases[i].encoded); - g_assert(obj !=3D NULL); - g_assert(qobject_type(obj) =3D=3D QTYPE_QINT); - - qint =3D qobject_to_qint(obj); + qint =3D qobject_to_qint(qobject_from_json(test_cases[i].encoded)); + g_assert(qint); g_assert(qint_get_int(qint) =3D=3D test_cases[i].decoded); if (test_cases[i].skip =3D=3D 0) { QString *str; =20 - str =3D qobject_to_json(obj); + str =3D qobject_to_json(QOBJECT(qint)); g_assert(strcmp(qstring_get_str(str), test_cases[i].encoded) = =3D=3D 0); QDECREF(str); } @@ -952,22 +948,12 @@ static void vararg_number(void) long long value_ll =3D 0x2342342343LL; double valuef =3D 2.323423423; =20 - obj =3D qobject_from_jsonf("%d", value); - g_assert(obj !=3D NULL); - g_assert(qobject_type(obj) =3D=3D QTYPE_QINT); - - qint =3D qobject_to_qint(obj); + qint =3D qobject_to_qint(qobject_from_jsonf("%d", value)); g_assert(qint_get_int(qint) =3D=3D value); - QDECREF(qint); =20 - obj =3D qobject_from_jsonf("%lld", value_ll); - g_assert(obj !=3D NULL); - g_assert(qobject_type(obj) =3D=3D QTYPE_QINT); - - qint =3D qobject_to_qint(obj); + qint =3D qobject_to_qint(qobject_from_jsonf("%lld", value_ll)); g_assert(qint_get_int(qint) =3D=3D value_ll); - QDECREF(qint); =20 obj =3D qobject_from_jsonf("%f", valuef); diff --git a/tests/test-qobject-output-visitor.c b/tests/test-qobject-outpu= t-visitor.c index 3e34aa5..50b807e 100644 --- a/tests/test-qobject-output-visitor.c +++ b/tests/test-qobject-output-visitor.c @@ -58,13 +58,13 @@ static void test_visitor_out_int(TestOutputVisitorData = *data, const void *unused) { int64_t value =3D -42; - QObject *obj; + QInt *qint; =20 visit_type_int(data->ov, NULL, &value, &error_abort); =20 - obj =3D visitor_get(data); - g_assert(qobject_type(obj) =3D=3D QTYPE_QINT); - g_assert_cmpint(qint_get_int(qobject_to_qint(obj)), =3D=3D, value); + qint =3D qobject_to_qint(visitor_get(data)); + g_assert(qint); + g_assert_cmpint(qint_get_int(qint), =3D=3D, value); } =20 static void test_visitor_out_bool(TestOutputVisitorData *data, @@ -335,13 +335,12 @@ static void test_visitor_out_any(TestOutputVisitorDat= a *data, QBool *qbool; QString *qstring; QDict *qdict; - QObject *obj; =20 qobj =3D QOBJECT(qint_from_int(-42)); visit_type_any(data->ov, NULL, &qobj, &error_abort); - obj =3D visitor_get(data); - g_assert(qobject_type(obj) =3D=3D QTYPE_QINT); - g_assert_cmpint(qint_get_int(qobject_to_qint(obj)), =3D=3D, -42); + qint =3D qobject_to_qint(visitor_get(data)); + g_assert(qint); + g_assert_cmpint(qint_get_int(qint), =3D=3D, -42); qobject_decref(qobj); =20 visitor_reset(data); @@ -354,9 +353,7 @@ static void test_visitor_out_any(TestOutputVisitorData = *data, qobject_decref(qobj); qdict =3D qobject_to_qdict(visitor_get(data)); g_assert(qdict); - qobj =3D qdict_get(qdict, "integer"); - g_assert(qobj); - qint =3D qobject_to_qint(qobj); + qint =3D qobject_to_qint(qdict_get(qdict, "integer")); g_assert(qint); g_assert_cmpint(qint_get_int(qint), =3D=3D, -42); qobj =3D qdict_get(qdict, "boolean"); @@ -394,8 +391,8 @@ static void test_visitor_out_union_flat(TestOutputVisit= orData *data, static void test_visitor_out_alternate(TestOutputVisitorData *data, const void *unused) { - QObject *arg; UserDefAlternate *tmp; + QInt *qint; QString *qstr; QDict *qdict; =20 @@ -404,10 +401,9 @@ static void test_visitor_out_alternate(TestOutputVisit= orData *data, tmp->u.i =3D 42; =20 visit_type_UserDefAlternate(data->ov, NULL, &tmp, &error_abort); - arg =3D visitor_get(data); - - g_assert(qobject_type(arg) =3D=3D QTYPE_QINT); - g_assert_cmpint(qint_get_int(qobject_to_qint(arg)), =3D=3D, 42); + qint =3D qobject_to_qint(visitor_get(data)); + g_assert(qint); + g_assert_cmpint(qint_get_int(qint), =3D=3D, 42); =20 qapi_free_UserDefAlternate(tmp); =20 --=20 2.7.4 From nobody Sun Apr 28 04:42:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487364281583503.53190361795725; Fri, 17 Feb 2017 12:44:41 -0800 (PST) Received: from localhost ([::1]:55804 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cepOS-00087f-8N for importer@patchew.org; Fri, 17 Feb 2017 15:44:40 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58993) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cepIU-0002Yi-US for qemu-devel@nongnu.org; Fri, 17 Feb 2017 15:38:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cepIT-0004QE-N6 for qemu-devel@nongnu.org; Fri, 17 Feb 2017 15:38:30 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54028) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cepIT-0004PR-Gw for qemu-devel@nongnu.org; Fri, 17 Feb 2017 15:38:29 -0500 Received: from smtp.corp.redhat.com (int-mx16.intmail.prod.int.phx2.redhat.com [10.5.11.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A18C2C05AA43 for ; Fri, 17 Feb 2017 20:38:29 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-50.ams2.redhat.com [10.36.116.50]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 69DCE19CB5 for ; Fri, 17 Feb 2017 20:38:29 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 5590811384B7; Fri, 17 Feb 2017 21:38:25 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 17 Feb 2017 21:38:22 +0100 Message-Id: <1487363905-9480-12-git-send-email-armbru@redhat.com> In-Reply-To: <1487363905-9480-1-git-send-email-armbru@redhat.com> References: <1487363905-9480-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.74 on 10.5.11.28 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 17 Feb 2017 20:38:29 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 11/14] tests: Don't check qobject_type() before qobject_to_qfloat() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" qobject_to_qfloat(obj) returns NULL when obj isn't a QFloat. Check that instead of qobject_type(obj) =3D=3D QTYPE_QFLOAT. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- tests/check-qjson.c | 12 ++---------- tests/test-qobject-output-visitor.c | 8 ++++---- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/tests/check-qjson.c b/tests/check-qjson.c index aab4e0a..591b70a 100644 --- a/tests/check-qjson.c +++ b/tests/check-qjson.c @@ -921,10 +921,8 @@ static void float_number(void) QFloat *qfloat; =20 obj =3D qobject_from_json(test_cases[i].encoded); - g_assert(obj !=3D NULL); - g_assert(qobject_type(obj) =3D=3D QTYPE_QFLOAT); - qfloat =3D qobject_to_qfloat(obj); + g_assert(qfloat); g_assert(qfloat_get_double(qfloat) =3D=3D test_cases[i].decoded); =20 if (test_cases[i].skip =3D=3D 0) { @@ -941,7 +939,6 @@ static void float_number(void) =20 static void vararg_number(void) { - QObject *obj; QInt *qint; QFloat *qfloat; int value =3D 0x2342; @@ -956,13 +953,8 @@ static void vararg_number(void) g_assert(qint_get_int(qint) =3D=3D value_ll); QDECREF(qint); =20 - obj =3D qobject_from_jsonf("%f", valuef); - g_assert(obj !=3D NULL); - g_assert(qobject_type(obj) =3D=3D QTYPE_QFLOAT); - - qfloat =3D qobject_to_qfloat(obj); + qfloat =3D qobject_to_qfloat(qobject_from_jsonf("%f", valuef)); g_assert(qfloat_get_double(qfloat) =3D=3D valuef); - QDECREF(qfloat); } =20 diff --git a/tests/test-qobject-output-visitor.c b/tests/test-qobject-outpu= t-visitor.c index 50b807e..5617fd3 100644 --- a/tests/test-qobject-output-visitor.c +++ b/tests/test-qobject-output-visitor.c @@ -84,13 +84,13 @@ static void test_visitor_out_number(TestOutputVisitorDa= ta *data, const void *unused) { double value =3D 3.14; - QObject *obj; + QFloat *qfloat; =20 visit_type_number(data->ov, NULL, &value, &error_abort); =20 - obj =3D visitor_get(data); - g_assert(qobject_type(obj) =3D=3D QTYPE_QFLOAT); - g_assert(qfloat_get_double(qobject_to_qfloat(obj)) =3D=3D value); + qfloat =3D qobject_to_qfloat(visitor_get(data)); + g_assert(qfloat); + g_assert(qfloat_get_double(qfloat) =3D=3D value); } =20 static void test_visitor_out_string(TestOutputVisitorData *data, --=20 2.7.4 From nobody Sun Apr 28 04:42:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487364028257511.30790417436924; Fri, 17 Feb 2017 12:40:28 -0800 (PST) Received: from localhost ([::1]:55781 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cepKM-0003lk-Rf for importer@patchew.org; Fri, 17 Feb 2017 15:40:26 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58995) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cepIV-0002Ym-0a for qemu-devel@nongnu.org; Fri, 17 Feb 2017 15:38:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cepIT-0004QU-OS for qemu-devel@nongnu.org; Fri, 17 Feb 2017 15:38:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52532) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cepIT-0004PX-GP for qemu-devel@nongnu.org; Fri, 17 Feb 2017 15:38:29 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AB9EF7FB77 for ; Fri, 17 Feb 2017 20:38:29 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-50.ams2.redhat.com [10.36.116.50]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1HKcS11005390 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Fri, 17 Feb 2017 15:38:29 -0500 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 5E7B511384B8; Fri, 17 Feb 2017 21:38:25 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 17 Feb 2017 21:38:23 +0100 Message-Id: <1487363905-9480-13-git-send-email-armbru@redhat.com> In-Reply-To: <1487363905-9480-1-git-send-email-armbru@redhat.com> References: <1487363905-9480-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 17 Feb 2017 20:38:29 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 12/14] tests: Don't check qobject_type() before qobject_to_qbool() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" qobject_to_qbool(obj) returns NULL when obj isn't a QBool. Check that instead of qobject_type(obj) =3D=3D QTYPE_QBOOL. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- tests/check-qjson.c | 24 ++++++------------------ tests/test-qobject-output-visitor.c | 12 +++++------- 2 files changed, 11 insertions(+), 25 deletions(-) diff --git a/tests/check-qjson.c b/tests/check-qjson.c index 591b70a..e6d6935 100644 --- a/tests/check-qjson.c +++ b/tests/check-qjson.c @@ -966,10 +966,8 @@ static void keyword_literal(void) QString *str; =20 obj =3D qobject_from_json("true"); - g_assert(obj !=3D NULL); - g_assert(qobject_type(obj) =3D=3D QTYPE_QBOOL); - qbool =3D qobject_to_qbool(obj); + g_assert(qbool); g_assert(qbool_get_bool(qbool) =3D=3D true); =20 str =3D qobject_to_json(obj); @@ -979,10 +977,8 @@ static void keyword_literal(void) QDECREF(qbool); =20 obj =3D qobject_from_json("false"); - g_assert(obj !=3D NULL); - g_assert(qobject_type(obj) =3D=3D QTYPE_QBOOL); - qbool =3D qobject_to_qbool(obj); + g_assert(qbool); g_assert(qbool_get_bool(qbool) =3D=3D false); =20 str =3D qobject_to_json(obj); @@ -991,23 +987,15 @@ static void keyword_literal(void) =20 QDECREF(qbool); =20 - obj =3D qobject_from_jsonf("%i", false); - g_assert(obj !=3D NULL); - g_assert(qobject_type(obj) =3D=3D QTYPE_QBOOL); - - qbool =3D qobject_to_qbool(obj); + qbool =3D qobject_to_qbool(qobject_from_jsonf("%i", false)); + g_assert(qbool); g_assert(qbool_get_bool(qbool) =3D=3D false); - QDECREF(qbool); =20 /* Test that non-zero values other than 1 get collapsed to true */ - obj =3D qobject_from_jsonf("%i", 2); - g_assert(obj !=3D NULL); - g_assert(qobject_type(obj) =3D=3D QTYPE_QBOOL); - - qbool =3D qobject_to_qbool(obj); + qbool =3D qobject_to_qbool(qobject_from_jsonf("%i", 2)); + g_assert(qbool); g_assert(qbool_get_bool(qbool) =3D=3D true); - QDECREF(qbool); =20 obj =3D qobject_from_json("null"); diff --git a/tests/test-qobject-output-visitor.c b/tests/test-qobject-outpu= t-visitor.c index 5617fd3..500b452 100644 --- a/tests/test-qobject-output-visitor.c +++ b/tests/test-qobject-output-visitor.c @@ -71,13 +71,13 @@ static void test_visitor_out_bool(TestOutputVisitorData= *data, const void *unused) { bool value =3D true; - QObject *obj; + QBool *qbool; =20 visit_type_bool(data->ov, NULL, &value, &error_abort); =20 - obj =3D visitor_get(data); - g_assert(qobject_type(obj) =3D=3D QTYPE_QBOOL); - g_assert(qbool_get_bool(qobject_to_qbool(obj)) =3D=3D value); + qbool =3D qobject_to_qbool(visitor_get(data)); + g_assert(qbool); + g_assert(qbool_get_bool(qbool) =3D=3D value); } =20 static void test_visitor_out_number(TestOutputVisitorData *data, @@ -356,9 +356,7 @@ static void test_visitor_out_any(TestOutputVisitorData = *data, qint =3D qobject_to_qint(qdict_get(qdict, "integer")); g_assert(qint); g_assert_cmpint(qint_get_int(qint), =3D=3D, -42); - qobj =3D qdict_get(qdict, "boolean"); - g_assert(qobj); - qbool =3D qobject_to_qbool(qobj); + qbool =3D qobject_to_qbool(qdict_get(qdict, "boolean")); g_assert(qbool); g_assert(qbool_get_bool(qbool) =3D=3D true); qstring =3D qobject_to_qstring(qdict_get(qdict, "string")); --=20 2.7.4 From nobody Sun Apr 28 04:42:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 148736574525345.18589276860189; Fri, 17 Feb 2017 13:09:05 -0800 (PST) Received: from localhost ([::1]:55972 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cepm4-000687-2u for importer@patchew.org; Fri, 17 Feb 2017 16:09:04 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58991) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cepIU-0002Yg-SU for qemu-devel@nongnu.org; Fri, 17 Feb 2017 15:38:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cepIT-0004QI-OL for qemu-devel@nongnu.org; Fri, 17 Feb 2017 15:38:30 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38898) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cepIT-0004PV-Hf for qemu-devel@nongnu.org; Fri, 17 Feb 2017 15:38:29 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A8F4861D2C for ; Fri, 17 Feb 2017 20:38:29 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-50.ams2.redhat.com [10.36.116.50]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1HKcSTL008001 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Fri, 17 Feb 2017 15:38:29 -0500 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 686F611384B9; Fri, 17 Feb 2017 21:38:25 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 17 Feb 2017 21:38:24 +0100 Message-Id: <1487363905-9480-14-git-send-email-armbru@redhat.com> In-Reply-To: <1487363905-9480-1-git-send-email-armbru@redhat.com> References: <1487363905-9480-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 17 Feb 2017 20:38:29 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 13/14] monitor: Clean up handle_hmp_command() a bit X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Leave checking qobject_type(req) to qmp_check_input_obj(). Rework handling of json_parser_parse_err() failing without setting an error. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- monitor.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/monitor.c b/monitor.c index 493bed9..1e352a6 100644 --- a/monitor.c +++ b/monitor.c @@ -3735,10 +3735,11 @@ static void handle_qmp_command(JSONMessageParser *p= arser, GQueue *tokens) Error *err =3D NULL; =20 req =3D json_parser_parse_err(tokens, NULL, &err); - if (err || !req || qobject_type(req) !=3D QTYPE_QDICT) { - if (!err) { - error_setg(&err, QERR_JSON_PARSING); - } + if (!req && !err) { + /* json_parser_parse_err() sucks: can fail without setting @err */ + error_setg(&err, QERR_JSON_PARSING); + } + if (err) { goto err_out; } =20 --=20 2.7.4 From nobody Sun Apr 28 04:42:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487364953705921.962284797358; Fri, 17 Feb 2017 12:55:53 -0800 (PST) Received: from localhost ([::1]:55873 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cepZI-0001Pu-B6 for importer@patchew.org; Fri, 17 Feb 2017 15:55:52 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58997) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cepIV-0002Yr-2O for qemu-devel@nongnu.org; Fri, 17 Feb 2017 15:38:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cepIT-0004QP-OQ for qemu-devel@nongnu.org; Fri, 17 Feb 2017 15:38:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60626) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cepIT-0004PZ-Hd for qemu-devel@nongnu.org; Fri, 17 Feb 2017 15:38:29 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AA9B66AAC7 for ; Fri, 17 Feb 2017 20:38:29 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-50.ams2.redhat.com [10.36.116.50]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1HKcSVH019375 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Fri, 17 Feb 2017 15:38:29 -0500 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 6AC2811384BA; Fri, 17 Feb 2017 21:38:25 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 17 Feb 2017 21:38:25 +0100 Message-Id: <1487363905-9480-15-git-send-email-armbru@redhat.com> In-Reply-To: <1487363905-9480-1-git-send-email-armbru@redhat.com> References: <1487363905-9480-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 17 Feb 2017 20:38:29 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 14/14] block: Don't bother asserting type of output visitor's output X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" After a visit of a complex QAPI type FOO ov =3D qobject_output_visitor_new(&foo); visit_type_FOO(ov, NULL, expr, &error_abort); visit_complete(ov, &foo); we can safely assume qobject_type(foo) is QTYPE_QDICT. We do in many places, but occasionally assert qobject_type(obj) =3D=3D QTYPE_QDICT. Don't. The appropriate place to check such fundamental properties of QAPI visitors is the test suite. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- block/nbd.c | 2 -- block/nfs.c | 2 -- block/qapi.c | 1 - 3 files changed, 5 deletions(-) diff --git a/block/nbd.c b/block/nbd.c index 35f24be..a7f9108 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -537,8 +537,6 @@ static void nbd_refresh_filename(BlockDriverState *bs, = QDict *options) visit_type_SocketAddress(ov, NULL, &s->saddr, &error_abort); visit_complete(ov, &saddr_qdict); visit_free(ov); - assert(qobject_type(saddr_qdict) =3D=3D QTYPE_QDICT); - qdict_put_obj(opts, "server", saddr_qdict); =20 if (s->export) { diff --git a/block/nfs.c b/block/nfs.c index 689eaa7..55a8a62 100644 --- a/block/nfs.c +++ b/block/nfs.c @@ -798,8 +798,6 @@ static void nfs_refresh_filename(BlockDriverState *bs, = QDict *options) ov =3D qobject_output_visitor_new(&server_qdict); visit_type_NFSServer(ov, NULL, &client->server, &error_abort); visit_complete(ov, &server_qdict); - assert(qobject_type(server_qdict) =3D=3D QTYPE_QDICT); - qdict_put_obj(opts, "server", server_qdict); qdict_put(opts, "path", qstring_from_str(client->path)); =20 diff --git a/block/qapi.c b/block/qapi.c index ac480aa..a40922e 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -682,7 +682,6 @@ void bdrv_image_info_specific_dump(fprintf_function fun= c_fprintf, void *f, =20 visit_type_ImageInfoSpecific(v, NULL, &info_spec, &error_abort); visit_complete(v, &obj); - assert(qobject_type(obj) =3D=3D QTYPE_QDICT); data =3D qdict_get(qobject_to_qdict(obj), "data"); dump_qobject(func_fprintf, f, 1, data); qobject_decref(obj); --=20 2.7.4