From nobody Thu May 2 20:19:12 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.zohomail.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 150365903073516.856003535007403; Fri, 25 Aug 2017 04:03:50 -0700 (PDT) Received: from localhost ([::1]:52484 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dlCOz-0002qN-Ky for importer@patchew.org; Fri, 25 Aug 2017 07:03:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46651) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dlCKm-0007AK-VJ for qemu-devel@nongnu.org; Fri, 25 Aug 2017 06:59:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dlCKl-0004mi-W5 for qemu-devel@nongnu.org; Fri, 25 Aug 2017 06:59:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54012) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dlCKl-0004m1-QE for qemu-devel@nongnu.org; Fri, 25 Aug 2017 06:59:27 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8D76B7E434; Fri, 25 Aug 2017 10:59:26 +0000 (UTC) Received: from localhost (ovpn-112-49.ams2.redhat.com [10.36.112.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 72BFE80E0F; Fri, 25 Aug 2017 10:59:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8D76B7E434 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Fri, 25 Aug 2017 12:59:00 +0200 Message-Id: <20170825105913.4060-2-marcandre.lureau@redhat.com> In-Reply-To: <20170825105913.4060-1-marcandre.lureau@redhat.com> References: <20170825105913.4060-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 25 Aug 2017 10:59:26 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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 v2 01/14] qdict: add qdict_put_null() helper 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: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Richard Henderson , armbru@redhat.com, Eduardo Habkost , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" A step towards completeness. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Markus Armbruster Reviewed-by: Eduardo Habkost --- include/qapi/qmp/qdict.h | 4 +++- target/i386/cpu.c | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/qapi/qmp/qdict.h b/include/qapi/qmp/qdict.h index 363e431106..6588c7f0c8 100644 --- a/include/qapi/qmp/qdict.h +++ b/include/qapi/qmp/qdict.h @@ -53,13 +53,15 @@ void qdict_destroy_obj(QObject *obj); #define qdict_put(qdict, key, obj) \ qdict_put_obj(qdict, key, QOBJECT(obj)) =20 -/* Helpers for int, bool, and string */ +/* Helpers for int, bool, null, and string */ #define qdict_put_int(qdict, key, value) \ qdict_put(qdict, key, qnum_from_int(value)) #define qdict_put_bool(qdict, key, value) \ qdict_put(qdict, key, qbool_from_bool(value)) #define qdict_put_str(qdict, key, value) \ qdict_put(qdict, key, qstring_from_str(value)) +#define qdict_put_null(qdict, key) \ + qdict_put(qdict, key, qnull()) =20 /* High level helpers */ double qdict_get_double(const QDict *qdict, const char *key); diff --git a/target/i386/cpu.c b/target/i386/cpu.c index ddc45abd70..bec2009a9c 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -2454,7 +2454,7 @@ static QDict *x86_cpu_static_props(void) =20 d =3D qdict_new(); for (i =3D 0; props[i]; i++) { - qdict_put(d, props[i], qnull()); + qdict_put_null(d, props[i]); } =20 for (w =3D 0; w < FEATURE_WORDS; w++) { @@ -2464,7 +2464,7 @@ static QDict *x86_cpu_static_props(void) if (!fi->feat_names[bit]) { continue; } - qdict_put(d, fi->feat_names[bit], qnull()); + qdict_put_null(d, fi->feat_names[bit]); } } =20 --=20 2.14.1.146.gd35faa819 From nobody Thu May 2 20:19:12 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.zohomail.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 1503659204380102.97580165429565; Fri, 25 Aug 2017 04:06:44 -0700 (PDT) Received: from localhost ([::1]:52498 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dlCRn-000559-23 for importer@patchew.org; Fri, 25 Aug 2017 07:06:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46862) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dlCL1-0007Im-6w for qemu-devel@nongnu.org; Fri, 25 Aug 2017 06:59:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dlCKw-0004rS-Bb for qemu-devel@nongnu.org; Fri, 25 Aug 2017 06:59:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54836) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dlCKw-0004rC-3L for qemu-devel@nongnu.org; Fri, 25 Aug 2017 06:59:38 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CF26713AB1 for ; Fri, 25 Aug 2017 10:59:36 +0000 (UTC) Received: from localhost (ovpn-112-49.ams2.redhat.com [10.36.112.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 650C06C40B; Fri, 25 Aug 2017 10:59:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CF26713AB1 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Fri, 25 Aug 2017 12:59:01 +0200 Message-Id: <20170825105913.4060-3-marcandre.lureau@redhat.com> In-Reply-To: <20170825105913.4060-1-marcandre.lureau@redhat.com> References: <20170825105913.4060-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 25 Aug 2017 10:59:37 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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 v2 02/14] qlit: move qlit from check-qjson to qobject/ 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: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Fix code style issues while at it, to please checkpatch. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Markus Armbruster --- include/qapi/qmp/qlit.h | 49 +++++++++++++++++++++++++ qobject/qlit.c | 89 +++++++++++++++++++++++++++++++++++++++++++++ tests/check-qjson.c | 96 +--------------------------------------------= ---- qobject/Makefile.objs | 2 +- 4 files changed, 140 insertions(+), 96 deletions(-) create mode 100644 include/qapi/qmp/qlit.h create mode 100644 qobject/qlit.c diff --git a/include/qapi/qmp/qlit.h b/include/qapi/qmp/qlit.h new file mode 100644 index 0000000000..280db5064a --- /dev/null +++ b/include/qapi/qmp/qlit.h @@ -0,0 +1,49 @@ +/* + * Copyright IBM, Corp. 2009 + * Copyright (c) 2013, 2015, 2017 Red Hat Inc. + * + * Authors: + * Anthony Liguori + * Markus Armbruster + * Marc-Andr=C3=A9 Lureau + * + * This work is licensed under the terms of the GNU LGPL, version 2.1 or l= ater. + * See the COPYING.LIB file in the top-level directory. + * + */ +#ifndef QLIT_H +#define QLIT_H + +#include "qapi-types.h" +#include "qobject.h" + +typedef struct LiteralQDictEntry LiteralQDictEntry; +typedef struct LiteralQObject LiteralQObject; + +struct LiteralQObject { + int type; + union { + int64_t qnum; + const char *qstr; + LiteralQDictEntry *qdict; + LiteralQObject *qlist; + } value; +}; + +struct LiteralQDictEntry { + const char *key; + LiteralQObject value; +}; + +#define QLIT_QNUM(val) \ + (LiteralQObject){.type =3D QTYPE_QNUM, .value.qnum =3D (val)} +#define QLIT_QSTR(val) \ + (LiteralQObject){.type =3D QTYPE_QSTRING, .value.qstr =3D (val)} +#define QLIT_QDICT(val) \ + (LiteralQObject){.type =3D QTYPE_QDICT, .value.qdict =3D (val)} +#define QLIT_QLIST(val) \ + (LiteralQObject){.type =3D QTYPE_QLIST, .value.qlist =3D (val)} + +int compare_litqobj_to_qobj(LiteralQObject *lhs, QObject *rhs); + +#endif /* QLIT_H */ diff --git a/qobject/qlit.c b/qobject/qlit.c new file mode 100644 index 0000000000..5917c3584e --- /dev/null +++ b/qobject/qlit.c @@ -0,0 +1,89 @@ +/* + * QLit literal qobject + * + * Copyright IBM, Corp. 2009 + * Copyright (c) 2013, 2015, 2017 Red Hat Inc. + * + * Authors: + * Anthony Liguori + * Markus Armbruster + * Marc-Andr=C3=A9 Lureau + * + * This work is licensed under the terms of the GNU LGPL, version 2.1 or l= ater. + * See the COPYING.LIB file in the top-level directory. + */ + +#include "qemu/osdep.h" + +#include "qapi/qmp/qlit.h" +#include "qapi/qmp/types.h" + +typedef struct QListCompareHelper { + int index; + LiteralQObject *objs; + int result; +} QListCompareHelper; + +static void compare_helper(QObject *obj, void *opaque) +{ + QListCompareHelper *helper =3D opaque; + + if (helper->result =3D=3D 0) { + return; + } + + if (helper->objs[helper->index].type =3D=3D QTYPE_NONE) { + helper->result =3D 0; + return; + } + + helper->result =3D + compare_litqobj_to_qobj(&helper->objs[helper->index++], obj); +} + +int compare_litqobj_to_qobj(LiteralQObject *lhs, QObject *rhs) +{ + int64_t val; + + if (!rhs || lhs->type !=3D qobject_type(rhs)) { + return 0; + } + + switch (lhs->type) { + case QTYPE_QNUM: + g_assert(qnum_get_try_int(qobject_to_qnum(rhs), &val)); + return lhs->value.qnum =3D=3D val; + case QTYPE_QSTRING: + return (strcmp(lhs->value.qstr, + qstring_get_str(qobject_to_qstring(rhs))) =3D=3D 0); + case QTYPE_QDICT: { + int i; + + for (i =3D 0; lhs->value.qdict[i].key; i++) { + QObject *obj =3D qdict_get(qobject_to_qdict(rhs), + lhs->value.qdict[i].key); + + if (!compare_litqobj_to_qobj(&lhs->value.qdict[i].value, obj))= { + return 0; + } + } + + return 1; + } + case QTYPE_QLIST: { + QListCompareHelper helper; + + helper.index =3D 0; + helper.objs =3D lhs->value.qlist; + helper.result =3D 1; + + qlist_iter(qobject_to_qlist(rhs), compare_helper, &helper); + + return helper.result; + } + default: + break; + } + + return 0; +} diff --git a/tests/check-qjson.c b/tests/check-qjson.c index a3a97b0d99..525f79e60b 100644 --- a/tests/check-qjson.c +++ b/tests/check-qjson.c @@ -16,6 +16,7 @@ #include "qapi/error.h" #include "qapi/qmp/types.h" #include "qapi/qmp/qjson.h" +#include "qapi/qmp/qlit.h" #include "qemu-common.h" =20 static void escaped_string(void) @@ -1059,101 +1060,6 @@ static void keyword_literal(void) QDECREF(null); } =20 -typedef struct LiteralQDictEntry LiteralQDictEntry; -typedef struct LiteralQObject LiteralQObject; - -struct LiteralQObject -{ - int type; - union { - int64_t qnum; - const char *qstr; - LiteralQDictEntry *qdict; - LiteralQObject *qlist; - } value; -}; - -struct LiteralQDictEntry -{ - const char *key; - LiteralQObject value; -}; - -#define QLIT_QNUM(val) (LiteralQObject){.type =3D QTYPE_QNUM, .value.qnum = =3D (val)} -#define QLIT_QSTR(val) (LiteralQObject){.type =3D QTYPE_QSTRING, .value.qs= tr =3D (val)} -#define QLIT_QDICT(val) (LiteralQObject){.type =3D QTYPE_QDICT, .value.qdi= ct =3D (val)} -#define QLIT_QLIST(val) (LiteralQObject){.type =3D QTYPE_QLIST, .value.qli= st =3D (val)} - -typedef struct QListCompareHelper -{ - int index; - LiteralQObject *objs; - int result; -} QListCompareHelper; - -static int compare_litqobj_to_qobj(LiteralQObject *lhs, QObject *rhs); - -static void compare_helper(QObject *obj, void *opaque) -{ - QListCompareHelper *helper =3D opaque; - - if (helper->result =3D=3D 0) { - return; - } - - if (helper->objs[helper->index].type =3D=3D QTYPE_NONE) { - helper->result =3D 0; - return; - } - - helper->result =3D compare_litqobj_to_qobj(&helper->objs[helper->index= ++], obj); -} - -static int compare_litqobj_to_qobj(LiteralQObject *lhs, QObject *rhs) -{ - int64_t val; - - if (!rhs || lhs->type !=3D qobject_type(rhs)) { - return 0; - } - - switch (lhs->type) { - case QTYPE_QNUM: - g_assert(qnum_get_try_int(qobject_to_qnum(rhs), &val)); - return lhs->value.qnum =3D=3D val; - case QTYPE_QSTRING: - return (strcmp(lhs->value.qstr, qstring_get_str(qobject_to_qstring= (rhs))) =3D=3D 0); - case QTYPE_QDICT: { - int i; - - for (i =3D 0; lhs->value.qdict[i].key; i++) { - QObject *obj =3D qdict_get(qobject_to_qdict(rhs), lhs->value.q= dict[i].key); - - if (!compare_litqobj_to_qobj(&lhs->value.qdict[i].value, obj))= { - return 0; - } - } - - return 1; - } - case QTYPE_QLIST: { - QListCompareHelper helper; - - helper.index =3D 0; - helper.objs =3D lhs->value.qlist; - helper.result =3D 1; - =20 - qlist_iter(qobject_to_qlist(rhs), compare_helper, &helper); - - return helper.result; - } - default: - break; - } - - return 0; -} - static void simple_dict(void) { int i; diff --git a/qobject/Makefile.objs b/qobject/Makefile.objs index fc8885c9a4..002d25873a 100644 --- a/qobject/Makefile.objs +++ b/qobject/Makefile.objs @@ -1,2 +1,2 @@ -util-obj-y =3D qnull.o qnum.o qstring.o qdict.o qlist.o qbool.o +util-obj-y =3D qnull.o qnum.o qstring.o qdict.o qlist.o qbool.o qlit.o util-obj-y +=3D qjson.o qobject.o json-lexer.o json-streamer.o json-parser= .o --=20 2.14.1.146.gd35faa819 From nobody Thu May 2 20:19:12 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.zohomail.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 15036593643541018.1504432290627; Fri, 25 Aug 2017 04:09:24 -0700 (PDT) Received: from localhost ([::1]:52508 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dlCUN-0007cs-5e for importer@patchew.org; Fri, 25 Aug 2017 07:09:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46885) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dlCL5-0007Jb-94 for qemu-devel@nongnu.org; Fri, 25 Aug 2017 06:59:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dlCL3-0004tk-VR for qemu-devel@nongnu.org; Fri, 25 Aug 2017 06:59:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59444) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dlCL3-0004tb-MA for qemu-devel@nongnu.org; Fri, 25 Aug 2017 06:59:45 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 94FB3C058EB7 for ; Fri, 25 Aug 2017 10:59:44 +0000 (UTC) Received: from localhost (ovpn-112-49.ams2.redhat.com [10.36.112.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5916C7B8FB; Fri, 25 Aug 2017 10:59:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 94FB3C058EB7 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Fri, 25 Aug 2017 12:59:02 +0200 Message-Id: <20170825105913.4060-4-marcandre.lureau@redhat.com> In-Reply-To: <20170825105913.4060-1-marcandre.lureau@redhat.com> References: <20170825105913.4060-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 25 Aug 2017 10:59:44 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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 v2 03/14] qlit: use QLit prefix consistently 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: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Rename from LiteralQ to QLit. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Markus Armbruster --- include/qapi/qmp/qlit.h | 24 ++++++++++++------------ qobject/qlit.c | 4 ++-- tests/check-qjson.c | 40 ++++++++++++++++++++-------------------- 3 files changed, 34 insertions(+), 34 deletions(-) diff --git a/include/qapi/qmp/qlit.h b/include/qapi/qmp/qlit.h index 280db5064a..a4ad91321b 100644 --- a/include/qapi/qmp/qlit.h +++ b/include/qapi/qmp/qlit.h @@ -17,33 +17,33 @@ #include "qapi-types.h" #include "qobject.h" =20 -typedef struct LiteralQDictEntry LiteralQDictEntry; -typedef struct LiteralQObject LiteralQObject; +typedef struct QLitDictEntry QLitDictEntry; +typedef struct QLitObject QLitObject; =20 -struct LiteralQObject { +struct QLitObject { int type; union { int64_t qnum; const char *qstr; - LiteralQDictEntry *qdict; - LiteralQObject *qlist; + QLitDictEntry *qdict; + QLitObject *qlist; } value; }; =20 -struct LiteralQDictEntry { +struct QLitDictEntry { const char *key; - LiteralQObject value; + QLitObject value; }; =20 #define QLIT_QNUM(val) \ - (LiteralQObject){.type =3D QTYPE_QNUM, .value.qnum =3D (val)} + (QLitObject){.type =3D QTYPE_QNUM, .value.qnum =3D (val)} #define QLIT_QSTR(val) \ - (LiteralQObject){.type =3D QTYPE_QSTRING, .value.qstr =3D (val)} + (QLitObject){.type =3D QTYPE_QSTRING, .value.qstr =3D (val)} #define QLIT_QDICT(val) \ - (LiteralQObject){.type =3D QTYPE_QDICT, .value.qdict =3D (val)} + (QLitObject){.type =3D QTYPE_QDICT, .value.qdict =3D (val)} #define QLIT_QLIST(val) \ - (LiteralQObject){.type =3D QTYPE_QLIST, .value.qlist =3D (val)} + (QLitObject){.type =3D QTYPE_QLIST, .value.qlist =3D (val)} =20 -int compare_litqobj_to_qobj(LiteralQObject *lhs, QObject *rhs); +int compare_litqobj_to_qobj(QLitObject *lhs, QObject *rhs); =20 #endif /* QLIT_H */ diff --git a/qobject/qlit.c b/qobject/qlit.c index 5917c3584e..262d64988d 100644 --- a/qobject/qlit.c +++ b/qobject/qlit.c @@ -20,7 +20,7 @@ =20 typedef struct QListCompareHelper { int index; - LiteralQObject *objs; + QLitObject *objs; int result; } QListCompareHelper; =20 @@ -41,7 +41,7 @@ static void compare_helper(QObject *obj, void *opaque) compare_litqobj_to_qobj(&helper->objs[helper->index++], obj); } =20 -int compare_litqobj_to_qobj(LiteralQObject *lhs, QObject *rhs) +int compare_litqobj_to_qobj(QLitObject *lhs, QObject *rhs) { int64_t val; =20 diff --git a/tests/check-qjson.c b/tests/check-qjson.c index 525f79e60b..82b3681327 100644 --- a/tests/check-qjson.c +++ b/tests/check-qjson.c @@ -1065,23 +1065,23 @@ static void simple_dict(void) int i; struct { const char *encoded; - LiteralQObject decoded; + QLitObject decoded; } test_cases[] =3D { { .encoded =3D "{\"foo\": 42, \"bar\": \"hello world\"}", - .decoded =3D QLIT_QDICT(((LiteralQDictEntry[]){ + .decoded =3D QLIT_QDICT(((QLitDictEntry[]){ { "foo", QLIT_QNUM(42) }, { "bar", QLIT_QSTR("hello world") }, { } })), }, { .encoded =3D "{}", - .decoded =3D QLIT_QDICT(((LiteralQDictEntry[]){ + .decoded =3D QLIT_QDICT(((QLitDictEntry[]){ { } })), }, { .encoded =3D "{\"foo\": 43}", - .decoded =3D QLIT_QDICT(((LiteralQDictEntry[]){ + .decoded =3D QLIT_QDICT(((QLitDictEntry[]){ { "foo", QLIT_QNUM(43) }, { } })), @@ -1163,11 +1163,11 @@ static void simple_list(void) int i; struct { const char *encoded; - LiteralQObject decoded; + QLitObject decoded; } test_cases[] =3D { { .encoded =3D "[43,42]", - .decoded =3D QLIT_QLIST(((LiteralQObject[]){ + .decoded =3D QLIT_QLIST(((QLitObject[]){ QLIT_QNUM(43), QLIT_QNUM(42), { } @@ -1175,21 +1175,21 @@ static void simple_list(void) }, { .encoded =3D "[43]", - .decoded =3D QLIT_QLIST(((LiteralQObject[]){ + .decoded =3D QLIT_QLIST(((QLitObject[]){ QLIT_QNUM(43), { } })), }, { .encoded =3D "[]", - .decoded =3D QLIT_QLIST(((LiteralQObject[]){ + .decoded =3D QLIT_QLIST(((QLitObject[]){ { } })), }, { .encoded =3D "[{}]", - .decoded =3D QLIT_QLIST(((LiteralQObject[]){ - QLIT_QDICT(((LiteralQDictEntry[]){ + .decoded =3D QLIT_QLIST(((QLitObject[]){ + QLIT_QDICT(((QLitDictEntry[]){ {}, })), {}, @@ -1220,11 +1220,11 @@ static void simple_whitespace(void) int i; struct { const char *encoded; - LiteralQObject decoded; + QLitObject decoded; } test_cases[] =3D { { .encoded =3D " [ 43 , 42 ]", - .decoded =3D QLIT_QLIST(((LiteralQObject[]){ + .decoded =3D QLIT_QLIST(((QLitObject[]){ QLIT_QNUM(43), QLIT_QNUM(42), { } @@ -1232,12 +1232,12 @@ static void simple_whitespace(void) }, { .encoded =3D " [ 43 , { 'h' : 'b' }, [ ], 42 ]", - .decoded =3D QLIT_QLIST(((LiteralQObject[]){ + .decoded =3D QLIT_QLIST(((QLitObject[]){ QLIT_QNUM(43), - QLIT_QDICT(((LiteralQDictEntry[]){ + QLIT_QDICT(((QLitDictEntry[]){ { "h", QLIT_QSTR("b") }, { }})), - QLIT_QLIST(((LiteralQObject[]){ + QLIT_QLIST(((QLitObject[]){ { }})), QLIT_QNUM(42), { } @@ -1245,13 +1245,13 @@ static void simple_whitespace(void) }, { .encoded =3D " [ 43 , { 'h' : 'b' , 'a' : 32 }, [ ], 42 ]", - .decoded =3D QLIT_QLIST(((LiteralQObject[]){ + .decoded =3D QLIT_QLIST(((QLitObject[]){ QLIT_QNUM(43), - QLIT_QDICT(((LiteralQDictEntry[]){ + QLIT_QDICT(((QLitDictEntry[]){ { "h", QLIT_QSTR("b") }, { "a", QLIT_QNUM(32) }, { }})), - QLIT_QLIST(((LiteralQObject[]){ + QLIT_QLIST(((QLitObject[]){ { }})), QLIT_QNUM(42), { } @@ -1282,10 +1282,10 @@ static void simple_varargs(void) { QObject *embedded_obj; QObject *obj; - LiteralQObject decoded =3D QLIT_QLIST(((LiteralQObject[]){ + QLitObject decoded =3D QLIT_QLIST(((QLitObject[]){ QLIT_QNUM(1), QLIT_QNUM(2), - QLIT_QLIST(((LiteralQObject[]){ + QLIT_QLIST(((QLitObject[]){ QLIT_QNUM(32), QLIT_QNUM(42), {}})), --=20 2.14.1.146.gd35faa819 From nobody Thu May 2 20:19:12 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.zohomail.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 1503658918670816.3643248842259; Fri, 25 Aug 2017 04:01:58 -0700 (PDT) Received: from localhost ([::1]:52477 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dlCNB-0001EG-Cl for importer@patchew.org; Fri, 25 Aug 2017 07:01:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46919) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dlCL7-0007RD-38 for qemu-devel@nongnu.org; Fri, 25 Aug 2017 06:59:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dlCL6-0004uj-A6 for qemu-devel@nongnu.org; Fri, 25 Aug 2017 06:59:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59704) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dlCL6-0004uH-4R for qemu-devel@nongnu.org; Fri, 25 Aug 2017 06:59:48 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 067F47EA9A for ; Fri, 25 Aug 2017 10:59:47 +0000 (UTC) Received: from localhost (ovpn-112-49.ams2.redhat.com [10.36.112.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6CA7B7B9DF; Fri, 25 Aug 2017 10:59:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 067F47EA9A Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Fri, 25 Aug 2017 12:59:03 +0200 Message-Id: <20170825105913.4060-5-marcandre.lureau@redhat.com> In-Reply-To: <20170825105913.4060-1-marcandre.lureau@redhat.com> References: <20170825105913.4060-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 25 Aug 2017 10:59:47 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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 v2 04/14] qlit: remove compound literals 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: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" They are not considered constant expressions in C, producing an error when compiling a const QLit. Signed-off-by: Marc-Andr=C3=A9 Lureau --- include/qapi/qmp/qlit.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/qapi/qmp/qlit.h b/include/qapi/qmp/qlit.h index a4ad91321b..f1d6eed317 100644 --- a/include/qapi/qmp/qlit.h +++ b/include/qapi/qmp/qlit.h @@ -36,13 +36,13 @@ struct QLitDictEntry { }; =20 #define QLIT_QNUM(val) \ - (QLitObject){.type =3D QTYPE_QNUM, .value.qnum =3D (val)} + { .type =3D QTYPE_QNUM, .value.qnum =3D (val) } #define QLIT_QSTR(val) \ - (QLitObject){.type =3D QTYPE_QSTRING, .value.qstr =3D (val)} + { .type =3D QTYPE_QSTRING, .value.qstr =3D (val) } #define QLIT_QDICT(val) \ - (QLitObject){.type =3D QTYPE_QDICT, .value.qdict =3D (val)} + { .type =3D QTYPE_QDICT, .value.qdict =3D (val) } #define QLIT_QLIST(val) \ - (QLitObject){.type =3D QTYPE_QLIST, .value.qlist =3D (val)} + { .type =3D QTYPE_QLIST, .value.qlist =3D (val) } =20 int compare_litqobj_to_qobj(QLitObject *lhs, QObject *rhs); =20 --=20 2.14.1.146.gd35faa819 From nobody Thu May 2 20:19:12 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.zohomail.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 1503659530585677.8768102265407; Fri, 25 Aug 2017 04:12:10 -0700 (PDT) Received: from localhost ([::1]:52528 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dlCX3-0001ao-BU for importer@patchew.org; Fri, 25 Aug 2017 07:12:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46986) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dlCLD-0007WI-Jv for qemu-devel@nongnu.org; Fri, 25 Aug 2017 06:59:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dlCLC-0004xD-Ln for qemu-devel@nongnu.org; Fri, 25 Aug 2017 06:59:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:30294) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dlCLB-0004wX-VI for qemu-devel@nongnu.org; Fri, 25 Aug 2017 06:59:54 -0400 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 mx1.redhat.com (Postfix) with ESMTPS id CE2B8285C1 for ; Fri, 25 Aug 2017 10:59:52 +0000 (UTC) Received: from localhost (ovpn-112-49.ams2.redhat.com [10.36.112.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id A243E4D734; Fri, 25 Aug 2017 10:59:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CE2B8285C1 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Fri, 25 Aug 2017 12:59:04 +0200 Message-Id: <20170825105913.4060-6-marcandre.lureau@redhat.com> In-Reply-To: <20170825105913.4060-1-marcandre.lureau@redhat.com> References: <20170825105913.4060-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 25 Aug 2017 10:59:52 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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 v2 05/14] qlit: rename compare_litqobj_to_qobj() to qlit_equal_qobject() 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: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" compare_litqobj_to_qobj() lacks a qlit_ prefix. Moreover, "compare" suggests -1, 0, +1 for less than, equal and greater than. The function actually returns non-zero for equal, zero for unequal. Rename to qlit_equal_qobject(). Its return type will be cleaned up in the next patch. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Markus Armbruster --- include/qapi/qmp/qlit.h | 2 +- qobject/qlit.c | 6 +++--- tests/check-qjson.c | 14 +++++++------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/include/qapi/qmp/qlit.h b/include/qapi/qmp/qlit.h index f1d6eed317..5a180477c8 100644 --- a/include/qapi/qmp/qlit.h +++ b/include/qapi/qmp/qlit.h @@ -44,6 +44,6 @@ struct QLitDictEntry { #define QLIT_QLIST(val) \ { .type =3D QTYPE_QLIST, .value.qlist =3D (val) } =20 -int compare_litqobj_to_qobj(QLitObject *lhs, QObject *rhs); +int qlit_equal_qobject(QLitObject *lhs, QObject *rhs); =20 #endif /* QLIT_H */ diff --git a/qobject/qlit.c b/qobject/qlit.c index 262d64988d..0c4101898d 100644 --- a/qobject/qlit.c +++ b/qobject/qlit.c @@ -38,10 +38,10 @@ static void compare_helper(QObject *obj, void *opaque) } =20 helper->result =3D - compare_litqobj_to_qobj(&helper->objs[helper->index++], obj); + qlit_equal_qobject(&helper->objs[helper->index++], obj); } =20 -int compare_litqobj_to_qobj(QLitObject *lhs, QObject *rhs) +int qlit_equal_qobject(QLitObject *lhs, QObject *rhs) { int64_t val; =20 @@ -63,7 +63,7 @@ int compare_litqobj_to_qobj(QLitObject *lhs, QObject *rhs) QObject *obj =3D qdict_get(qobject_to_qdict(rhs), lhs->value.qdict[i].key); =20 - if (!compare_litqobj_to_qobj(&lhs->value.qdict[i].value, obj))= { + if (!qlit_equal_qobject(&lhs->value.qdict[i].value, obj)) { return 0; } } diff --git a/tests/check-qjson.c b/tests/check-qjson.c index 82b3681327..e5ca273cbc 100644 --- a/tests/check-qjson.c +++ b/tests/check-qjson.c @@ -1094,13 +1094,13 @@ static void simple_dict(void) QString *str; =20 obj =3D qobject_from_json(test_cases[i].encoded, &error_abort); - g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) =3D= =3D 1); + g_assert(qlit_equal_qobject(&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), &error_abort); - g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) =3D= =3D 1); + g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj) =3D=3D 1); qobject_decref(obj); QDECREF(str); } @@ -1203,13 +1203,13 @@ static void simple_list(void) QString *str; =20 obj =3D qobject_from_json(test_cases[i].encoded, &error_abort); - g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) =3D= =3D 1); + g_assert(qlit_equal_qobject(&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), &error_abort); - g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) =3D= =3D 1); + g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj) =3D=3D 1); qobject_decref(obj); QDECREF(str); } @@ -1265,13 +1265,13 @@ static void simple_whitespace(void) QString *str; =20 obj =3D qobject_from_json(test_cases[i].encoded, &error_abort); - g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) =3D= =3D 1); + g_assert(qlit_equal_qobject(&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), &error_abort); - g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) =3D= =3D 1); + g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj) =3D=3D 1); =20 qobject_decref(obj); QDECREF(str); @@ -1295,7 +1295,7 @@ 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(compare_litqobj_to_qobj(&decoded, obj) =3D=3D 1); + g_assert(qlit_equal_qobject(&decoded, obj) =3D=3D 1); =20 qobject_decref(obj); } --=20 2.14.1.146.gd35faa819 From nobody Thu May 2 20:19:12 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.zohomail.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 1503658920534468.07050058411664; Fri, 25 Aug 2017 04:02:00 -0700 (PDT) Received: from localhost ([::1]:52478 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dlCND-0001GG-8Y for importer@patchew.org; Fri, 25 Aug 2017 07:01:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47020) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dlCLF-0007aM-Va for qemu-devel@nongnu.org; Fri, 25 Aug 2017 06:59:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dlCLF-0004yK-0K for qemu-devel@nongnu.org; Fri, 25 Aug 2017 06:59:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42014) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dlCLE-0004y3-NU for qemu-devel@nongnu.org; Fri, 25 Aug 2017 06:59:56 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9FD077DD05 for ; Fri, 25 Aug 2017 10:59:55 +0000 (UTC) Received: from localhost (ovpn-112-49.ams2.redhat.com [10.36.112.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id C0B657BAE0; Fri, 25 Aug 2017 10:59:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9FD077DD05 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Fri, 25 Aug 2017 12:59:05 +0200 Message-Id: <20170825105913.4060-7-marcandre.lureau@redhat.com> In-Reply-To: <20170825105913.4060-1-marcandre.lureau@redhat.com> References: <20170825105913.4060-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 25 Aug 2017 10:59:55 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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 v2 06/14] qlit: make qlit_equal_qobject return a bool 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: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Make it more obvious about the expected return values. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Markus Armbruster --- include/qapi/qmp/qlit.h | 2 +- qobject/qlit.c | 18 +++++++++--------- tests/check-qjson.c | 14 +++++++------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/include/qapi/qmp/qlit.h b/include/qapi/qmp/qlit.h index 5a180477c8..35aabbdc9f 100644 --- a/include/qapi/qmp/qlit.h +++ b/include/qapi/qmp/qlit.h @@ -44,6 +44,6 @@ struct QLitDictEntry { #define QLIT_QLIST(val) \ { .type =3D QTYPE_QLIST, .value.qlist =3D (val) } =20 -int qlit_equal_qobject(QLitObject *lhs, QObject *rhs); +bool qlit_equal_qobject(QLitObject *lhs, QObject *rhs); =20 #endif /* QLIT_H */ diff --git a/qobject/qlit.c b/qobject/qlit.c index 0c4101898d..a2975bef3f 100644 --- a/qobject/qlit.c +++ b/qobject/qlit.c @@ -21,19 +21,19 @@ typedef struct QListCompareHelper { int index; QLitObject *objs; - int result; + bool result; } QListCompareHelper; =20 static void compare_helper(QObject *obj, void *opaque) { QListCompareHelper *helper =3D opaque; =20 - if (helper->result =3D=3D 0) { + if (!helper->result) { return; } =20 if (helper->objs[helper->index].type =3D=3D QTYPE_NONE) { - helper->result =3D 0; + helper->result =3D false; return; } =20 @@ -41,12 +41,12 @@ static void compare_helper(QObject *obj, void *opaque) qlit_equal_qobject(&helper->objs[helper->index++], obj); } =20 -int qlit_equal_qobject(QLitObject *lhs, QObject *rhs) +bool qlit_equal_qobject(QLitObject *lhs, QObject *rhs) { int64_t val; =20 if (!rhs || lhs->type !=3D qobject_type(rhs)) { - return 0; + return false; } =20 switch (lhs->type) { @@ -64,18 +64,18 @@ int qlit_equal_qobject(QLitObject *lhs, QObject *rhs) lhs->value.qdict[i].key); =20 if (!qlit_equal_qobject(&lhs->value.qdict[i].value, obj)) { - return 0; + return false; } } =20 - return 1; + return true; } case QTYPE_QLIST: { QListCompareHelper helper; =20 helper.index =3D 0; helper.objs =3D lhs->value.qlist; - helper.result =3D 1; + helper.result =3D true; =20 qlist_iter(qobject_to_qlist(rhs), compare_helper, &helper); =20 @@ -85,5 +85,5 @@ int qlit_equal_qobject(QLitObject *lhs, QObject *rhs) break; } =20 - return 0; + return false; } diff --git a/tests/check-qjson.c b/tests/check-qjson.c index e5ca273cbc..59227934ce 100644 --- a/tests/check-qjson.c +++ b/tests/check-qjson.c @@ -1094,13 +1094,13 @@ static void simple_dict(void) QString *str; =20 obj =3D qobject_from_json(test_cases[i].encoded, &error_abort); - g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj) =3D=3D 1); + g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj)); =20 str =3D qobject_to_json(obj); qobject_decref(obj); =20 obj =3D qobject_from_json(qstring_get_str(str), &error_abort); - g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj) =3D=3D 1); + g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj)); qobject_decref(obj); QDECREF(str); } @@ -1203,13 +1203,13 @@ static void simple_list(void) QString *str; =20 obj =3D qobject_from_json(test_cases[i].encoded, &error_abort); - g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj) =3D=3D 1); + g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj)); =20 str =3D qobject_to_json(obj); qobject_decref(obj); =20 obj =3D qobject_from_json(qstring_get_str(str), &error_abort); - g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj) =3D=3D 1); + g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj)); qobject_decref(obj); QDECREF(str); } @@ -1265,13 +1265,13 @@ static void simple_whitespace(void) QString *str; =20 obj =3D qobject_from_json(test_cases[i].encoded, &error_abort); - g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj) =3D=3D 1); + g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj)); =20 str =3D qobject_to_json(obj); qobject_decref(obj); =20 obj =3D qobject_from_json(qstring_get_str(str), &error_abort); - g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj) =3D=3D 1); + g_assert(qlit_equal_qobject(&test_cases[i].decoded, obj)); =20 qobject_decref(obj); QDECREF(str); @@ -1295,7 +1295,7 @@ 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(qlit_equal_qobject(&decoded, obj) =3D=3D 1); + g_assert(qlit_equal_qobject(&decoded, obj)); =20 qobject_decref(obj); } --=20 2.14.1.146.gd35faa819 From nobody Thu May 2 20:19:12 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.zohomail.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 1503659097974578.0731425627347; Fri, 25 Aug 2017 04:04:57 -0700 (PDT) Received: from localhost ([::1]:52486 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dlCQ4-0003fX-IZ for importer@patchew.org; Fri, 25 Aug 2017 07:04:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47049) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dlCLH-0007bF-O6 for qemu-devel@nongnu.org; Fri, 25 Aug 2017 07:00:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dlCLH-0004zC-1o for qemu-devel@nongnu.org; Fri, 25 Aug 2017 06:59:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60538) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dlCLG-0004yo-Rt for qemu-devel@nongnu.org; Fri, 25 Aug 2017 06:59:58 -0400 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 mx1.redhat.com (Postfix) with ESMTPS id C4FC17CDE7 for ; Fri, 25 Aug 2017 10:59:57 +0000 (UTC) Received: from localhost (ovpn-112-49.ams2.redhat.com [10.36.112.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4D21F6932C; Fri, 25 Aug 2017 10:59:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C4FC17CDE7 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Fri, 25 Aug 2017 12:59:06 +0200 Message-Id: <20170825105913.4060-8-marcandre.lureau@redhat.com> In-Reply-To: <20170825105913.4060-1-marcandre.lureau@redhat.com> References: <20170825105913.4060-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 25 Aug 2017 10:59:57 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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 v2 07/14] qlit: make qlit_equal_qobject() take const arguments 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: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Markus Armbruster --- include/qapi/qmp/qlit.h | 2 +- qobject/qlit.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/qapi/qmp/qlit.h b/include/qapi/qmp/qlit.h index 35aabbdc9f..fc1a2d845d 100644 --- a/include/qapi/qmp/qlit.h +++ b/include/qapi/qmp/qlit.h @@ -44,6 +44,6 @@ struct QLitDictEntry { #define QLIT_QLIST(val) \ { .type =3D QTYPE_QLIST, .value.qlist =3D (val) } =20 -bool qlit_equal_qobject(QLitObject *lhs, QObject *rhs); +bool qlit_equal_qobject(const QLitObject *lhs, const QObject *rhs); =20 #endif /* QLIT_H */ diff --git a/qobject/qlit.c b/qobject/qlit.c index a2975bef3f..ae2787ef35 100644 --- a/qobject/qlit.c +++ b/qobject/qlit.c @@ -41,7 +41,7 @@ static void compare_helper(QObject *obj, void *opaque) qlit_equal_qobject(&helper->objs[helper->index++], obj); } =20 -bool qlit_equal_qobject(QLitObject *lhs, QObject *rhs) +bool qlit_equal_qobject(const QLitObject *lhs, const QObject *rhs) { int64_t val; =20 --=20 2.14.1.146.gd35faa819 From nobody Thu May 2 20:19:12 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.zohomail.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 1503658938843940.0578020400271; Fri, 25 Aug 2017 04:02:18 -0700 (PDT) Received: from localhost ([::1]:52479 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dlCNV-0001Qo-Mb for importer@patchew.org; Fri, 25 Aug 2017 07:02:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47118) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dlCLQ-00085l-NH for qemu-devel@nongnu.org; Fri, 25 Aug 2017 07:00:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dlCLL-000518-2z for qemu-devel@nongnu.org; Fri, 25 Aug 2017 07:00:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35784) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dlCLK-00050p-Sp for qemu-devel@nongnu.org; Fri, 25 Aug 2017 07:00:03 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CD92CC047B68 for ; Fri, 25 Aug 2017 11:00:01 +0000 (UTC) Received: from localhost (ovpn-112-49.ams2.redhat.com [10.36.112.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4C3395D6A0; Fri, 25 Aug 2017 10:59:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CD92CC047B68 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Fri, 25 Aug 2017 12:59:07 +0200 Message-Id: <20170825105913.4060-9-marcandre.lureau@redhat.com> In-Reply-To: <20170825105913.4060-1-marcandre.lureau@redhat.com> References: <20170825105913.4060-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 25 Aug 2017 11:00:01 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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 v2 08/14] qlit: add QLIT_QNULL and QLIT_BOOL 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: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" As they are going to be used in the following patches. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Markus Armbruster --- include/qapi/qmp/qlit.h | 5 +++++ qobject/qlit.c | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/include/qapi/qmp/qlit.h b/include/qapi/qmp/qlit.h index fc1a2d845d..b18406bce9 100644 --- a/include/qapi/qmp/qlit.h +++ b/include/qapi/qmp/qlit.h @@ -23,6 +23,7 @@ typedef struct QLitObject QLitObject; struct QLitObject { int type; union { + bool qbool; int64_t qnum; const char *qstr; QLitDictEntry *qdict; @@ -35,6 +36,10 @@ struct QLitDictEntry { QLitObject value; }; =20 +#define QLIT_QNULL \ + { .type =3D QTYPE_QNULL } +#define QLIT_QBOOL(val) \ + { .type =3D QTYPE_QBOOL, .value.qbool =3D (val) } #define QLIT_QNUM(val) \ { .type =3D QTYPE_QNUM, .value.qnum =3D (val) } #define QLIT_QSTR(val) \ diff --git a/qobject/qlit.c b/qobject/qlit.c index ae2787ef35..07ad6b05e8 100644 --- a/qobject/qlit.c +++ b/qobject/qlit.c @@ -50,6 +50,8 @@ bool qlit_equal_qobject(const QLitObject *lhs, const QObj= ect *rhs) } =20 switch (lhs->type) { + case QTYPE_QBOOL: + return lhs->value.qbool =3D=3D qbool_get_bool(qobject_to_qbool(rhs= )); case QTYPE_QNUM: g_assert(qnum_get_try_int(qobject_to_qnum(rhs), &val)); return lhs->value.qnum =3D=3D val; @@ -81,6 +83,8 @@ bool qlit_equal_qobject(const QLitObject *lhs, const QObj= ect *rhs) =20 return helper.result; } + case QTYPE_QNULL: + return true; default: break; } --=20 2.14.1.146.gd35faa819 From nobody Thu May 2 20:19:12 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.zohomail.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 1503659096136748.2753209910752; Fri, 25 Aug 2017 04:04:56 -0700 (PDT) Received: from localhost ([::1]:52485 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dlCQ3-0003eE-2C for importer@patchew.org; Fri, 25 Aug 2017 07:04:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47154) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dlCLX-0008Tv-HM for qemu-devel@nongnu.org; Fri, 25 Aug 2017 07:00:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dlCLT-00058W-10 for qemu-devel@nongnu.org; Fri, 25 Aug 2017 07:00:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32866) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dlCLS-00057p-S1 for qemu-devel@nongnu.org; Fri, 25 Aug 2017 07:00:10 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C5BB380462 for ; Fri, 25 Aug 2017 11:00:09 +0000 (UTC) Received: from localhost (ovpn-112-49.ams2.redhat.com [10.36.112.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 31D2A7B9D2; Fri, 25 Aug 2017 11:00:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C5BB380462 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Fri, 25 Aug 2017 12:59:08 +0200 Message-Id: <20170825105913.4060-10-marcandre.lureau@redhat.com> In-Reply-To: <20170825105913.4060-1-marcandre.lureau@redhat.com> References: <20170825105913.4060-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 25 Aug 2017 11:00:09 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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 v2 09/14] qlit: Replace open-coded qnum_get_int() by call 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: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Bonus: rids us of a side effect in an assertion. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Markus Armbruster --- qobject/qlit.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/qobject/qlit.c b/qobject/qlit.c index 07ad6b05e8..b1d9146220 100644 --- a/qobject/qlit.c +++ b/qobject/qlit.c @@ -43,8 +43,6 @@ static void compare_helper(QObject *obj, void *opaque) =20 bool qlit_equal_qobject(const QLitObject *lhs, const QObject *rhs) { - int64_t val; - if (!rhs || lhs->type !=3D qobject_type(rhs)) { return false; } @@ -53,8 +51,7 @@ bool qlit_equal_qobject(const QLitObject *lhs, const QObj= ect *rhs) case QTYPE_QBOOL: return lhs->value.qbool =3D=3D qbool_get_bool(qobject_to_qbool(rhs= )); case QTYPE_QNUM: - g_assert(qnum_get_try_int(qobject_to_qnum(rhs), &val)); - return lhs->value.qnum =3D=3D val; + return lhs->value.qnum =3D=3D qnum_get_int(qobject_to_qnum(rhs)); case QTYPE_QSTRING: return (strcmp(lhs->value.qstr, qstring_get_str(qobject_to_qstring(rhs))) =3D=3D 0); --=20 2.14.1.146.gd35faa819 From nobody Thu May 2 20:19:12 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.zohomail.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 1503659641427251.3296827507794; Fri, 25 Aug 2017 04:14:01 -0700 (PDT) Received: from localhost ([::1]:52539 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dlCYq-00032t-9O for importer@patchew.org; Fri, 25 Aug 2017 07:14:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47174) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dlCLb-00005z-Oc for qemu-devel@nongnu.org; Fri, 25 Aug 2017 07:00:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dlCLZ-0005Al-E8 for qemu-devel@nongnu.org; Fri, 25 Aug 2017 07:00:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36852) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dlCLZ-0005AS-4V for qemu-devel@nongnu.org; Fri, 25 Aug 2017 07:00:17 -0400 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 mx1.redhat.com (Postfix) with ESMTPS id 0D46881E11 for ; Fri, 25 Aug 2017 11:00:16 +0000 (UTC) Received: from localhost (ovpn-112-49.ams2.redhat.com [10.36.112.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1A50469313; Fri, 25 Aug 2017 11:00:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0D46881E11 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Fri, 25 Aug 2017 12:59:09 +0200 Message-Id: <20170825105913.4060-11-marcandre.lureau@redhat.com> In-Reply-To: <20170825105913.4060-1-marcandre.lureau@redhat.com> References: <20170825105913.4060-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 25 Aug 2017 11:00:16 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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 v2 10/14] tests: add qlit tests 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: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Marc-Andr=C3=A9 Lureau --- tests/check-qlit.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++= ++++ tests/Makefile.include | 5 +++- 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 tests/check-qlit.c diff --git a/tests/check-qlit.c b/tests/check-qlit.c new file mode 100644 index 0000000000..47fde92a46 --- /dev/null +++ b/tests/check-qlit.c @@ -0,0 +1,64 @@ +/* + * QLit unit-tests. + * + * Copyright (C) 2017 Red Hat Inc. + * + * This work is licensed under the terms of the GNU LGPL, version 2.1 or l= ater. + * See the COPYING.LIB file in the top-level directory. + */ + +#include "qemu/osdep.h" + +#include "qapi/qmp/qbool.h" +#include "qapi/qmp/qdict.h" +#include "qapi/qmp/qlit.h" +#include "qapi/qmp/qnum.h" +#include "qapi/qmp/qstring.h" + +static QLitObject qlit =3D QLIT_QDICT(((QLitDictEntry[]) { + { "foo", QLIT_QNUM(42) }, + { "bar", QLIT_QSTR("hello world") }, + { "baz", QLIT_QNULL }, + { "bee", QLIT_QLIST(((QLitObject[]) { + QLIT_QNUM(43), + QLIT_QNUM(44), + QLIT_QBOOL(true), + { }, + }))}, + { }, +})); + +static QObject *make_qobject(void) +{ + QDict *qdict =3D qdict_new(); + QList *list =3D qlist_new(); + + qdict_put_int(qdict, "foo", 42); + qdict_put_str(qdict, "bar", "hello world"); + qdict_put_null(qdict, "baz"); + + qlist_append_int(list, 43); + qlist_append_int(list, 44); + qlist_append_bool(list, true); + qdict_put(qdict, "bee", list); + + return QOBJECT(qdict); +} + +static void qlit_equal_qobject_test(void) +{ + QObject *qobj =3D make_qobject(); + + g_assert(qlit_equal_qobject(&qlit, qobj)); + + qobject_decref(qobj); +} + +int main(int argc, char **argv) +{ + g_test_init(&argc, &argv, NULL); + + g_test_add_func("/qlit/equal_qobject", qlit_equal_qobject_test); + + return g_test_run(); +} diff --git a/tests/Makefile.include b/tests/Makefile.include index 37c1bed683..3653c7b40a 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -43,6 +43,8 @@ check-unit-y +=3D tests/check-qnull$(EXESUF) gcov-files-check-qnull-y =3D qobject/qnull.c check-unit-y +=3D tests/check-qjson$(EXESUF) gcov-files-check-qjson-y =3D qobject/qjson.c +check-unit-y +=3D tests/check-qlit$(EXESUF) +gcov-files-check-qlit-y =3D qobject/qlit.c check-unit-y +=3D tests/test-qobject-output-visitor$(EXESUF) gcov-files-test-qobject-output-visitor-y =3D qapi/qobject-output-visitor.c check-unit-y +=3D tests/test-clone-visitor$(EXESUF) @@ -535,7 +537,7 @@ GENERATED_FILES +=3D tests/test-qapi-types.h tests/test= -qapi-visit.h \ =20 test-obj-y =3D tests/check-qnum.o tests/check-qstring.o tests/check-qdict.= o \ tests/check-qlist.o tests/check-qnull.o \ - tests/check-qjson.o \ + tests/check-qjson.o tests/check-qlit.o \ tests/test-coroutine.o tests/test-string-output-visitor.o \ tests/test-string-input-visitor.o tests/test-qobject-output-visitor.o \ tests/test-clone-visitor.o \ @@ -569,6 +571,7 @@ tests/check-qdict$(EXESUF): tests/check-qdict.o $(test-= util-obj-y) tests/check-qlist$(EXESUF): tests/check-qlist.o $(test-util-obj-y) tests/check-qnull$(EXESUF): tests/check-qnull.o $(test-util-obj-y) tests/check-qjson$(EXESUF): tests/check-qjson.o $(test-util-obj-y) +tests/check-qlit$(EXESUF): tests/check-qlit.o $(test-util-obj-y) tests/check-qom-interface$(EXESUF): tests/check-qom-interface.o $(test-qom= -obj-y) tests/check-qom-proplist$(EXESUF): tests/check-qom-proplist.o $(test-qom-o= bj-y) =20 --=20 2.14.1.146.gd35faa819 From nobody Thu May 2 20:19:12 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.zohomail.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 1503659264481206.46424474974822; Fri, 25 Aug 2017 04:07:44 -0700 (PDT) Received: from localhost ([::1]:52499 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dlCSl-00062i-7d for importer@patchew.org; Fri, 25 Aug 2017 07:07:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47272) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dlCLj-0000FO-O1 for qemu-devel@nongnu.org; Fri, 25 Aug 2017 07:00:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dlCLf-0005D7-74 for qemu-devel@nongnu.org; Fri, 25 Aug 2017 07:00:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:12512) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dlCLe-0005CX-Uw for qemu-devel@nongnu.org; Fri, 25 Aug 2017 07:00:23 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D9607C056787 for ; Fri, 25 Aug 2017 11:00:21 +0000 (UTC) Received: from localhost (ovpn-112-49.ams2.redhat.com [10.36.112.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8A9336C40E; Fri, 25 Aug 2017 11:00:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D9607C056787 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Fri, 25 Aug 2017 12:59:10 +0200 Message-Id: <20170825105913.4060-12-marcandre.lureau@redhat.com> In-Reply-To: <20170825105913.4060-1-marcandre.lureau@redhat.com> References: <20170825105913.4060-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 25 Aug 2017 11:00:22 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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 v2 11/14] qlit: improve QLit dict vs qdict comparison 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: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Verify that all qdict values are covered. (a previous iteration of this patch created a copy of qdict to remove all checked elements, verifying no duplicates exist in the literal qdict, however this is a programming error, and a size comparison should be enough) Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Markus Armbruster --- qobject/qlit.c | 37 +++++++++++++++++++++++-------------- tests/check-qlit.c | 7 +++++++ 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/qobject/qlit.c b/qobject/qlit.c index b1d9146220..dc0015f76c 100644 --- a/qobject/qlit.c +++ b/qobject/qlit.c @@ -41,6 +41,27 @@ static void compare_helper(QObject *obj, void *opaque) qlit_equal_qobject(&helper->objs[helper->index++], obj); } =20 +static bool qlit_equal_qdict(const QLitObject *lhs, const QDict *qdict) +{ + int i; + + for (i =3D 0; lhs->value.qdict[i].key; i++) { + QObject *obj =3D qdict_get(qdict, lhs->value.qdict[i].key); + + if (!qlit_equal_qobject(&lhs->value.qdict[i].value, obj)) { + return false; + } + } + + /* Note: the literal qdict must not contain duplicates, this is + * considered a programming error and it isn't checked here. */ + if (qdict_size(qdict) !=3D i) { + return false; + } + + return true; +} + bool qlit_equal_qobject(const QLitObject *lhs, const QObject *rhs) { if (!rhs || lhs->type !=3D qobject_type(rhs)) { @@ -55,20 +76,8 @@ bool qlit_equal_qobject(const QLitObject *lhs, const QOb= ject *rhs) case QTYPE_QSTRING: return (strcmp(lhs->value.qstr, qstring_get_str(qobject_to_qstring(rhs))) =3D=3D 0); - case QTYPE_QDICT: { - int i; - - for (i =3D 0; lhs->value.qdict[i].key; i++) { - QObject *obj =3D qdict_get(qobject_to_qdict(rhs), - lhs->value.qdict[i].key); - - if (!qlit_equal_qobject(&lhs->value.qdict[i].value, obj)) { - return false; - } - } - - return true; - } + case QTYPE_QDICT: + return qlit_equal_qdict(lhs, qobject_to_qdict(rhs)); case QTYPE_QLIST: { QListCompareHelper helper; =20 diff --git a/tests/check-qlit.c b/tests/check-qlit.c index 47fde92a46..5d9558dfd9 100644 --- a/tests/check-qlit.c +++ b/tests/check-qlit.c @@ -28,6 +28,11 @@ static QLitObject qlit =3D QLIT_QDICT(((QLitDictEntry[])= { { }, })); =20 +static QLitObject qlit_foo =3D QLIT_QDICT(((QLitDictEntry[]) { + { "foo", QLIT_QNUM(42) }, + { }, +})); + static QObject *make_qobject(void) { QDict *qdict =3D qdict_new(); @@ -51,6 +56,8 @@ static void qlit_equal_qobject_test(void) =20 g_assert(qlit_equal_qobject(&qlit, qobj)); =20 + g_assert(!qlit_equal_qobject(&qlit_foo, qobj)); + qobject_decref(qobj); } =20 --=20 2.14.1.146.gd35faa819 From nobody Thu May 2 20:19:12 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.zohomail.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 1503659113708920.9304414764977; Fri, 25 Aug 2017 04:05:13 -0700 (PDT) Received: from localhost ([::1]:52487 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dlCQK-0003qa-F0 for importer@patchew.org; Fri, 25 Aug 2017 07:05:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47339) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dlCLp-0000Ht-1Z for qemu-devel@nongnu.org; Fri, 25 Aug 2017 07:00:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dlCLj-0005H5-8I for qemu-devel@nongnu.org; Fri, 25 Aug 2017 07:00:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35936) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dlCLi-0005GC-Vu for qemu-devel@nongnu.org; Fri, 25 Aug 2017 07:00:27 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DF9F04A6EB for ; Fri, 25 Aug 2017 11:00:25 +0000 (UTC) Received: from localhost (ovpn-112-49.ams2.redhat.com [10.36.112.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 421B27EE70; Fri, 25 Aug 2017 11:00:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com DF9F04A6EB Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Fri, 25 Aug 2017 12:59:11 +0200 Message-Id: <20170825105913.4060-13-marcandre.lureau@redhat.com> In-Reply-To: <20170825105913.4060-1-marcandre.lureau@redhat.com> References: <20170825105913.4060-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 25 Aug 2017 11:00:26 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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 v2 12/14] qlit: improve QLit list vs qlist comparison 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: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Use QLIST_FOREACH_ENTRY() to simplify the code and break earlier. Check that the QLit list has the same size as the qlist, this should ensure that we have an exact match when iterating over qlist for comparing the elements. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Markus Armbruster --- qobject/qlit.c | 53 +++++++++++++++++++-------------------------------= --- tests/check-qlit.c | 3 +++ 2 files changed, 22 insertions(+), 34 deletions(-) diff --git a/qobject/qlit.c b/qobject/qlit.c index dc0015f76c..3c4882c784 100644 --- a/qobject/qlit.c +++ b/qobject/qlit.c @@ -18,29 +18,6 @@ #include "qapi/qmp/qlit.h" #include "qapi/qmp/types.h" =20 -typedef struct QListCompareHelper { - int index; - QLitObject *objs; - bool result; -} QListCompareHelper; - -static void compare_helper(QObject *obj, void *opaque) -{ - QListCompareHelper *helper =3D opaque; - - if (!helper->result) { - return; - } - - if (helper->objs[helper->index].type =3D=3D QTYPE_NONE) { - helper->result =3D false; - return; - } - - helper->result =3D - qlit_equal_qobject(&helper->objs[helper->index++], obj); -} - static bool qlit_equal_qdict(const QLitObject *lhs, const QDict *qdict) { int i; @@ -62,6 +39,23 @@ static bool qlit_equal_qdict(const QLitObject *lhs, cons= t QDict *qdict) return true; } =20 +static bool qlit_equal_qlist(const QLitObject *lhs, const QList *qlist) +{ + QListEntry *e; + int i =3D 0; + + QLIST_FOREACH_ENTRY(qlist, e) { + QObject *obj =3D qlist_entry_obj(e); + + if (!qlit_equal_qobject(&lhs->value.qlist[i], obj)) { + return false; + } + i++; + } + + return !e && lhs->value.qlist[i].type =3D=3D QTYPE_NONE; +} + bool qlit_equal_qobject(const QLitObject *lhs, const QObject *rhs) { if (!rhs || lhs->type !=3D qobject_type(rhs)) { @@ -78,17 +72,8 @@ bool qlit_equal_qobject(const QLitObject *lhs, const QOb= ject *rhs) qstring_get_str(qobject_to_qstring(rhs))) =3D=3D 0); case QTYPE_QDICT: return qlit_equal_qdict(lhs, qobject_to_qdict(rhs)); - case QTYPE_QLIST: { - QListCompareHelper helper; - - helper.index =3D 0; - helper.objs =3D lhs->value.qlist; - helper.result =3D true; - - qlist_iter(qobject_to_qlist(rhs), compare_helper, &helper); - - return helper.result; - } + case QTYPE_QLIST: + return qlit_equal_qlist(lhs, qobject_to_qlist(rhs)); case QTYPE_QNULL: return true; default: diff --git a/tests/check-qlit.c b/tests/check-qlit.c index 5d9558dfd9..ae74bfcb83 100644 --- a/tests/check-qlit.c +++ b/tests/check-qlit.c @@ -58,6 +58,9 @@ static void qlit_equal_qobject_test(void) =20 g_assert(!qlit_equal_qobject(&qlit_foo, qobj)); =20 + qdict_put(qobject_to_qdict(qobj), "bee", qlist_new()); + g_assert(!qlit_equal_qobject(&qlit, qobj)); + qobject_decref(qobj); } =20 --=20 2.14.1.146.gd35faa819 From nobody Thu May 2 20:19:12 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.zohomail.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 1503659419954567.8781776331952; Fri, 25 Aug 2017 04:10:19 -0700 (PDT) Received: from localhost ([::1]:52510 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dlCVG-0008UI-Jv for importer@patchew.org; Fri, 25 Aug 2017 07:10:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47319) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dlCLo-0000HI-5e for qemu-devel@nongnu.org; Fri, 25 Aug 2017 07:00:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dlCLl-0005I3-07 for qemu-devel@nongnu.org; Fri, 25 Aug 2017 07:00:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35986) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dlCLk-0005He-ON for qemu-devel@nongnu.org; Fri, 25 Aug 2017 07:00:28 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AA4864A6EB for ; Fri, 25 Aug 2017 11:00:27 +0000 (UTC) Received: from localhost (ovpn-112-49.ams2.redhat.com [10.36.112.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 50AD66C409; Fri, 25 Aug 2017 11:00:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com AA4864A6EB Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Fri, 25 Aug 2017 12:59:12 +0200 Message-Id: <20170825105913.4060-14-marcandre.lureau@redhat.com> In-Reply-To: <20170825105913.4060-1-marcandre.lureau@redhat.com> References: <20170825105913.4060-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 25 Aug 2017 11:00:27 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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 v2 13/14] qlit: add qobject_form_qlit() 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: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Markus Armbruster --- include/qapi/qmp/qlit.h | 2 ++ qobject/qlit.c | 37 +++++++++++++++++++++++++++++++++++++ tests/check-qlit.c | 26 ++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) diff --git a/include/qapi/qmp/qlit.h b/include/qapi/qmp/qlit.h index b18406bce9..56feb25e04 100644 --- a/include/qapi/qmp/qlit.h +++ b/include/qapi/qmp/qlit.h @@ -51,4 +51,6 @@ struct QLitDictEntry { =20 bool qlit_equal_qobject(const QLitObject *lhs, const QObject *rhs); =20 +QObject *qobject_from_qlit(const QLitObject *qlit); + #endif /* QLIT_H */ diff --git a/qobject/qlit.c b/qobject/qlit.c index 3c4882c784..e44c09e9eb 100644 --- a/qobject/qlit.c +++ b/qobject/qlit.c @@ -82,3 +82,40 @@ bool qlit_equal_qobject(const QLitObject *lhs, const QOb= ject *rhs) =20 return false; } + +QObject *qobject_from_qlit(const QLitObject *qlit) +{ + int i; + + switch (qlit->type) { + case QTYPE_QNULL: + return QOBJECT(qnull()); + case QTYPE_QNUM: + return QOBJECT(qnum_from_int(qlit->value.qnum)); + case QTYPE_QSTRING: + return QOBJECT(qstring_from_str(qlit->value.qstr)); + case QTYPE_QDICT: { + QDict *qdict =3D qdict_new(); + for (i =3D 0; qlit->value.qdict[i].value.type !=3D QTYPE_NONE; i++= ) { + QLitDictEntry *e =3D &qlit->value.qdict[i]; + + qdict_put_obj(qdict, e->key, qobject_from_qlit(&e->value)); + } + return QOBJECT(qdict); + } + case QTYPE_QLIST: { + QList *qlist =3D qlist_new(); + + for (i =3D 0; qlit->value.qlist[i].type !=3D QTYPE_NONE; i++) { + qlist_append_obj(qlist, qobject_from_qlit(&qlit->value.qlist[i= ])); + } + return QOBJECT(qlist); + } + case QTYPE_QBOOL: + return QOBJECT(qbool_from_bool(qlit->value.qbool)); + case QTYPE_NONE: + assert(0); + } + + return NULL; +} diff --git a/tests/check-qlit.c b/tests/check-qlit.c index ae74bfcb83..135a399c6d 100644 --- a/tests/check-qlit.c +++ b/tests/check-qlit.c @@ -64,11 +64,37 @@ static void qlit_equal_qobject_test(void) qobject_decref(qobj); } =20 +static void qobject_from_qlit_test(void) +{ + QObject *obj, *qobj =3D qobject_from_qlit(&qlit); + QDict *qdict; + QList *bee; + + qdict =3D qobject_to_qdict(qobj); + g_assert_cmpint(qdict_get_int(qdict, "foo"), =3D=3D, 42); + g_assert_cmpstr(qdict_get_str(qdict, "bar"), =3D=3D, "hello world"); + g_assert(qobject_type(qdict_get(qdict, "baz")) =3D=3D QTYPE_QNULL); + + bee =3D qdict_get_qlist(qdict, "bee"); + obj =3D qlist_pop(bee); + g_assert_cmpint(qnum_get_int(qobject_to_qnum(obj)), =3D=3D, 43); + qobject_decref(obj); + obj =3D qlist_pop(bee); + g_assert_cmpint(qnum_get_int(qobject_to_qnum(obj)), =3D=3D, 44); + qobject_decref(obj); + obj =3D qlist_pop(bee); + g_assert(qbool_get_bool(qobject_to_qbool(obj))); + qobject_decref(obj); + + qobject_decref(qobj); +} + int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); =20 g_test_add_func("/qlit/equal_qobject", qlit_equal_qobject_test); + g_test_add_func("/qlit/qobject_from_qlit", qobject_from_qlit_test); =20 return g_test_run(); } --=20 2.14.1.146.gd35faa819 From nobody Thu May 2 20:19:12 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.zohomail.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 1503659284424610.7071711710187; Fri, 25 Aug 2017 04:08:04 -0700 (PDT) Received: from localhost ([::1]:52501 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dlCT5-0006GP-2D for importer@patchew.org; Fri, 25 Aug 2017 07:08:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47412) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dlCLu-0000Pd-Gf for qemu-devel@nongnu.org; Fri, 25 Aug 2017 07:00:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dlCLq-0005Kp-8b for qemu-devel@nongnu.org; Fri, 25 Aug 2017 07:00:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:15364) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dlCLq-0005KC-0H for qemu-devel@nongnu.org; Fri, 25 Aug 2017 07:00:34 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E34D461468; Fri, 25 Aug 2017 11:00:32 +0000 (UTC) Received: from localhost (ovpn-112-49.ams2.redhat.com [10.36.112.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id B87577B9C6; Fri, 25 Aug 2017 11:00:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E34D461468 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Fri, 25 Aug 2017 12:59:13 +0200 Message-Id: <20170825105913.4060-15-marcandre.lureau@redhat.com> In-Reply-To: <20170825105913.4060-1-marcandre.lureau@redhat.com> References: <20170825105913.4060-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 25 Aug 2017 11:00:33 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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 v2 14/14] qapi: generate a literal qobject for introspection 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: , Cc: Michael Roth , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com, "Dr. David Alan Gilbert" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Replace the generated json string with a literal qobject. The later is easier to deal with, at run time as well as compile time: adding #if conditionals will be easier than in a json string. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Markus Armbruster --- scripts/qapi-introspect.py | 87 ++++++++++++++++++++++------------= ---- monitor.c | 2 +- tests/test-qobject-input-visitor.c | 11 +++-- docs/devel/qapi-code-gen.txt | 29 ++++++++----- 4 files changed, 78 insertions(+), 51 deletions(-) diff --git a/scripts/qapi-introspect.py b/scripts/qapi-introspect.py index 032bcea491..a157a5f91c 100644 --- a/scripts/qapi-introspect.py +++ b/scripts/qapi-introspect.py @@ -12,31 +12,41 @@ from qapi import * =20 =20 -# Caveman's json.dumps() replacement (we're stuck at Python 2.4) -# TODO try to use json.dumps() once we get unstuck -def to_json(obj, level=3D0): +def to_qlit(obj, level=3D0, suppress_first_indent=3DFalse): + + def indent(level): + return level * 4 * ' ' + + ret =3D '' + if not suppress_first_indent: + ret +=3D indent(level) if obj is None: - ret =3D 'null' + ret +=3D 'QLIT_QNULL' elif isinstance(obj, str): - ret =3D '"' + obj.replace('"', r'\"') + '"' + ret +=3D 'QLIT_QSTR(' + to_c_string(obj) + ')' elif isinstance(obj, list): - elts =3D [to_json(elt, level + 1) + elts =3D [to_qlit(elt, level + 1) for elt in obj] - ret =3D '[' + ', '.join(elts) + ']' + elts.append(indent(level + 1) + "{}") + ret +=3D 'QLIT_QLIST(((QLitObject[]) {\n' + ret +=3D ',\n'.join(elts) + '\n' + ret +=3D indent(level) + '}))' elif isinstance(obj, dict): - elts =3D ['"%s": %s' % (key.replace('"', r'\"'), - to_json(obj[key], level + 1)) - for key in sorted(obj.keys())] - ret =3D '{' + ', '.join(elts) + '}' + elts =3D [] + for key, value in sorted(obj.iteritems()): + elts.append(indent(level + 1) + '{ %s, %s }' % + (to_c_string(key), to_qlit(value, level + 1, False= ))) + elts.append(indent(level + 1) + '{}') + ret +=3D 'QLIT_QDICT(((QLitDictEntry[]) {\n' + ret +=3D ',\n'.join(elts) + '\n' + ret +=3D indent(level) + '}))' else: assert False # not implemented - if level =3D=3D 1: - ret =3D '\n' + ret return ret =20 =20 -def to_c_string(string): - return '"' + string.replace('\\', r'\\').replace('"', r'\"') + '"' +def to_c_string(s): + return '"' + s.replace('\\', r'\\').replace('"', r'\"') + '"' =20 =20 class QAPISchemaGenIntrospectVisitor(QAPISchemaVisitor): @@ -45,39 +55,37 @@ class QAPISchemaGenIntrospectVisitor(QAPISchemaVisitor): self.defn =3D None self.decl =3D None self._schema =3D None - self._jsons =3D None + self._qlits =3D None self._used_types =3D None self._name_map =3D None =20 def visit_begin(self, schema): self._schema =3D schema - self._jsons =3D [] + self._qlits =3D [] self._used_types =3D [] self._name_map =3D {} =20 def visit_end(self): # visit the types that are actually used - jsons =3D self._jsons - self._jsons =3D [] + qlits =3D self._qlits + self._qlits =3D [] for typ in self._used_types: typ.visit(self) # generate C # TODO can generate awfully long lines - jsons.extend(self._jsons) - name =3D c_name(prefix, protect=3DFalse) + 'qmp_schema_json' + qlits.extend(self._qlits) + name =3D c_name(prefix, protect=3DFalse) + 'qmp_schema_qlit' self.decl =3D mcgen(''' -extern const char %(c_name)s[]; +extern const QLitObject %(c_name)s; ''', c_name=3Dc_name(name)) - lines =3D to_json(jsons).split('\n') - c_string =3D '\n '.join([to_c_string(line) for line in lines]) self.defn =3D mcgen(''' -const char %(c_name)s[] =3D %(c_string)s; +const QLitObject %(c_name)s =3D %(c_string)s; ''', c_name=3Dc_name(name), - c_string=3Dc_string) + c_string=3Dto_qlit(qlits)) self._schema =3D None - self._jsons =3D None + self._qlits =3D None self._used_types =3D None self._name_map =3D None =20 @@ -111,12 +119,12 @@ const char %(c_name)s[] =3D %(c_string)s; return '[' + self._use_type(typ.element_type) + ']' return self._name(typ.name) =20 - def _gen_json(self, name, mtype, obj): + def _gen_qlit(self, name, mtype, obj): if mtype not in ('command', 'event', 'builtin', 'array'): name =3D self._name(name) obj['name'] =3D name obj['meta-type'] =3D mtype - self._jsons.append(obj) + self._qlits.append(obj) =20 def _gen_member(self, member): ret =3D {'name': member.name, 'type': self._use_type(member.type)} @@ -132,24 +140,24 @@ const char %(c_name)s[] =3D %(c_string)s; return {'case': variant.name, 'type': self._use_type(variant.type)} =20 def visit_builtin_type(self, name, info, json_type): - self._gen_json(name, 'builtin', {'json-type': json_type}) + self._gen_qlit(name, 'builtin', {'json-type': json_type}) =20 def visit_enum_type(self, name, info, values, prefix): - self._gen_json(name, 'enum', {'values': values}) + self._gen_qlit(name, 'enum', {'values': values}) =20 def visit_array_type(self, name, info, element_type): element =3D self._use_type(element_type) - self._gen_json('[' + element + ']', 'array', {'element-type': elem= ent}) + self._gen_qlit('[' + element + ']', 'array', {'element-type': elem= ent}) =20 def visit_object_type_flat(self, name, info, members, variants): obj =3D {'members': [self._gen_member(m) for m in members]} if variants: obj.update(self._gen_variants(variants.tag_member.name, variants.variants)) - self._gen_json(name, 'object', obj) + self._gen_qlit(name, 'object', obj) =20 def visit_alternate_type(self, name, info, variants): - self._gen_json(name, 'alternate', + self._gen_qlit(name, 'alternate', {'members': [{'type': self._use_type(m.type)} for m in variants.variants]}) =20 @@ -157,13 +165,13 @@ const char %(c_name)s[] =3D %(c_string)s; gen, success_response, boxed): arg_type =3D arg_type or self._schema.the_empty_object_type ret_type =3D ret_type or self._schema.the_empty_object_type - self._gen_json(name, 'command', + self._gen_qlit(name, 'command', {'arg-type': self._use_type(arg_type), 'ret-type': self._use_type(ret_type)}) =20 def visit_event(self, name, info, arg_type, boxed): arg_type =3D arg_type or self._schema.the_empty_object_type - self._gen_json(name, 'event', {'arg-type': self._use_type(arg_type= )}) + self._gen_qlit(name, 'event', {'arg-type': self._use_type(arg_type= )}) =20 # Debugging aid: unmask QAPI schema's type names # We normally mask them, because they're not QMP wire ABI @@ -205,11 +213,18 @@ h_comment =3D ''' =20 fdef.write(mcgen(''' #include "qemu/osdep.h" +#include "qapi/qmp/qlit.h" #include "%(prefix)sqmp-introspect.h" =20 ''', prefix=3Dprefix)) =20 +fdecl.write(mcgen(''' +#include "qemu/osdep.h" +#include "qapi/qmp/qlit.h" + +''')) + schema =3D QAPISchema(input_file) gen =3D QAPISchemaGenIntrospectVisitor(opt_unmask) schema.visit(gen) diff --git a/monitor.c b/monitor.c index e0f880107f..14c27d4b6f 100644 --- a/monitor.c +++ b/monitor.c @@ -953,7 +953,7 @@ EventInfoList *qmp_query_events(Error **errp) static void qmp_query_qmp_schema(QDict *qdict, QObject **ret_data, Error **errp) { - *ret_data =3D qobject_from_json(qmp_schema_json, &error_abort); + *ret_data =3D qobject_from_qlit(&qmp_schema_qlit); } =20 /* diff --git a/tests/test-qobject-input-visitor.c b/tests/test-qobject-input-= visitor.c index bcf02617dc..bdd00f6bd8 100644 --- a/tests/test-qobject-input-visitor.c +++ b/tests/test-qobject-input-visitor.c @@ -1247,24 +1247,27 @@ static void test_visitor_in_fail_alternate(TestInpu= tVisitorData *data, } =20 static void do_test_visitor_in_qmp_introspect(TestInputVisitorData *data, - const char *schema_json) + const QLitObject *qlit) { SchemaInfoList *schema =3D NULL; + QObject *obj =3D qobject_from_qlit(qlit); Visitor *v; =20 - v =3D visitor_input_test_init_raw(data, schema_json); + v =3D qobject_input_visitor_new(obj); =20 visit_type_SchemaInfoList(v, NULL, &schema, &error_abort); g_assert(schema); =20 qapi_free_SchemaInfoList(schema); + qobject_decref(obj); + visit_free(v); } =20 static void test_visitor_in_qmp_introspect(TestInputVisitorData *data, const void *unused) { - do_test_visitor_in_qmp_introspect(data, test_qmp_schema_json); - do_test_visitor_in_qmp_introspect(data, qmp_schema_json); + do_test_visitor_in_qmp_introspect(data, &test_qmp_schema_qlit); + do_test_visitor_in_qmp_introspect(data, &qmp_schema_qlit); } =20 int main(int argc, char **argv) diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt index 9903ac4c19..b653e86bff 100644 --- a/docs/devel/qapi-code-gen.txt +++ b/docs/devel/qapi-code-gen.txt @@ -1295,18 +1295,27 @@ Example: #ifndef EXAMPLE_QMP_INTROSPECT_H #define EXAMPLE_QMP_INTROSPECT_H =20 - extern const char example_qmp_schema_json[]; + extern const QLitObject qmp_schema_qlit; =20 #endif $ cat qapi-generated/example-qmp-introspect.c [Uninteresting stuff omitted...] =20 - const char example_qmp_schema_json[] =3D "[" - "{\"arg-type\": \"0\", \"meta-type\": \"event\", \"name\": \"MY_EV= ENT\"}, " - "{\"arg-type\": \"1\", \"meta-type\": \"command\", \"name\": \"my-= command\", \"ret-type\": \"2\"}, " - "{\"members\": [], \"meta-type\": \"object\", \"name\": \"0\"}, " - "{\"members\": [{\"name\": \"arg1\", \"type\": \"[2]\"}], \"meta-t= ype\": \"object\", \"name\": \"1\"}, " - "{\"members\": [{\"name\": \"integer\", \"type\": \"int\"}, {\"def= ault\": null, \"name\": \"string\", \"type\": \"str\"}], \"meta-type\": \"o= bject\", \"name\": \"2\"}, " - "{\"element-type\": \"2\", \"meta-type\": \"array\", \"name\": \"[= 2]\"}, " - "{\"json-type\": \"int\", \"meta-type\": \"builtin\", \"name\": \"= int\"}, " - "{\"json-type\": \"string\", \"meta-type\": \"builtin\", \"name\":= \"str\"}]"; + const QLitObject example_qmp_schema_qlit =3D QLIT_QLIST(((QLitObject[]= ) { + QLIT_QDICT(((QLitDictEntry[]) { + { "arg-type", QLIT_QSTR("0") }, + { "meta-type", QLIT_QSTR("event") }, + { "name", QLIT_QSTR("Event") }, + { } + })), + QLIT_QDICT(((QLitDictEntry[]) { + { "members", QLIT_QLIST(((QLitObject[]) { + { } + })) }, + { "meta-type", QLIT_QSTR("object") }, + { "name", QLIT_QSTR("0") }, + { } + })), + ... + { } + })); --=20 2.14.1.146.gd35faa819