From nobody Tue May 7 01:19:00 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 1503409179981599.9076751057373; Tue, 22 Aug 2017 06:39:39 -0700 (PDT) Received: from localhost ([::1]:46950 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9P8-0004Aq-K0 for importer@patchew.org; Tue, 22 Aug 2017 09:39:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53585) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9Ea-0003iu-C5 for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:28:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9EZ-0003dP-By for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:28:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47378) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9EZ-0003dF-6K for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:28:43 -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 057F67ACA5; Tue, 22 Aug 2017 13:23:05 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id A3AC981B49; Tue, 22 Aug 2017 13:23:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 057F67ACA5 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: Tue, 22 Aug 2017 15:22:02 +0200 Message-Id: <20170822132255.23945-2-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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.26]); Tue, 22 Aug 2017 13:23:05 +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/54] qapi: fix type_seen key error 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?= , Markus Armbruster , Michael Roth 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" The type_seen member can be of a different type than the 'qtype' being checked, since a string create several conflicts. Lookup the real conflicting type in the conflict set, that one must be present in type_seen. This fixes the following error, reproducible with the modified test: Traceback (most recent call last): File "/home/elmarco/src/qq/tests/qapi-schema/test-qapi.py", line 56, in <= module> schema =3D QAPISchema(sys.argv[1]) File "/home/elmarco/src/qq/scripts/qapi.py", line 1470, in __init__ self.exprs =3D check_exprs(parser.exprs) File "/home/elmarco/src/qq/scripts/qapi.py", line 959, in check_exprs check_alternate(expr, info) File "/home/elmarco/src/qq/scripts/qapi.py", line 831, in check_alternate % (name, key, types_seen[qtype])) KeyError: 'QTYPE_QSTRING' Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Markus Armbruster --- scripts/qapi.py | 6 ++++-- tests/qapi-schema/alternate-conflict-string.json | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/scripts/qapi.py b/scripts/qapi.py index 8aa2775f12..a3ac799535 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -825,10 +825,12 @@ def check_alternate(expr, info): else: conflicting.add('QTYPE_QNUM') conflicting.add('QTYPE_QBOOL') - if conflicting & set(types_seen): + conflict =3D conflicting & set(types_seen) + if conflict: + conflict_qtype =3D list(conflict)[0] raise QAPISemError(info, "Alternate '%s' member '%s' can't " "be distinguished from member '%s'" - % (name, key, types_seen[qtype])) + % (name, key, types_seen[conflict_qtype])) for qt in conflicting: types_seen[qt] =3D key =20 diff --git a/tests/qapi-schema/alternate-conflict-string.json b/tests/qapi-= schema/alternate-conflict-string.json index 85adbd4adc..bb2702978e 100644 --- a/tests/qapi-schema/alternate-conflict-string.json +++ b/tests/qapi-schema/alternate-conflict-string.json @@ -1,4 +1,4 @@ # alternate branches of 'str' type conflict with all scalar types { 'alternate': 'Alt', - 'data': { 'one': 'str', - 'two': 'int' } } + 'data': { 'one': 'int', + 'two': 'str' } } --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 1503409735587590.9339071355058; Tue, 22 Aug 2017 06:48:55 -0700 (PDT) Received: from localhost ([::1]:47124 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9Y4-00041i-4H for importer@patchew.org; Tue, 22 Aug 2017 09:48:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54798) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9Hn-0006f0-O9 for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:32:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9Hk-000649-4k for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:32:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33404) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9Hj-00063T-VF for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:32:00 -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 F15566146A for ; Tue, 22 Aug 2017 13:23:08 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 946F1617A0; Tue, 22 Aug 2017 13:23:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com F15566146A 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: Tue, 22 Aug 2017 15:22:03 +0200 Message-Id: <20170822132255.23945-3-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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.39]); Tue, 22 Aug 2017 13:23: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 02/54] 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?= , Markus Armbruster 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 --- include/qapi/qmp/qdict.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/qapi/qmp/qdict.h b/include/qapi/qmp/qdict.h index 363e431106..a35bed9f16 100644 --- a/include/qapi/qmp/qdict.h +++ b/include/qapi/qmp/qdict.h @@ -60,6 +60,8 @@ void qdict_destroy_obj(QObject *obj); 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); --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 15034095361461007.7631041333291; Tue, 22 Aug 2017 06:45:36 -0700 (PDT) Received: from localhost ([::1]:47104 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9Uq-000119-Js for importer@patchew.org; Tue, 22 Aug 2017 09:45:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54713) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9Hg-0006XQ-AD for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:32:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9HZ-0005wY-5P for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:31:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53942) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9HY-0005w7-So for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:31:49 -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 C06CB7EA8F for ; Tue, 22 Aug 2017 13:23:11 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id AF05881B49; Tue, 22 Aug 2017 13:23:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C06CB7EA8F 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: Tue, 22 Aug 2017 15:22:04 +0200 Message-Id: <20170822132255.23945-4-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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.28]); Tue, 22 Aug 2017 13:23:11 +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/54] qobject: add literal qobject type 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?= , Markus Armbruster 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" Promote LiteralQObject from tests/check-qjson.c to qobject/qlit.c, allowing to statically declare complex qobjects. Signed-off-by: Marc-Andr=C3=A9 Lureau --- include/qapi/qmp/qlit.h | 54 +++++++++++++++++ qobject/qlit.c | 106 ++++++++++++++++++++++++++++++++++ tests/check-qjson.c | 150 +++++++++-----------------------------------= ---- tests/check-qlit.c | 68 ++++++++++++++++++++++ qobject/Makefile.objs | 2 +- tests/Makefile.include | 5 +- 6 files changed, 261 insertions(+), 124 deletions(-) create mode 100644 include/qapi/qmp/qlit.h create mode 100644 qobject/qlit.c create mode 100644 tests/check-qlit.c diff --git a/include/qapi/qmp/qlit.h b/include/qapi/qmp/qlit.h new file mode 100644 index 0000000000..2cdceb448d --- /dev/null +++ b/include/qapi/qmp/qlit.h @@ -0,0 +1,54 @@ +/* + * 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 QLitDictEntry QLitDictEntry; +typedef struct QLitObject QLitObject; + +struct QLitObject { + int type; + union { + bool qbool; + int64_t qnum; + const char *qstr; + QLitDictEntry *qdict; + QLitObject *qlist; + } value; +}; + +struct QLitDictEntry { + const char *key; + QLitObject value; +}; + +#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) \ + { .type =3D QTYPE_QSTRING, .value.qstr =3D (val) } +#define QLIT_QDICT(val) \ + { .type =3D QTYPE_QDICT, .value.qdict =3D (val) } +#define QLIT_QLIST(val) \ + { .type =3D QTYPE_QLIST, .value.qlist =3D (val) } + +bool qlit_equal_qobject(QLitObject *lhs, QObject *rhs); + +#endif /* QLIT_H_ */ diff --git a/qobject/qlit.c b/qobject/qlit.c new file mode 100644 index 0000000000..f4ebeb6259 --- /dev/null +++ b/qobject/qlit.c @@ -0,0 +1,106 @@ +/* + * 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; + 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); +} + +bool qlit_equal_qobject(QLitObject *lhs, QObject *rhs) +{ + int64_t val; + + if (!rhs || lhs->type !=3D qobject_type(rhs)) { + return false; + } + + switch (lhs->type) { + case QTYPE_QBOOL: + return lhs->value.qbool =3D=3D qbool_get_bool(qobject_to_qbool(rhs= )); + case QTYPE_QNUM: + val =3D qnum_get_int(qobject_to_qnum(rhs)); + return lhs->value.qnum =3D=3D val; + case QTYPE_QSTRING: + return g_str_equal(lhs->value.qstr, + qstring_get_str(qobject_to_qstring(rhs))); + 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; + } + } + + if (qdict_size(qobject_to_qdict(rhs)) !=3D i) { + return false; + } + + return true; + } + case QTYPE_QLIST: { + QListCompareHelper helper; + int i; + + for (i =3D 0; lhs->value.qlist[i].type !=3D QTYPE_NONE; i++) { + continue; + } + + if (qlist_size(qobject_to_qlist(rhs)) !=3D i) { + return false; + } + + 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_QNULL: + return true; + default: + break; + } + + return false; +} diff --git a/tests/check-qjson.c b/tests/check-qjson.c index a3a97b0d99..59227934ce 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,123 +1060,28 @@ 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; 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) }, { } })), @@ -1188,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)); =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)); qobject_decref(obj); QDECREF(str); } @@ -1257,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), { } @@ -1269,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[]){ {}, })), {}, @@ -1297,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)); =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)); qobject_decref(obj); QDECREF(str); } @@ -1314,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), { } @@ -1326,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), { } @@ -1339,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), { } @@ -1359,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)); =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)); =20 qobject_decref(obj); QDECREF(str); @@ -1376,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), {}})), @@ -1389,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)); =20 qobject_decref(obj); } diff --git a/tests/check-qlit.c b/tests/check-qlit.c new file mode 100644 index 0000000000..5736b61ebf --- /dev/null +++ b/tests/check-qlit.c @@ -0,0 +1,68 @@ +/* + * 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(); + QList *list =3D qlist_new(); + + g_assert(qlit_equal_qobject(&qlit, qobj)); + + qdict_put(qobject_to_qdict(qobj), "bee", list); + 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/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 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 Tue May 7 01:19:00 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 1503409646869440.77566202173807; Tue, 22 Aug 2017 06:47:26 -0700 (PDT) Received: from localhost ([::1]:47115 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9Wf-0002kG-Oi for importer@patchew.org; Tue, 22 Aug 2017 09:47:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54817) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9Hp-0006gc-9Y for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:32:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9Hm-00066t-4T for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:32:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44190) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9Hl-00065V-S3 for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:32:02 -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 C6E8381E12 for ; Tue, 22 Aug 2017 13:23:16 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id A27617E575; Tue, 22 Aug 2017 13:23:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C6E8381E12 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: Tue, 22 Aug 2017 15:22:05 +0200 Message-Id: <20170822132255.23945-5-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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.25]); Tue, 22 Aug 2017 13:23: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 04/54] 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?= , Markus Armbruster 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 --- 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 2cdceb448d..dd562b7d69 100644 --- a/include/qapi/qmp/qlit.h +++ b/include/qapi/qmp/qlit.h @@ -51,4 +51,6 @@ struct QLitDictEntry { =20 bool qlit_equal_qobject(QLitObject *lhs, QObject *rhs); =20 +QObject *qobject_from_qlit(const QLitObject *qlit); + #endif /* QLIT_H_ */ diff --git a/qobject/qlit.c b/qobject/qlit.c index f4ebeb6259..5a2aa44355 100644 --- a/qobject/qlit.c +++ b/qobject/qlit.c @@ -104,3 +104,40 @@ bool qlit_equal_qobject(QLitObject *lhs, QObject *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 5736b61ebf..f25f3d9633 100644 --- a/tests/check-qlit.c +++ b/tests/check-qlit.c @@ -58,11 +58,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 Tue May 7 01:19:00 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 1503410290210620.0884048219408; Tue, 22 Aug 2017 06:58:10 -0700 (PDT) Received: from localhost ([::1]:47232 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9h0-0003iM-TX for importer@patchew.org; Tue, 22 Aug 2017 09:58:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55066) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9J3-0007nX-F2 for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9J0-0006nO-7X for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36820) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9Iz-0006mo-UN for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:18 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8260C46298; Tue, 22 Aug 2017 13:23:21 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id BEC2E17F3A; Tue, 22 Aug 2017 13:23:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8260C46298 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: Tue, 22 Aug 2017 15:22:06 +0200 Message-Id: <20170822132255.23945-6-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 22 Aug 2017 13:23:21 +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/54] 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?= , "Dr. David Alan Gilbert" , Markus Armbruster 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 | 91 ++++++++++++++++++++++------------= ---- monitor.c | 2 +- tests/test-qobject-input-visitor.c | 11 +++-- docs/devel/qapi-code-gen.txt | 29 +++++++----- 4 files changed, 80 insertions(+), 53 deletions(-) diff --git a/scripts/qapi-introspect.py b/scripts/qapi-introspect.py index 032bcea491..1b96926fa7 100644 --- a/scripts/qapi-introspect.py +++ b/scripts/qapi-introspect.py @@ -12,72 +12,80 @@ 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_c_string(s): + return '"' + s.replace('\\', r'\\').replace('"', r'\"') + '"' + + +def to_qlit(obj, level=3D0, first_indent=3DTrue): + + def indent(level): + return level * 4 * ' ' + + ret =3D '' + if 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'\"') + '"' - - class QAPISchemaGenIntrospectVisitor(QAPISchemaVisitor): def __init__(self, unmask): self._unmask =3D unmask 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 From nobody Tue May 7 01:19:00 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 1503411050342681.3208764436731; Tue, 22 Aug 2017 07:10:50 -0700 (PDT) Received: from localhost ([::1]:47347 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9tJ-0005gb-0y for importer@patchew.org; Tue, 22 Aug 2017 10:10:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55367) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9Jb-0008GX-Ey for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:34:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9JW-00079C-7q for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58306) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9JH-0006wm-TZ; Tue, 22 Aug 2017 09:33:36 -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 947A2C047B9A; Tue, 22 Aug 2017 13:23:35 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 49B967E578; Tue, 22 Aug 2017 13:23:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 947A2C047B9A 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: Tue, 22 Aug 2017 15:22:07 +0200 Message-Id: <20170822132255.23945-7-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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]); Tue, 22 Aug 2017 13:23:36 +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/54] qapi: introduce qapi_enum_lookup() 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: "open list:Sheepdog" , Stefan Hajnoczi , "Michael S. Tsirkin" , Jeff Cody , Michael Roth , Gerd Hoffmann , Josh Durgin , zhanghailiang , "open list:Block Jobs" , Juan Quintela , Markus Armbruster , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Liu Yuan , Jason Wang , Eduardo Habkost , Stefan Weil , Peter Lieven , "Dr. David Alan Gilbert" , Ronnie Sahlberg , Igor Mammedov , John Snow , Kevin Wolf , Hitoshi Mitake , Max Reitz , 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" This will help with the introduction of a new structure to handle enum lookup. Signed-off-by: Marc-Andr=C3=A9 Lureau --- include/qapi/util.h | 2 + backends/hostmem.c | 3 +- block/backup.c | 3 +- block/file-posix.c | 5 ++- block/file-win32.c | 2 +- block/gluster.c | 4 +- block/iscsi.c | 3 +- block/nfs.c | 3 +- block/qcow2.c | 5 ++- block/qed.c | 3 +- block/rbd.c | 3 +- block/sheepdog.c | 3 +- blockdev.c | 6 ++- blockjob.c | 9 +++-- chardev/char.c | 7 +++- crypto/block-luks.c | 17 ++++++--- crypto/block.c | 5 ++- crypto/cipher-afalg.c | 2 +- crypto/cipher-builtin.c | 8 ++-- crypto/cipher-gcrypt.c | 4 +- crypto/cipher-nettle.c | 8 ++-- crypto/cipher.c | 1 + crypto/hmac-gcrypt.c | 2 +- crypto/hmac-glib.c | 3 +- crypto/hmac-nettle.c | 3 +- crypto/pbkdf-gcrypt.c | 3 +- crypto/pbkdf-nettle.c | 4 +- hmp.c | 74 +++++++++++++++++++++++----------= ---- hw/block/fdc.c | 9 +++-- hw/char/escc.c | 3 +- hw/core/qdev-properties.c | 9 +++-- hw/input/virtio-input-hid.c | 5 ++- migration/colo-failover.c | 6 ++- migration/colo.c | 17 +++++---- migration/global_state.c | 2 +- monitor.c | 24 +++++++----- net/net.c | 5 ++- qapi/qapi-util.c | 7 ++++ qapi/qmp-dispatch.c | 4 +- tests/test-qobject-output-visitor.c | 4 +- tests/test-string-output-visitor.c | 6 ++- tpm.c | 4 +- ui/input.c | 13 ++++--- ui/vnc.c | 8 ++-- vl.c | 7 ++-- 45 files changed, 206 insertions(+), 122 deletions(-) diff --git a/include/qapi/util.h b/include/qapi/util.h index 7436ed815c..60733b6a80 100644 --- a/include/qapi/util.h +++ b/include/qapi/util.h @@ -11,6 +11,8 @@ #ifndef QAPI_UTIL_H #define QAPI_UTIL_H =20 +const char *qapi_enum_lookup(const char * const lookup[], int val); + int qapi_enum_parse(const char * const lookup[], const char *buf, int max, int def, Error **errp); =20 diff --git a/backends/hostmem.c b/backends/hostmem.c index 4606b73849..c4f795475c 100644 --- a/backends/hostmem.c +++ b/backends/hostmem.c @@ -13,6 +13,7 @@ #include "sysemu/hostmem.h" #include "hw/boards.h" #include "qapi/error.h" +#include "qapi/util.h" #include "qapi/visitor.h" #include "qapi-types.h" #include "qapi-visit.h" @@ -304,7 +305,7 @@ host_memory_backend_memory_complete(UserCreatable *uc, = Error **errp) return; } else if (maxnode =3D=3D 0 && backend->policy !=3D MPOL_DEFAULT) { error_setg(errp, "host-nodes must be set for policy %s", - HostMemPolicy_lookup[backend->policy]); + qapi_enum_lookup(HostMemPolicy_lookup, backend->policy)); return; } =20 diff --git a/block/backup.c b/block/backup.c index 504a089150..a700cc0315 100644 --- a/block/backup.c +++ b/block/backup.c @@ -19,6 +19,7 @@ #include "block/blockjob_int.h" #include "block/block_backup.h" #include "qapi/error.h" +#include "qapi/util.h" #include "qapi/qmp/qerror.h" #include "qemu/ratelimit.h" #include "qemu/cutils.h" @@ -596,7 +597,7 @@ BlockJob *backup_job_create(const char *job_id, BlockDr= iverState *bs, error_setg(errp, "a sync_bitmap was provided to backup_run, " "but received an incompatible sync_mode (%s)", - MirrorSyncMode_lookup[sync_mode]); + qapi_enum_lookup(MirrorSyncMode_lookup, sync_mode)); return NULL; } =20 diff --git a/block/file-posix.c b/block/file-posix.c index cb3bfce147..48200aef0b 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1725,7 +1725,7 @@ static int raw_regular_truncate(int fd, int64_t offse= t, PreallocMode prealloc, default: result =3D -ENOTSUP; error_setg(errp, "Unsupported preallocation mode: %s", - PreallocMode_lookup[prealloc]); + qapi_enum_lookup(PreallocMode_lookup, prealloc)); return result; } =20 @@ -1760,7 +1760,8 @@ static int raw_truncate(BlockDriverState *bs, int64_t= offset, =20 if (prealloc !=3D PREALLOC_MODE_OFF) { error_setg(errp, "Preallocation mode '%s' unsupported for this " - "non-regular file", PreallocMode_lookup[prealloc]); + "non-regular file", qapi_enum_lookup(PreallocMode_looku= p, + prealloc)); return -ENOTSUP; } =20 diff --git a/block/file-win32.c b/block/file-win32.c index 4706335cff..2f3975f040 100644 --- a/block/file-win32.c +++ b/block/file-win32.c @@ -470,7 +470,7 @@ static int raw_truncate(BlockDriverState *bs, int64_t o= ffset, =20 if (prealloc !=3D PREALLOC_MODE_OFF) { error_setg(errp, "Unsupported preallocation mode '%s'", - PreallocMode_lookup[prealloc]); + qapi_enum_lookup(reallocMode_lookup, prealloc)); return -ENOTSUP; } =20 diff --git a/block/gluster.c b/block/gluster.c index 3064a45047..934f459014 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -1050,7 +1050,7 @@ static int qemu_gluster_create(const char *filename, default: ret =3D -EINVAL; error_setg(errp, "Unsupported preallocation mode: %s", - PreallocMode_lookup[prealloc]); + qapi_enum_lookup(PreallocMode_lookup, prealloc)); break; } =20 @@ -1102,7 +1102,7 @@ static int qemu_gluster_truncate(BlockDriverState *bs= , int64_t offset, =20 if (prealloc !=3D PREALLOC_MODE_OFF) { error_setg(errp, "Unsupported preallocation mode '%s'", - PreallocMode_lookup[prealloc]); + qapi_enum_lookup(PreallocMode_lookup, prealloc)); return -ENOTSUP; } =20 diff --git a/block/iscsi.c b/block/iscsi.c index d557c99668..5c1870340b 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -39,6 +39,7 @@ #include "qemu/uuid.h" #include "qmp-commands.h" #include "qapi/qmp/qstring.h" +#include "qapi/util.h" #include "crypto/secret.h" =20 #include @@ -2087,7 +2088,7 @@ static int iscsi_truncate(BlockDriverState *bs, int64= _t offset, =20 if (prealloc !=3D PREALLOC_MODE_OFF) { error_setg(errp, "Unsupported preallocation mode '%s'", - PreallocMode_lookup[prealloc]); + qapi_enum_lookup(PreallocMode_lookup, prealloc)); return -ENOTSUP; } =20 diff --git a/block/nfs.c b/block/nfs.c index bec16b72a6..953728ae31 100644 --- a/block/nfs.c +++ b/block/nfs.c @@ -40,6 +40,7 @@ #include "qapi-visit.h" #include "qapi/qobject-input-visitor.h" #include "qapi/qobject-output-visitor.h" +#include "qapi/util.h" #include =20 =20 @@ -772,7 +773,7 @@ static int nfs_file_truncate(BlockDriverState *bs, int6= 4_t offset, =20 if (prealloc !=3D PREALLOC_MODE_OFF) { error_setg(errp, "Unsupported preallocation mode '%s'", - PreallocMode_lookup[prealloc]); + qapi_enum_lookup(PreallocMode_lookup, prealloc)); return -ENOTSUP; } =20 diff --git a/block/qcow2.c b/block/qcow2.c index 40ba26c111..45b0579caa 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2732,7 +2732,8 @@ static int qcow2_create2(const char *filename, int64_= t total_size, int64_t prealloc_size =3D qcow2_calc_prealloc_size(total_size, cluster_size, refcount_or= der); qemu_opt_set_number(opts, BLOCK_OPT_SIZE, prealloc_size, &error_ab= ort); - qemu_opt_set(opts, BLOCK_OPT_PREALLOC, PreallocMode_lookup[preallo= c], + qemu_opt_set(opts, BLOCK_OPT_PREALLOC, + qapi_enum_lookup(PreallocMode_lookup, prealloc), &error_abort); } =20 @@ -3098,7 +3099,7 @@ static int qcow2_truncate(BlockDriverState *bs, int64= _t offset, prealloc !=3D PREALLOC_MODE_FALLOC && prealloc !=3D PREALLOC_MODE_= FULL) { error_setg(errp, "Unsupported preallocation mode '%s'", - PreallocMode_lookup[prealloc]); + qapi_enum_lookup(PreallocMode_lookup, prealloc)); return -ENOTSUP; } =20 diff --git a/block/qed.c b/block/qed.c index dc54bf4a93..756fcb85a7 100644 --- a/block/qed.c +++ b/block/qed.c @@ -19,6 +19,7 @@ #include "trace.h" #include "qed.h" #include "qapi/qmp/qerror.h" +#include "qapi/util.h" #include "sysemu/block-backend.h" =20 static int bdrv_qed_probe(const uint8_t *buf, int buf_size, @@ -1399,7 +1400,7 @@ static int bdrv_qed_truncate(BlockDriverState *bs, in= t64_t offset, =20 if (prealloc !=3D PREALLOC_MODE_OFF) { error_setg(errp, "Unsupported preallocation mode '%s'", - PreallocMode_lookup[prealloc]); + qapi_enum_lookup(PreallocMode_lookup, prealloc)); return -ENOTSUP; } =20 diff --git a/block/rbd.c b/block/rbd.c index 9c3aa638e7..09f8d18d1b 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -21,6 +21,7 @@ #include "qemu/cutils.h" #include "qapi/qmp/qstring.h" #include "qapi/qmp/qjson.h" +#include "qapi/util.h" =20 /* * When specifying the image filename use: @@ -944,7 +945,7 @@ static int qemu_rbd_truncate(BlockDriverState *bs, int6= 4_t offset, =20 if (prealloc !=3D PREALLOC_MODE_OFF) { error_setg(errp, "Unsupported preallocation mode '%s'", - PreallocMode_lookup[prealloc]); + qapi_enum_lookup(PreallocMode_lookup, prealloc)); return -ENOTSUP; } =20 diff --git a/block/sheepdog.c b/block/sheepdog.c index abb2e79065..69d49fb720 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -17,6 +17,7 @@ #include "qapi/error.h" #include "qapi/qmp/qdict.h" #include "qapi/qobject-input-visitor.h" +#include "qapi/util.h" #include "qemu/uri.h" #include "qemu/error-report.h" #include "qemu/sockets.h" @@ -2176,7 +2177,7 @@ static int sd_truncate(BlockDriverState *bs, int64_t = offset, =20 if (prealloc !=3D PREALLOC_MODE_OFF) { error_setg(errp, "Unsupported preallocation mode '%s'", - PreallocMode_lookup[prealloc]); + qapi_enum_lookup(PreallocMode_lookup, prealloc)); return -ENOTSUP; } =20 diff --git a/blockdev.c b/blockdev.c index 02cd69bc21..6a067e81bf 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1468,8 +1468,10 @@ static int action_check_completion_mode(BlkActionSta= te *s, Error **errp) error_setg(errp, "Action '%s' does not support Transaction property " "completion-mode =3D %s", - TransactionActionKind_lookup[s->action->type], - ActionCompletionMode_lookup[s->txn_props->completion_mo= de]); + qapi_enum_lookup(TransactionActionKind_lookup, + s->action->type), + qapi_enum_lookup(ActionCompletionMode_lookup, + s->txn_props->completion_mode)); return -1; } return 0; diff --git a/blockjob.c b/blockjob.c index 70a78188b7..fca71123e0 100644 --- a/blockjob.c +++ b/blockjob.c @@ -31,6 +31,7 @@ #include "sysemu/block-backend.h" #include "qapi/qmp/qerror.h" #include "qapi/qmp/qjson.h" +#include "qapi/util.h" #include "qemu/coroutine.h" #include "qemu/id.h" #include "qmp-commands.h" @@ -208,7 +209,8 @@ static char *child_job_get_parent_desc(BdrvChild *c) { BlockJob *job =3D c->opaque; return g_strdup_printf("%s job '%s'", - BlockJobType_lookup[job->driver->job_type], + qapi_enum_lookup(BlockJobType_lookup, + job->driver->job_type), job->id); } =20 @@ -553,7 +555,8 @@ BlockJobInfo *block_job_query(BlockJob *job, Error **er= rp) return NULL; } info =3D g_new0(BlockJobInfo, 1); - info->type =3D g_strdup(BlockJobType_lookup[job->driver->job_type= ]); + info->type =3D g_strdup(qapi_enum_lookup(BlockJobType_lookup, + job->driver->job_type)); info->device =3D g_strdup(job->id); info->len =3D job->len; info->busy =3D job->busy; @@ -666,7 +669,7 @@ void *block_job_create(const char *job_id, const BlockJ= obDriver *driver, job->refcnt =3D 1; =20 error_setg(&job->blocker, "block device is in use by block job: %s", - BlockJobType_lookup[driver->job_type]); + qapi_enum_lookup(BlockJobType_lookup, driver->job_type)); block_job_add_bdrv(job, "main node", bs, 0, BLK_PERM_ALL, &error_abort= ); bs->job =3D job; =20 diff --git a/chardev/char.c b/chardev/char.c index 5d283b90d3..4408d12a08 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -30,6 +30,7 @@ #include "chardev/char.h" #include "qmp-commands.h" #include "qapi-visit.h" +#include "qapi/util.h" #include "sysemu/replay.h" #include "qemu/help_option.h" =20 @@ -931,7 +932,8 @@ ChardevReturn *qmp_chardev_add(const char *id, ChardevB= ackend *backend, ChardevReturn *ret; Chardev *chr; =20 - cc =3D char_get_class(ChardevBackendKind_lookup[backend->type], errp); + cc =3D char_get_class(qapi_enum_lookup(ChardevBackendKind_lookup, + backend->type), errp); if (!cc) { return NULL; } @@ -989,7 +991,8 @@ ChardevReturn *qmp_chardev_change(const char *id, Chard= evBackend *backend, return NULL; } =20 - cc =3D char_get_class(ChardevBackendKind_lookup[backend->type], errp); + cc =3D char_get_class(qapi_enum_lookup(ChardevBackendKind_lookup, + backend->type), errp); if (!cc) { return NULL; } diff --git a/crypto/block-luks.c b/crypto/block-luks.c index afb8543108..b78a6345f3 100644 --- a/crypto/block-luks.c +++ b/crypto/block-luks.c @@ -20,6 +20,7 @@ =20 #include "qemu/osdep.h" #include "qapi/error.h" +#include "qapi/util.h" #include "qemu/bswap.h" =20 #include "crypto/block-luks.h" @@ -257,7 +258,7 @@ qcrypto_block_luks_cipher_alg_lookup(QCryptoCipherAlgor= ithm alg, } =20 error_setg(errp, "Algorithm '%s' not supported", - QCryptoCipherAlgorithm_lookup[alg]); + qapi_enum_lookup(QCryptoCipherAlgorithm_lookup, alg)); return NULL; } =20 @@ -398,7 +399,7 @@ qcrypto_block_luks_essiv_cipher(QCryptoCipherAlgorithm = cipher, break; default: error_setg(errp, "Cipher %s not supported with essiv", - QCryptoCipherAlgorithm_lookup[cipher]); + qapi_enum_lookup(QCryptoCipherAlgorithm_lookup, cipher)= ); return 0; } } @@ -968,16 +969,20 @@ qcrypto_block_luks_create(QCryptoBlock *block, goto error; } =20 - cipher_mode =3D QCryptoCipherMode_lookup[luks_opts.cipher_mode]; - ivgen_alg =3D QCryptoIVGenAlgorithm_lookup[luks_opts.ivgen_alg]; + cipher_mode =3D qapi_enum_lookup(QCryptoCipherMode_lookup, + luks_opts.cipher_mode); + ivgen_alg =3D qapi_enum_lookup(QCryptoIVGenAlgorithm_lookup, + luks_opts.ivgen_alg); if (luks_opts.has_ivgen_hash_alg) { - ivgen_hash_alg =3D QCryptoHashAlgorithm_lookup[luks_opts.ivgen_has= h_alg]; + ivgen_hash_alg =3D qapi_enum_lookup(QCryptoHashAlgorithm_lookup, + luks_opts.ivgen_hash_alg); cipher_mode_spec =3D g_strdup_printf("%s-%s:%s", cipher_mode, ivge= n_alg, ivgen_hash_alg); } else { cipher_mode_spec =3D g_strdup_printf("%s-%s", cipher_mode, ivgen_a= lg); } - hash_alg =3D QCryptoHashAlgorithm_lookup[luks_opts.hash_alg]; + hash_alg =3D qapi_enum_lookup(QCryptoHashAlgorithm_lookup, + luks_opts.hash_alg); =20 =20 if (strlen(cipher_alg) >=3D QCRYPTO_BLOCK_LUKS_CIPHER_NAME_LEN) { diff --git a/crypto/block.c b/crypto/block.c index b097d451af..2140e55426 100644 --- a/crypto/block.c +++ b/crypto/block.c @@ -20,6 +20,7 @@ =20 #include "qemu/osdep.h" #include "qapi/error.h" +#include "qapi/util.h" #include "crypto/blockpriv.h" #include "crypto/block-qcow.h" #include "crypto/block-luks.h" @@ -61,7 +62,7 @@ QCryptoBlock *qcrypto_block_open(QCryptoBlockOpenOptions = *options, if (options->format >=3D G_N_ELEMENTS(qcrypto_block_drivers) || !qcrypto_block_drivers[options->format]) { error_setg(errp, "Unsupported block driver %s", - QCryptoBlockFormat_lookup[options->format]); + qapi_enum_lookup(QCryptoBlockFormat_lookup, options->format)); g_free(block); return NULL; } @@ -92,7 +93,7 @@ QCryptoBlock *qcrypto_block_create(QCryptoBlockCreateOpti= ons *options, if (options->format >=3D G_N_ELEMENTS(qcrypto_block_drivers) || !qcrypto_block_drivers[options->format]) { error_setg(errp, "Unsupported block driver %s", - QCryptoBlockFormat_lookup[options->format]); + qapi_enum_lookup(QCryptoBlockFormat_lookup, options->format)); g_free(block); return NULL; } diff --git a/crypto/cipher-afalg.c b/crypto/cipher-afalg.c index 01343b2b7c..24d7ba8277 100644 --- a/crypto/cipher-afalg.c +++ b/crypto/cipher-afalg.c @@ -52,7 +52,7 @@ qcrypto_afalg_cipher_format_name(QCryptoCipherAlgorithm a= lg, return NULL; } =20 - mode_name =3D QCryptoCipherMode_lookup[mode]; + mode_name =3D qapi_enum_lookup(QCryptoCipherMode_lookup, mode); name =3D g_strdup_printf("%s(%s)", mode_name, alg_name); =20 return name; diff --git a/crypto/cipher-builtin.c b/crypto/cipher-builtin.c index 16a36d4532..76c76fb05b 100644 --- a/crypto/cipher-builtin.c +++ b/crypto/cipher-builtin.c @@ -247,7 +247,7 @@ qcrypto_cipher_init_aes(QCryptoCipherMode mode, mode !=3D QCRYPTO_CIPHER_MODE_ECB && mode !=3D QCRYPTO_CIPHER_MODE_XTS) { error_setg(errp, "Unsupported cipher mode %s", - QCryptoCipherMode_lookup[mode]); + qapi_enum_lookup(QCryptoCipherMode_lookup, mode)); return NULL; } =20 @@ -379,7 +379,7 @@ qcrypto_cipher_init_des_rfb(QCryptoCipherMode mode, =20 if (mode !=3D QCRYPTO_CIPHER_MODE_ECB) { error_setg(errp, "Unsupported cipher mode %s", - QCryptoCipherMode_lookup[mode]); + qapi_enum_lookup(QCryptoCipherMode_lookup, mode)); return NULL; } =20 @@ -440,7 +440,7 @@ static QCryptoCipherBuiltin *qcrypto_cipher_ctx_new(QCr= yptoCipherAlgorithm alg, break; default: error_setg(errp, "Unsupported cipher mode %s", - QCryptoCipherMode_lookup[mode]); + qapi_enum_lookup(QCryptoCipherMode_lookup, mode)); return NULL; } =20 @@ -460,7 +460,7 @@ static QCryptoCipherBuiltin *qcrypto_cipher_ctx_new(QCr= yptoCipherAlgorithm alg, default: error_setg(errp, "Unsupported cipher algorithm %s", - QCryptoCipherAlgorithm_lookup[alg]); + qapi_enum_lookup(QCryptoCipherAlgorithm_lookup, alg)); return NULL; } =20 diff --git a/crypto/cipher-gcrypt.c b/crypto/cipher-gcrypt.c index 0489147398..09210195a4 100644 --- a/crypto/cipher-gcrypt.c +++ b/crypto/cipher-gcrypt.c @@ -105,7 +105,7 @@ static QCryptoCipherGcrypt *qcrypto_cipher_ctx_new(QCry= ptoCipherAlgorithm alg, break; default: error_setg(errp, "Unsupported cipher mode %s", - QCryptoCipherMode_lookup[mode]); + qapi_enum_lookup(QCryptoCipherMode_lookup, mode)); return NULL; } =20 @@ -160,7 +160,7 @@ static QCryptoCipherGcrypt *qcrypto_cipher_ctx_new(QCry= ptoCipherAlgorithm alg, =20 default: error_setg(errp, "Unsupported cipher algorithm %s", - QCryptoCipherAlgorithm_lookup[alg]); + qapi_enum_lookup(QCryptoCipherAlgorithm_lookup, alg)); return NULL; } =20 diff --git a/crypto/cipher-nettle.c b/crypto/cipher-nettle.c index c51f119cbc..7c02b3e7a2 100644 --- a/crypto/cipher-nettle.c +++ b/crypto/cipher-nettle.c @@ -281,7 +281,7 @@ static QCryptoCipherNettle *qcrypto_cipher_ctx_new(QCry= ptoCipherAlgorithm alg, break; default: error_setg(errp, "Unsupported cipher mode %s", - QCryptoCipherMode_lookup[mode]); + qapi_enum_lookup(QCryptoCipherMode_lookup, mode)); return NULL; } =20 @@ -420,7 +420,7 @@ static QCryptoCipherNettle *qcrypto_cipher_ctx_new(QCry= ptoCipherAlgorithm alg, =20 default: error_setg(errp, "Unsupported cipher algorithm %s", - QCryptoCipherAlgorithm_lookup[alg]); + qapi_enum_lookup(QCryptoCipherAlgorithm_lookup, alg)); goto error; } =20 @@ -491,7 +491,7 @@ qcrypto_nettle_cipher_encrypt(QCryptoCipher *cipher, =20 default: error_setg(errp, "Unsupported cipher mode %s", - QCryptoCipherMode_lookup[cipher->mode]); + qapi_enum_lookup(QCryptoCipherMode_lookup, cipher->mode= )); return -1; } return 0; @@ -537,7 +537,7 @@ qcrypto_nettle_cipher_decrypt(QCryptoCipher *cipher, =20 default: error_setg(errp, "Unsupported cipher mode %s", - QCryptoCipherMode_lookup[cipher->mode]); + qapi_enum_lookup(QCryptoCipherMode_lookup, cipher->mode= )); return -1; } return 0; diff --git a/crypto/cipher.c b/crypto/cipher.c index 0aad9d6d79..43291cba7e 100644 --- a/crypto/cipher.c +++ b/crypto/cipher.c @@ -22,6 +22,7 @@ #include "qapi/error.h" #include "crypto/cipher.h" #include "cipherpriv.h" +#include "qapi/util.h" =20 =20 static size_t alg_key_len[QCRYPTO_CIPHER_ALG__MAX] =3D { diff --git a/crypto/hmac-gcrypt.c b/crypto/hmac-gcrypt.c index 76ca61ba24..0784795269 100644 --- a/crypto/hmac-gcrypt.c +++ b/crypto/hmac-gcrypt.c @@ -52,7 +52,7 @@ void *qcrypto_hmac_ctx_new(QCryptoHashAlgorithm alg, =20 if (!qcrypto_hmac_supports(alg)) { error_setg(errp, "Unsupported hmac algorithm %s", - QCryptoHashAlgorithm_lookup[alg]); + qapi_enum_lookup(QCryptoHashAlgorithm_lookup, alg)); return NULL; } =20 diff --git a/crypto/hmac-glib.c b/crypto/hmac-glib.c index 8cf6b221ed..56b71dbf85 100644 --- a/crypto/hmac-glib.c +++ b/crypto/hmac-glib.c @@ -14,6 +14,7 @@ =20 #include "qemu/osdep.h" #include "qapi/error.h" +#include "qapi/util.h" #include "crypto/hmac.h" #include "hmacpriv.h" =20 @@ -58,7 +59,7 @@ void *qcrypto_hmac_ctx_new(QCryptoHashAlgorithm alg, =20 if (!qcrypto_hmac_supports(alg)) { error_setg(errp, "Unsupported hmac algorithm %s", - QCryptoHashAlgorithm_lookup[alg]); + qapi_enum_lookup(QCryptoHashAlgorithm_lookup, alg)); return NULL; } =20 diff --git a/crypto/hmac-nettle.c b/crypto/hmac-nettle.c index 1d5a915f03..be43511252 100644 --- a/crypto/hmac-nettle.c +++ b/crypto/hmac-nettle.c @@ -14,6 +14,7 @@ =20 #include "qemu/osdep.h" #include "qapi/error.h" +#include "qapi/util.h" #include "crypto/hmac.h" #include "hmacpriv.h" #include @@ -106,7 +107,7 @@ void *qcrypto_hmac_ctx_new(QCryptoHashAlgorithm alg, =20 if (!qcrypto_hmac_supports(alg)) { error_setg(errp, "Unsupported hmac algorithm %s", - QCryptoHashAlgorithm_lookup[alg]); + qapi_enum_lookup(QCryptoHashAlgorithm_lookup, alg)); return NULL; } =20 diff --git a/crypto/pbkdf-gcrypt.c b/crypto/pbkdf-gcrypt.c index 40289858bf..a815138c46 100644 --- a/crypto/pbkdf-gcrypt.c +++ b/crypto/pbkdf-gcrypt.c @@ -22,6 +22,7 @@ #include #include "qapi/error.h" #include "crypto/pbkdf.h" +#include "qapi/util.h" =20 bool qcrypto_pbkdf2_supports(QCryptoHashAlgorithm hash) { @@ -68,7 +69,7 @@ int qcrypto_pbkdf2(QCryptoHashAlgorithm hash, hash_map[hash] =3D=3D GCRY_MD_NONE) { error_setg_errno(errp, ENOSYS, "PBKDF does not support hash algorithm %s", - QCryptoHashAlgorithm_lookup[hash]); + qapi_enum_lookup(QCryptoHashAlgorithm_lookup, has= h)); return -1; } =20 diff --git a/crypto/pbkdf-nettle.c b/crypto/pbkdf-nettle.c index 6fb2671656..84977fdd69 100644 --- a/crypto/pbkdf-nettle.c +++ b/crypto/pbkdf-nettle.c @@ -23,7 +23,7 @@ #include #include "qapi/error.h" #include "crypto/pbkdf.h" - +#include "qapi/util.h" =20 bool qcrypto_pbkdf2_supports(QCryptoHashAlgorithm hash) { @@ -110,7 +110,7 @@ int qcrypto_pbkdf2(QCryptoHashAlgorithm hash, default: error_setg_errno(errp, ENOSYS, "PBKDF does not support hash algorithm %s", - QCryptoHashAlgorithm_lookup[hash]); + qapi_enum_lookup(QCryptoHashAlgorithm_lookup, has= h)); return -1; } return 0; diff --git a/hmp.c b/hmp.c index fd80dce758..29e42ab661 100644 --- a/hmp.c +++ b/hmp.c @@ -107,7 +107,8 @@ void hmp_info_status(Monitor *mon, const QDict *qdict) info->singlestep ? " (single step mode)" : ""); =20 if (!info->running && info->status !=3D RUN_STATE_PAUSED) { - monitor_printf(mon, " (%s)", RunState_lookup[info->status]); + monitor_printf(mon, " (%s)", + qapi_enum_lookup(RunState_lookup, info->status)); } =20 monitor_printf(mon, "\n"); @@ -172,7 +173,8 @@ void hmp_info_migrate(Monitor *mon, const QDict *qdict) monitor_printf(mon, "capabilities: "); for (cap =3D caps; cap; cap =3D cap->next) { monitor_printf(mon, "%s: %s ", - MigrationCapability_lookup[cap->value->capabili= ty], + qapi_enum_lookup(MigrationCapability_lookup, + cap->value->capability), cap->value->state ? "on" : "off"); } monitor_printf(mon, "\n"); @@ -180,7 +182,7 @@ void hmp_info_migrate(Monitor *mon, const QDict *qdict) =20 if (info->has_status) { monitor_printf(mon, "Migration status: %s", - MigrationStatus_lookup[info->status]); + qapi_enum_lookup(MigrationStatus_lookup, info->stat= us)); if (info->status =3D=3D MIGRATION_STATUS_FAILED && info->has_error_desc) { monitor_printf(mon, " (%s)\n", info->error_desc); @@ -278,7 +280,8 @@ void hmp_info_migrate_capabilities(Monitor *mon, const = QDict *qdict) if (caps) { for (cap =3D caps; cap; cap =3D cap->next) { monitor_printf(mon, "%s: %s\n", - MigrationCapability_lookup[cap->value->capabili= ty], + qapi_enum_lookup(MigrationCapability_lookup, + cap->value->capability), cap->value->state ? "on" : "off"); } } @@ -295,48 +298,59 @@ void hmp_info_migrate_parameters(Monitor *mon, const = QDict *qdict) if (params) { assert(params->has_compress_level); monitor_printf(mon, "%s: %" PRId64 "\n", - MigrationParameter_lookup[MIGRATION_PARAMETER_COMPRESS_LEVEL], + qapi_enum_lookup(MigrationParameter_lookup, + MIGRATION_PARAMETER_COMPRESS_LEVEL), params->compress_level); assert(params->has_compress_threads); monitor_printf(mon, "%s: %" PRId64 "\n", - MigrationParameter_lookup[MIGRATION_PARAMETER_COMPRESS_THREADS= ], + qapi_enum_lookup(MigrationParameter_lookup, + MIGRATION_PARAMETER_COMPRESS_THREADS), params->compress_threads); assert(params->has_decompress_threads); monitor_printf(mon, "%s: %" PRId64 "\n", - MigrationParameter_lookup[MIGRATION_PARAMETER_DECOMPRESS_THREA= DS], + qapi_enum_lookup(MigrationParameter_lookup, + MIGRATION_PARAMETER_DECOMPRESS_THREADS), params->decompress_threads); assert(params->has_cpu_throttle_initial); monitor_printf(mon, "%s: %" PRId64 "\n", - MigrationParameter_lookup[MIGRATION_PARAMETER_CPU_THROTTLE_INI= TIAL], + qapi_enum_lookup(MigrationParameter_lookup, + MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL), params->cpu_throttle_initial); assert(params->has_cpu_throttle_increment); monitor_printf(mon, "%s: %" PRId64 "\n", - MigrationParameter_lookup[MIGRATION_PARAMETER_CPU_THROTTLE_INC= REMENT], + qapi_enum_lookup(MigrationParameter_lookup, + MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT), params->cpu_throttle_increment); assert(params->has_tls_creds); monitor_printf(mon, "%s: '%s'\n", - MigrationParameter_lookup[MIGRATION_PARAMETER_TLS_CREDS], + qapi_enum_lookup(MigrationParameter_lookup, + MIGRATION_PARAMETER_TLS_CREDS), params->tls_creds); assert(params->has_tls_hostname); monitor_printf(mon, "%s: '%s'\n", - MigrationParameter_lookup[MIGRATION_PARAMETER_TLS_HOSTNAME], + qapi_enum_lookup(MigrationParameter_lookup, + MIGRATION_PARAMETER_TLS_HOSTNAME), params->tls_hostname); assert(params->has_max_bandwidth); monitor_printf(mon, "%s: %" PRId64 " bytes/second\n", - MigrationParameter_lookup[MIGRATION_PARAMETER_MAX_BANDWIDTH], + qapi_enum_lookup(MigrationParameter_lookup, + MIGRATION_PARAMETER_MAX_BANDWIDTH), params->max_bandwidth); assert(params->has_downtime_limit); monitor_printf(mon, "%s: %" PRId64 " milliseconds\n", - MigrationParameter_lookup[MIGRATION_PARAMETER_DOWNTIME_LIMIT], + qapi_enum_lookup(MigrationParameter_lookup, + MIGRATION_PARAMETER_DOWNTIME_LIMIT), params->downtime_limit); assert(params->has_x_checkpoint_delay); monitor_printf(mon, "%s: %" PRId64 "\n", - MigrationParameter_lookup[MIGRATION_PARAMETER_X_CHECKPOINT_DEL= AY], + qapi_enum_lookup(MigrationParameter_lookup, + MIGRATION_PARAMETER_X_CHECKPOINT_DELAY), params->x_checkpoint_delay); assert(params->has_block_incremental); monitor_printf(mon, "%s: %s\n", - MigrationParameter_lookup[MIGRATION_PARAMETER_BLOCK_INCREMENTA= L], - params->block_incremental ? "on" : "off"); + qapi_enum_lookup(MigrationParameter_lookup, + MIGRATION_PARAMETER_BLOCK_INCREMENTAL), + params->block_incremental ? "on" : "off"); } =20 qapi_free_MigrationParameters(params); @@ -432,7 +446,7 @@ static void print_block_info(Monitor *mon, BlockInfo *i= nfo, } if (info->has_io_status && info->io_status !=3D BLOCK_DEVICE_IO_ST= ATUS_OK) { monitor_printf(mon, " I/O status: %s\n", - BlockDeviceIoStatus_lookup[info->io_status]); + qapi_enum_lookup(BlockDeviceIoStatus_lookup, info->io_stat= us)); } =20 if (info->removable) { @@ -462,7 +476,8 @@ static void print_block_info(Monitor *mon, BlockInfo *i= nfo, =20 if (inserted->detect_zeroes !=3D BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) { monitor_printf(mon, " Detect zeroes: %s\n", - BlockdevDetectZeroesOptions_lookup[inserted->detect= _zeroes]); + qapi_enum_lookup(BlockdevDetectZeroesOptions_lookup, + inserted->detect_zeroes)); } =20 if (inserted->bps || inserted->bps_rd || inserted->bps_wr || @@ -613,7 +628,7 @@ static void hmp_info_VncBasicInfo(Monitor *mon, VncBasi= cInfo *info, name, info->host, info->service, - NetworkAddressFamily_lookup[info->family], + qapi_enum_lookup(NetworkAddressFamily_lookup, info->fam= ily), info->websocket ? " (Websocket)" : ""); } =20 @@ -623,8 +638,9 @@ static void hmp_info_vnc_authcrypt(Monitor *mon, const = char *indent, VncVencryptSubAuth *vencrypt) { monitor_printf(mon, "%sAuth: %s (Sub: %s)\n", indent, - VncPrimaryAuth_lookup[auth], - vencrypt ? VncVencryptSubAuth_lookup[*vencrypt] : "none= "); + qapi_enum_lookup(VncPrimaryAuth_lookup, auth), + vencrypt ? qapi_enum_lookup(VncVencryptSubAuth_lookup, *vencrypt) + : "none"); } =20 static void hmp_info_vnc_clients(Monitor *mon, VncClientInfoList *client) @@ -739,7 +755,7 @@ void hmp_info_spice(Monitor *mon, const QDict *qdict) monitor_printf(mon, " auth: %s\n", info->auth); monitor_printf(mon, " compiled: %s\n", info->compiled_version); monitor_printf(mon, " mouse-mode: %s\n", - SpiceQueryMouseMode_lookup[info->mouse_mode]); + qapi_enum_lookup(SpiceQueryMouseMode_lookup, info->mouse_mode)); =20 if (!info->has_channels || info->channels =3D=3D NULL) { monitor_printf(mon, "Channels: none\n"); @@ -1010,10 +1026,11 @@ void hmp_info_tpm(Monitor *mon, const QDict *qdict) for (info =3D info_list; info; info =3D info->next) { TPMInfo *ti =3D info->value; monitor_printf(mon, " tpm%d: model=3D%s\n", - c, TpmModel_lookup[ti->model]); + c, qapi_enum_lookup(TpmModel_lookup, ti->model)); =20 monitor_printf(mon, " \\ %s: type=3D%s", - ti->id, TpmTypeOptionsKind_lookup[ti->options->type= ]); + ti->id, qapi_enum_lookup(TpmTypeOptionsKind_lookup, + ti->options->type)); =20 switch (ti->options->type) { case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH: @@ -2374,7 +2391,7 @@ void hmp_info_memdev(Monitor *mon, const QDict *qdict) monitor_printf(mon, " prealloc: %s\n", m->value->prealloc ? "true" : "false"); monitor_printf(mon, " policy: %s\n", - HostMemPolicy_lookup[m->value->policy]); + qapi_enum_lookup(HostMemPolicy_lookup, m->value->policy)); visit_complete(v, &str); monitor_printf(mon, " host nodes: %s\n", str); =20 @@ -2405,8 +2422,8 @@ void hmp_info_memory_devices(Monitor *mon, const QDic= t *qdict) di =3D value->u.dimm.data; =20 monitor_printf(mon, "Memory device [%s]: \"%s\"\n", - MemoryDeviceInfoKind_lookup[value->type], - di->id ? di->id : ""); + qapi_enum_lookup(MemoryDeviceInfoKind_lookup, value->t= ype), + di->id ? di->id : ""); monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr); monitor_printf(mon, " slot: %" PRId64 "\n", di->slot); monitor_printf(mon, " node: %" PRId64 "\n", di->node); @@ -2799,7 +2816,8 @@ void hmp_info_dump(Monitor *mon, const QDict *qdict) DumpQueryResult *result =3D qmp_query_dump(NULL); =20 assert(result && result->status < DUMP_STATUS__MAX); - monitor_printf(mon, "Status: %s\n", DumpStatus_lookup[result->status]); + monitor_printf(mon, "Status: %s\n", + qapi_enum_lookup(DumpStatus_lookup, result->status)); =20 if (result->status =3D=3D DUMP_STATUS_ACTIVE) { float percent =3D 0; diff --git a/hw/block/fdc.c b/hw/block/fdc.c index 401129073b..8ebe08d1af 100644 --- a/hw/block/fdc.c +++ b/hw/block/fdc.c @@ -31,6 +31,7 @@ #include "hw/hw.h" #include "hw/block/fdc.h" #include "qapi/error.h" +#include "qapi/util.h" #include "qemu/error-report.h" #include "qemu/timer.h" #include "hw/isa/isa.h" @@ -392,9 +393,11 @@ static int pick_geometry(FDrive *drv) FLOPPY_DPRINTF("User requested floppy drive type '%s', " "but inserted medium appears to be a " "%"PRId64" sector '%s' type\n", - FloppyDriveType_lookup[drv->drive], + qapi_enum_lookup(FloppyDriveType_lookup, + drv->drive), nb_sectors, - FloppyDriveType_lookup[parse->drive]); + qapi_enum_lookup(FloppyDriveType_lookup, + parse->drive)); } match =3D type_match; } @@ -403,7 +406,7 @@ static int pick_geometry(FDrive *drv) if (match =3D=3D -1) { error_setg(&error_abort, "No candidate geometries present in table= " " for floppy drive type '%s'", - FloppyDriveType_lookup[drv->drive]); + qapi_enum_lookup(FloppyDriveType_lookup, drv->drive)); } =20 parse =3D &(fd_formats[match]); diff --git a/hw/char/escc.c b/hw/char/escc.c index 1aca564e33..5c1d7b0e29 100644 --- a/hw/char/escc.c +++ b/hw/char/escc.c @@ -31,6 +31,7 @@ #include "ui/console.h" #include "ui/input.h" #include "trace.h" +#include "qapi/util.h" =20 /* * Chipset docs: @@ -848,7 +849,7 @@ static void sunkbd_handle_event(DeviceState *dev, QemuC= onsole *src, assert(evt->type =3D=3D INPUT_EVENT_KIND_KEY); key =3D evt->u.key.data; qcode =3D qemu_input_key_value_to_qcode(key->key); - trace_escc_sunkbd_event_in(qcode, QKeyCode_lookup[qcode], + trace_escc_sunkbd_event_in(qcode, qapi_enum_lookup(QKeyCode_lookup, qc= ode), key->down); =20 if (qcode =3D=3D Q_KEY_CODE_CAPS_LOCK) { diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index 078fc5d239..c82c693bca 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -2,6 +2,7 @@ #include "net/net.h" #include "hw/qdev.h" #include "qapi/error.h" +#include "qapi/util.h" #include "hw/pci/pci.h" #include "qapi/qmp/qerror.h" #include "qemu/error-report.h" @@ -72,8 +73,9 @@ static void set_enum(Object *obj, Visitor *v, const char = *name, void *opaque, =20 static void set_default_value_enum(Object *obj, const Property *prop) { - object_property_set_str(obj, prop->info->enum_table[prop->defval.i], - prop->name, &error_abort); + object_property_set_str(obj, + qapi_enum_lookup(prop->info->enum_table, prop->defval.i), + prop->name, &error_abort); } =20 /* Bit */ @@ -1095,7 +1097,8 @@ void qdev_prop_set_enum(DeviceState *dev, const char = *name, int value) Property *prop; =20 prop =3D qdev_prop_find(dev, name); - object_property_set_str(OBJECT(dev), prop->info->enum_table[value], + object_property_set_str(OBJECT(dev), + qapi_enum_lookup(prop->info->enum_table, value= ), name, &error_abort); } =20 diff --git a/hw/input/virtio-input-hid.c b/hw/input/virtio-input-hid.c index 46c038110c..64039236f1 100644 --- a/hw/input/virtio-input-hid.c +++ b/hw/input/virtio-input-hid.c @@ -15,6 +15,7 @@ #include "ui/console.h" =20 #include "standard-headers/linux/input.h" +#include "qapi/util.h" =20 #define VIRTIO_ID_NAME_KEYBOARD "QEMU Virtio Keyboard" #define VIRTIO_ID_NAME_MOUSE "QEMU Virtio Mouse" @@ -209,7 +210,7 @@ static void virtio_input_handle_event(DeviceState *dev,= QemuConsole *src, } else { if (key->down) { fprintf(stderr, "%s: unmapped key: %d [%s]\n", __func__, - qcode, QKeyCode_lookup[qcode]); + qcode, qapi_enum_lookup(QKeyCode_lookup, qcode)); } } break; @@ -224,7 +225,7 @@ static void virtio_input_handle_event(DeviceState *dev,= QemuConsole *src, if (btn->down) { fprintf(stderr, "%s: unmapped button: %d [%s]\n", __func__, btn->button, - InputButton_lookup[btn->button]); + qapi_enum_lookup(InputButton_lookup, btn->button)); } } break; diff --git a/migration/colo-failover.c b/migration/colo-failover.c index f9914869c5..e5394ba631 100644 --- a/migration/colo-failover.c +++ b/migration/colo-failover.c @@ -17,6 +17,7 @@ #include "migration.h" #include "qmp-commands.h" #include "qapi/qmp/qerror.h" +#include "qapi/util.h" #include "qemu/error-report.h" #include "trace.h" =20 @@ -34,7 +35,7 @@ static void colo_failover_bh(void *opaque) FAILOVER_STATUS_ACTIVE); if (old_state !=3D FAILOVER_STATUS_REQUIRE) { error_report("Unknown error for failover, old_state =3D %s", - FailoverStatus_lookup[old_state]); + qapi_enum_lookup(FailoverStatus_lookup, old_state)); return; } =20 @@ -64,7 +65,8 @@ FailoverStatus failover_set_state(FailoverStatus old_stat= e, =20 old =3D atomic_cmpxchg(&failover_state, old_state, new_state); if (old =3D=3D old_state) { - trace_colo_failover_set_state(FailoverStatus_lookup[new_state]); + trace_colo_failover_set_state(qapi_enum_lookup(FailoverStatus_look= up, + new_state)); } return old; } diff --git a/migration/colo.c b/migration/colo.c index a4255432ac..2b683a0afc 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -24,6 +24,7 @@ #include "migration/failover.h" #include "replication.h" #include "qmp-commands.h" +#include "qapi/util.h" =20 static bool vmstate_loading; =20 @@ -61,7 +62,8 @@ static void secondary_vm_do_failover(void) FAILOVER_STATUS_RELAUNCH); if (old_state !=3D FAILOVER_STATUS_ACTIVE) { error_report("Unknown error while do failover for secondary VM= ," - "old_state: %s", FailoverStatus_lookup[old_state]= ); + "old_state: %s", + qapi_enum_lookup(FailoverStatus_lookup, old_state= )); } return; } @@ -91,7 +93,8 @@ static void secondary_vm_do_failover(void) FAILOVER_STATUS_COMPLETED); if (old_state !=3D FAILOVER_STATUS_ACTIVE) { error_report("Incorrect state (%s) while doing failover for " - "secondary VM", FailoverStatus_lookup[old_state]); + "secondary VM", + qapi_enum_lookup(FailoverStatus_lookup, old_state)); return; } /* Notify COLO incoming thread that failover work is finished */ @@ -126,7 +129,7 @@ static void primary_vm_do_failover(void) FAILOVER_STATUS_COMPLETED); if (old_state !=3D FAILOVER_STATUS_ACTIVE) { error_report("Incorrect state (%s) while doing failover for Primar= y VM", - FailoverStatus_lookup[old_state]); + qapi_enum_lookup(FailoverStatus_lookup, old_state)); return; } /* Notify COLO thread that failover work is finished */ @@ -222,7 +225,7 @@ static void colo_send_message(QEMUFile *f, COLOMessage = msg, if (ret < 0) { error_setg_errno(errp, -ret, "Can't send COLO message"); } - trace_colo_send_message(COLOMessage_lookup[msg]); + trace_colo_send_message(qapi_enum_lookup(COLOMessage_lookup, msg)); } =20 static void colo_send_message_value(QEMUFile *f, COLOMessage msg, @@ -242,7 +245,7 @@ static void colo_send_message_value(QEMUFile *f, COLOMe= ssage msg, ret =3D qemu_file_get_error(f); if (ret < 0) { error_setg_errno(errp, -ret, "Failed to send value for message:%s", - COLOMessage_lookup[msg]); + qapi_enum_lookup(COLOMessage_lookup, msg)); } } =20 @@ -261,7 +264,7 @@ static COLOMessage colo_receive_message(QEMUFile *f, Er= ror **errp) error_setg(errp, "%s: Invalid message", __func__); return msg; } - trace_colo_receive_message(COLOMessage_lookup[msg]); + trace_colo_receive_message(qapi_enum_lookup(COLOMessage_lookup, msg)); return msg; } =20 @@ -299,7 +302,7 @@ static uint64_t colo_receive_message_value(QEMUFile *f,= uint32_t expect_msg, ret =3D qemu_file_get_error(f); if (ret < 0) { error_setg_errno(errp, -ret, "Failed to get value for COLO message= : %s", - COLOMessage_lookup[expect_msg]); + qapi_enum_lookup(COLOMessage_lookup, expect_msg)); } return value; } diff --git a/migration/global_state.c b/migration/global_state.c index dcbbcb28be..4d57a9c5f2 100644 --- a/migration/global_state.c +++ b/migration/global_state.c @@ -42,7 +42,7 @@ int global_state_store(void) =20 void global_state_store_running(void) { - const char *state =3D RunState_lookup[RUN_STATE_RUNNING]; + const char *state =3D qapi_enum_lookup(RunState_lookup, RUN_STATE_RUNN= ING); strncpy((char *)global_state.runstate, state, sizeof(global_state.runstate)); } diff --git a/monitor.c b/monitor.c index 14c27d4b6f..ee2fdfd4f1 100644 --- a/monitor.c +++ b/monitor.c @@ -78,6 +78,7 @@ #include "sysemu/cpus.h" #include "qemu/cutils.h" #include "qapi/qmp/dispatch.h" +#include "qapi/util.h" =20 #if defined(TARGET_S390X) #include "hw/s390x/storage-keys.h" @@ -928,7 +929,7 @@ EventInfoList *qmp_query_events(Error **errp) QAPIEvent e; =20 for (e =3D 0 ; e < QAPI_EVENT__MAX ; e++) { - const char *event_name =3D QAPIEvent_lookup[e]; + const char *event_name =3D qapi_enum_lookup(QAPIEvent_lookup, e); assert(event_name !=3D NULL); info =3D g_malloc0(sizeof(*info)); info->value =3D g_malloc0(sizeof(*info->value)); @@ -3249,8 +3250,9 @@ void netdev_add_completion(ReadLineState *rs, int nb_= args, const char *str) } len =3D strlen(str); readline_set_completion_index(rs, len); - for (i =3D 0; NetClientDriver_lookup[i]; i++) { - add_completion_option(rs, str, NetClientDriver_lookup[i]); + for (i =3D 0; qapi_enum_lookup(NetClientDriver_lookup, i); i++) { + add_completion_option(rs, str, + qapi_enum_lookup(NetClientDriver_lookup, i)); } } =20 @@ -3434,8 +3436,8 @@ void sendkey_completion(ReadLineState *rs, int nb_arg= s, const char *str) len =3D strlen(str); readline_set_completion_index(rs, len); for (i =3D 0; i < Q_KEY_CODE__MAX; i++) { - if (!strncmp(str, QKeyCode_lookup[i], len)) { - readline_add_completion(rs, QKeyCode_lookup[i]); + if (!strncmp(str, qapi_enum_lookup(QKeyCode_lookup, i), len)) { + readline_add_completion(rs, qapi_enum_lookup(QKeyCode_lookup, = i)); } } } @@ -3537,8 +3539,9 @@ void watchdog_action_completion(ReadLineState *rs, in= t nb_args, const char *str) return; } readline_set_completion_index(rs, strlen(str)); - for (i =3D 0; WatchdogExpirationAction_lookup[i]; i++) { - add_completion_option(rs, str, WatchdogExpirationAction_lookup[i]); + for (i =3D 0; qapi_enum_lookup(WatchdogExpirationAction_lookup, i); i+= +) { + add_completion_option(rs, str, + qapi_enum_lookup(WatchdogExpirationAction_lookup, i)); } } =20 @@ -3552,7 +3555,7 @@ void migrate_set_capability_completion(ReadLineState = *rs, int nb_args, if (nb_args =3D=3D 2) { int i; for (i =3D 0; i < MIGRATION_CAPABILITY__MAX; i++) { - const char *name =3D MigrationCapability_lookup[i]; + const char *name =3D qapi_enum_lookup(MigrationCapability_look= up, i); if (!strncmp(str, name, len)) { readline_add_completion(rs, name); } @@ -3573,7 +3576,7 @@ void migrate_set_parameter_completion(ReadLineState *= rs, int nb_args, if (nb_args =3D=3D 2) { int i; for (i =3D 0; i < MIGRATION_PARAMETER__MAX; i++) { - const char *name =3D MigrationParameter_lookup[i]; + const char *name =3D qapi_enum_lookup(MigrationParameter_looku= p, i); if (!strncmp(str, name, len)) { readline_add_completion(rs, name); } @@ -3852,7 +3855,8 @@ static void handle_qmp_command(JSONMessageParser *par= ser, GQueue *tokens) qdict =3D qdict_get_qdict(qobject_to_qdict(rsp), "error"); if (qdict && !g_strcmp0(qdict_get_try_str(qdict, "class"), - QapiErrorClass_lookup[ERROR_CLASS_COMMAND_NOT_FOUND]))= { + qapi_enum_lookup(QapiErrorClass_lookup, + ERROR_CLASS_COMMAND_NOT_FOUND))= ) { /* Provide a more useful error message */ qdict_del(qdict, "desc"); qdict_put_str(qdict, "desc", "Expecting capabilities negotiati= on" diff --git a/net/net.c b/net/net.c index 0e28099554..efe2252c59 100644 --- a/net/net.c +++ b/net/net.c @@ -48,6 +48,7 @@ #include "sysemu/qtest.h" #include "net/filter.h" #include "qapi/string-output-visitor.h" +#include "qapi/util.h" =20 /* Net bridge is currently not supported for W32. */ #if !defined(_WIN32) @@ -1064,7 +1065,7 @@ static int net_client_init1(const void *object, bool = is_netdev, Error **errp) /* FIXME drop when all init functions store an Error */ if (errp && !*errp) { error_setg(errp, QERR_DEVICE_INIT_FAILED, - NetClientDriver_lookup[netdev->type]); + qapi_enum_lookup(NetClientDriver_lookup, netdev->ty= pe)); } return -1; } @@ -1288,7 +1289,7 @@ void print_net_client(Monitor *mon, NetClientState *n= c) =20 monitor_printf(mon, "%s: index=3D%d,type=3D%s,%s\n", nc->name, nc->queue_index, - NetClientDriver_lookup[nc->info->type], + qapi_enum_lookup(NetClientDriver_lookup, nc->info->type= ), nc->info_str); if (!QTAILQ_EMPTY(&nc->filters)) { monitor_printf(mon, "filters:\n"); diff --git a/qapi/qapi-util.c b/qapi/qapi-util.c index 46eda7d196..7677caa51e 100644 --- a/qapi/qapi-util.c +++ b/qapi/qapi-util.c @@ -34,6 +34,13 @@ int qapi_enum_parse(const char * const lookup[], const c= har *buf, return def; } =20 +const char *qapi_enum_lookup(const char * const lookup[], int val) +{ + assert(val >=3D 0); + + return lookup[val]; +} + /* * Parse a valid QAPI name from @str. * A valid name consists of letters, digits, hyphen and underscore. diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index 5ad36f8a09..06f1470516 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -19,6 +19,7 @@ #include "qapi/qmp/qjson.h" #include "qapi-types.h" #include "qapi/qmp/qerror.h" +#include "qapi/util.h" =20 static QDict *qmp_dispatch_check_obj(const QObject *request, Error **errp) { @@ -118,7 +119,8 @@ static QObject *do_qmp_dispatch(QmpCommandList *cmds, Q= Object *request, QObject *qmp_build_error_object(Error *err) { return qobject_from_jsonf("{ 'class': %s, 'desc': %s }", - QapiErrorClass_lookup[error_get_class(err)], + qapi_enum_lookup(QapiErrorClass_lookup, + error_get_class(err)), error_get_pretty(err)); } =20 diff --git a/tests/test-qobject-output-visitor.c b/tests/test-qobject-outpu= t-visitor.c index 7eb162059c..bb2d66b666 100644 --- a/tests/test-qobject-output-visitor.c +++ b/tests/test-qobject-output-visitor.c @@ -19,6 +19,7 @@ #include "test-qapi-visit.h" #include "qapi/qmp/types.h" #include "qapi/qmp/qjson.h" +#include "qapi/util.h" =20 typedef struct TestOutputVisitorData { Visitor *ov; @@ -133,7 +134,8 @@ static void test_visitor_out_enum(TestOutputVisitorData= *data, =20 qstr =3D qobject_to_qstring(visitor_get(data)); g_assert(qstr); - g_assert_cmpstr(qstring_get_str(qstr), =3D=3D, EnumOne_lookup[i]); + g_assert_cmpstr(qstring_get_str(qstr), =3D=3D, + qapi_enum_lookup(EnumOne_lookup, i)); visitor_reset(data); } } diff --git a/tests/test-string-output-visitor.c b/tests/test-string-output-= visitor.c index e736db3af8..0b2087d312 100644 --- a/tests/test-string-output-visitor.c +++ b/tests/test-string-output-visitor.c @@ -14,6 +14,7 @@ =20 #include "qemu-common.h" #include "qapi/error.h" +#include "qapi/util.h" #include "qapi/string-output-visitor.h" #include "test-qapi-types.h" #include "test-qapi-visit.h" @@ -194,12 +195,13 @@ static void test_visitor_out_enum(TestOutputVisitorDa= ta *data, =20 str =3D visitor_get(data); if (data->human) { - char *str_human =3D g_strdup_printf("\"%s\"", EnumOne_lookup[i= ]); + char *str_human =3D + g_strdup_printf("\"%s\"", qapi_enum_lookup(EnumOne_lookup,= i)); =20 g_assert_cmpstr(str, =3D=3D, str_human); g_free(str_human); } else { - g_assert_cmpstr(str, =3D=3D, EnumOne_lookup[i]); + g_assert_cmpstr(str, =3D=3D, qapi_enum_lookup(EnumOne_lookup, = i)); } visitor_reset(data); } diff --git a/tpm.c b/tpm.c index 9a7c7114d3..c3b731b3f2 100644 --- a/tpm.c +++ b/tpm.c @@ -19,6 +19,7 @@ #include "qemu/config-file.h" #include "qemu/error-report.h" #include "qmp-commands.h" +#include "qapi/util.h" =20 static QLIST_HEAD(, TPMBackend) tpm_backends =3D QLIST_HEAD_INITIALIZER(tpm_backends); @@ -102,7 +103,8 @@ static void tpm_display_backend_drivers(void) =20 for (i =3D 0; i < TPM_MAX_DRIVERS && be_drivers[i] !=3D NULL; i++) { fprintf(stderr, "%12s %s\n", - TpmType_lookup[be_drivers[i]->type], be_drivers[i]->desc()= ); + qapi_enum_lookup(TpmType_lookup, be_drivers[i]->type), + be_drivers[i]->desc()); } fprintf(stderr, "\n"); } diff --git a/ui/input.c b/ui/input.c index af05f06368..6bceb6b825 100644 --- a/ui/input.c +++ b/ui/input.c @@ -7,6 +7,7 @@ #include "ui/input.h" #include "ui/console.h" #include "sysemu/replay.h" +#include "qapi/util.h" =20 struct QemuInputHandlerState { DeviceState *dev; @@ -151,7 +152,7 @@ void qmp_input_send_event(bool has_device, const char *= device, if (!qemu_input_find_handler(1 << event->type, con)) { error_setg(errp, "Input handler not found for " "event type %s", - InputEventKind_lookup[event->type]); + qapi_enum_lookup(InputEventKind_lookup, event->type= )); return; } } @@ -213,12 +214,12 @@ static void qemu_input_event_trace(QemuConsole *src, = InputEvent *evt) switch (key->key->type) { case KEY_VALUE_KIND_NUMBER: qcode =3D qemu_input_key_number_to_qcode(key->key->u.number.da= ta); - name =3D QKeyCode_lookup[qcode]; + name =3D qapi_enum_lookup(QKeyCode_lookup, qcode); trace_input_event_key_number(idx, key->key->u.number.data, name, key->down); break; case KEY_VALUE_KIND_QCODE: - name =3D QKeyCode_lookup[key->key->u.qcode.data]; + name =3D qapi_enum_lookup(QKeyCode_lookup, key->key->u.qcode.d= ata); trace_input_event_key_qcode(idx, name, key->down); break; case KEY_VALUE_KIND__MAX: @@ -228,17 +229,17 @@ static void qemu_input_event_trace(QemuConsole *src, = InputEvent *evt) break; case INPUT_EVENT_KIND_BTN: btn =3D evt->u.btn.data; - name =3D InputButton_lookup[btn->button]; + name =3D qapi_enum_lookup(InputButton_lookup, btn->button); trace_input_event_btn(idx, name, btn->down); break; case INPUT_EVENT_KIND_REL: move =3D evt->u.rel.data; - name =3D InputAxis_lookup[move->axis]; + name =3D qapi_enum_lookup(InputAxis_lookup, move->axis); trace_input_event_rel(idx, name, move->value); break; case INPUT_EVENT_KIND_ABS: move =3D evt->u.abs.data; - name =3D InputAxis_lookup[move->axis]; + name =3D qapi_enum_lookup(InputAxis_lookup, move->axis); trace_input_event_abs(idx, name, move->value); break; case INPUT_EVENT_KIND__MAX: diff --git a/ui/vnc.c b/ui/vnc.c index 651cbb8606..20a45a7241 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -36,6 +36,7 @@ #include "qemu/config-file.h" #include "qapi/qmp/qerror.h" #include "qapi/qmp/types.h" +#include "qapi/util.h" #include "qmp-commands.h" #include "ui/input.h" #include "qapi-event.h" @@ -131,7 +132,7 @@ static void vnc_init_basic_info(SocketAddress *addr, case SOCKET_ADDRESS_TYPE_VSOCK: case SOCKET_ADDRESS_TYPE_FD: error_setg(errp, "Unsupported socket address type %s", - SocketAddressType_lookup[addr->type]); + qapi_enum_lookup(SocketAddressType_lookup, addr->type)); break; default: abort(); @@ -416,7 +417,7 @@ VncInfo *qmp_query_vnc(Error **errp) case SOCKET_ADDRESS_TYPE_VSOCK: case SOCKET_ADDRESS_TYPE_FD: error_setg(errp, "Unsupported socket address type %s", - SocketAddressType_lookup[addr->type]); + qapi_enum_lookup(SocketAddressType_lookup, addr->ty= pe)); goto out_error; default: abort(); @@ -1839,7 +1840,8 @@ static void vnc_release_modifiers(VncState *vs) =20 static const char *code2name(int keycode) { - return QKeyCode_lookup[qemu_input_key_number_to_qcode(keycode)]; + return qapi_enum_lookup(QKeyCode_lookup, + qemu_input_key_number_to_qcode(keycode)); } =20 static void key_event(VncState *vs, int down, uint32_t sym) diff --git a/vl.c b/vl.c index 8e247cc2a2..def4f5f05f 100644 --- a/vl.c +++ b/vl.c @@ -99,6 +99,7 @@ int main(int argc, char **argv) #include "sysemu/hax.h" #include "qapi/qobject-input-visitor.h" #include "qapi/qobject-input-visitor.h" +#include "qapi/util.h" #include "qapi-visit.h" #include "qapi/qmp/qjson.h" #include "qemu/option.h" @@ -688,7 +689,7 @@ bool runstate_check(RunState state) =20 bool runstate_store(char *str, size_t size) { - const char *state =3D RunState_lookup[current_run_state]; + const char *state =3D qapi_enum_lookup(RunState_lookup, current_run_st= ate); size_t len =3D strlen(state) + 1; =20 if (len > size) { @@ -721,8 +722,8 @@ void runstate_set(RunState new_state) =20 if (!runstate_valid_transitions[current_run_state][new_state]) { error_report("invalid runstate transition: '%s' -> '%s'", - RunState_lookup[current_run_state], - RunState_lookup[new_state]); + qapi_enum_lookup(RunState_lookup, current_run_state), + qapi_enum_lookup(RunState_lookup, new_state)); abort(); } trace_runstate_set(new_state); --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 1503409409146185.630027946087; Tue, 22 Aug 2017 06:43:29 -0700 (PDT) Received: from localhost ([::1]:47045 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9Sp-0007gZ-WF for importer@patchew.org; Tue, 22 Aug 2017 09:43:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53712) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9Ez-000469-VM for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:29:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9Ez-0003mU-4N for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:29:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37262) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9Ey-0003mH-R9 for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:29:09 -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 77AD1C058EBD for ; Tue, 22 Aug 2017 13:23:39 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id F221E617A3; Tue, 22 Aug 2017 13:23:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 77AD1C058EBD 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: Tue, 22 Aug 2017 15:22:08 +0200 Message-Id: <20170822132255.23945-8-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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.32]); Tue, 22 Aug 2017 13:23:39 +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/54] tpm: simplify driver registration & lookup 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?= 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 be_drivers[n] match order of TpmType enum. Use qapi_enum_parse() in tpm_get_backend_driver. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Markus Armbruster --- include/sysemu/tpm_backend.h | 2 +- tpm.c | 42 ++++++++++++----------------------------= -- 2 files changed, 13 insertions(+), 31 deletions(-) diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h index b58f52d39f..1d21c6b19b 100644 --- a/include/sysemu/tpm_backend.h +++ b/include/sysemu/tpm_backend.h @@ -227,6 +227,6 @@ TPMBackend *qemu_find_tpm(const char *id); =20 const TPMDriverOps *tpm_get_backend_driver(const char *type); int tpm_register_model(enum TpmModel model); -int tpm_register_driver(const TPMDriverOps *tdo); +void tpm_register_driver(const TPMDriverOps *tdo); =20 #endif diff --git a/tpm.c b/tpm.c index c3b731b3f2..f175661bfe 100644 --- a/tpm.c +++ b/tpm.c @@ -26,9 +26,8 @@ static QLIST_HEAD(, TPMBackend) tpm_backends =3D =20 =20 #define TPM_MAX_MODELS 1 -#define TPM_MAX_DRIVERS 1 =20 -static TPMDriverOps const *be_drivers[TPM_MAX_DRIVERS] =3D { +static TPMDriverOps const *be_drivers[TPM_TYPE__MAX] =3D { NULL, }; =20 @@ -64,31 +63,18 @@ static bool tpm_model_is_registered(enum TpmModel model) =20 const TPMDriverOps *tpm_get_backend_driver(const char *type) { - int i; + int i =3D qapi_enum_parse(TpmType_lookup, type, TPM_TYPE__MAX, -1, NUL= L); =20 - for (i =3D 0; i < TPM_MAX_DRIVERS && be_drivers[i] !=3D NULL; i++) { - if (!strcmp(TpmType_lookup[be_drivers[i]->type], type)) { - return be_drivers[i]; - } - } - - return NULL; + return i >=3D 0 ? be_drivers[i] : NULL; } =20 #ifdef CONFIG_TPM =20 -int tpm_register_driver(const TPMDriverOps *tdo) +void tpm_register_driver(const TPMDriverOps *tdo) { - int i; + assert(!be_drivers[tdo->type]); =20 - for (i =3D 0; i < TPM_MAX_DRIVERS; i++) { - if (!be_drivers[i]) { - be_drivers[i] =3D tdo; - return 0; - } - } - error_report("Could not register TPM driver"); - return 1; + be_drivers[tdo->type] =3D tdo; } =20 /* @@ -101,9 +87,12 @@ static void tpm_display_backend_drivers(void) =20 fprintf(stderr, "Supported TPM types (choose only one):\n"); =20 - for (i =3D 0; i < TPM_MAX_DRIVERS && be_drivers[i] !=3D NULL; i++) { + for (i =3D 0; i < TPM_TYPE__MAX; i++) { + if (be_drivers[i] =3D=3D NULL) { + continue; + } fprintf(stderr, "%12s %s\n", - qapi_enum_lookup(TpmType_lookup, be_drivers[i]->type), + qapi_enum_lookup(TpmType_lookup, i), be_drivers[i]->desc()); } fprintf(stderr, "\n"); @@ -241,14 +230,7 @@ int tpm_config_parse(QemuOptsList *opts_list, const ch= ar *optarg) =20 static const TPMDriverOps *tpm_driver_find_by_type(enum TpmType type) { - int i; - - for (i =3D 0; i < TPM_MAX_DRIVERS && be_drivers[i] !=3D NULL; i++) { - if (be_drivers[i]->type =3D=3D type) { - return be_drivers[i]; - } - } - return NULL; + return be_drivers[type]; } =20 static TPMInfo *qmp_query_tpm_inst(TPMBackend *drv) --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 1503410527326544.363022327412; Tue, 22 Aug 2017 07:02:07 -0700 (PDT) Received: from localhost ([::1]:47262 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9kr-0007CZ-BW for importer@patchew.org; Tue, 22 Aug 2017 10:02:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54820) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9Hp-0006ge-9t for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:32:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9Hm-00066l-2c for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:32:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44188) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9Hl-00065U-SA for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:32:02 -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 E301B8123A for ; Tue, 22 Aug 2017 13:23:43 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id A27A081E27; Tue, 22 Aug 2017 13:23:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E301B8123A 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: Tue, 22 Aug 2017 15:22:09 +0200 Message-Id: <20170822132255.23945-9-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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.25]); Tue, 22 Aug 2017 13:23: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 08/54] hmp: use qapi_enum_parse() in hmp_migrate_set_capability 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?= , "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" Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Markus Armbruster --- hmp.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/hmp.c b/hmp.c index 29e42ab661..4ba50e8e26 100644 --- a/hmp.c +++ b/hmp.c @@ -1544,23 +1544,21 @@ void hmp_migrate_set_capability(Monitor *mon, const= QDict *qdict) bool state =3D qdict_get_bool(qdict, "state"); Error *err =3D NULL; MigrationCapabilityStatusList *caps =3D g_malloc0(sizeof(*caps)); - int i; + int val; =20 - for (i =3D 0; i < MIGRATION_CAPABILITY__MAX; i++) { - if (strcmp(cap, MigrationCapability_lookup[i]) =3D=3D 0) { - caps->value =3D g_malloc0(sizeof(*caps->value)); - caps->value->capability =3D i; - caps->value->state =3D state; - caps->next =3D NULL; - qmp_migrate_set_capabilities(caps, &err); - break; - } + val =3D qapi_enum_parse(MigrationCapability_lookup, cap, + MIGRATION_CAPABILITY__MAX, -1, &err); + if (val < 0) { + goto end; } =20 - if (i =3D=3D MIGRATION_CAPABILITY__MAX) { - error_setg(&err, QERR_INVALID_PARAMETER, cap); - } + caps->value =3D g_malloc0(sizeof(*caps->value)); + caps->value->capability =3D val; + caps->value->state =3D state; + caps->next =3D NULL; + qmp_migrate_set_capabilities(caps, &err); =20 +end: qapi_free_MigrationCapabilityStatusList(caps); =20 if (err) { --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 1503411397376334.5191046793067; Tue, 22 Aug 2017 07:16:37 -0700 (PDT) Received: from localhost ([::1]:47459 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9yu-000211-3s for importer@patchew.org; Tue, 22 Aug 2017 10:16:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55287) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9JR-00085E-Kg for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9JQ-00074f-4j for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38646) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9JP-00073R-RF for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:44 -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 33647883DC for ; Tue, 22 Aug 2017 13:23:49 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 99F9A7E57E; Tue, 22 Aug 2017 13:23:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 33647883DC 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: Tue, 22 Aug 2017 15:22:10 +0200 Message-Id: <20170822132255.23945-10-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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.26]); Tue, 22 Aug 2017 13:23:49 +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/54] hmp: use qapi_enum_parse() in hmp_migrate_set_parameter 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?= , "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" Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Markus Armbruster --- hmp.c | 139 ++++++++++++++++++++++++++++++++------------------------------= ---- 1 file changed, 68 insertions(+), 71 deletions(-) diff --git a/hmp.c b/hmp.c index 4ba50e8e26..ccc58e6d88 100644 --- a/hmp.c +++ b/hmp.c @@ -1574,84 +1574,81 @@ void hmp_migrate_set_parameter(Monitor *mon, const = QDict *qdict) MigrateSetParameters *p =3D g_new0(MigrateSetParameters, 1); uint64_t valuebw =3D 0; Error *err =3D NULL; - int i, ret; - - for (i =3D 0; i < MIGRATION_PARAMETER__MAX; i++) { - if (strcmp(param, MigrationParameter_lookup[i]) =3D=3D 0) { - switch (i) { - case MIGRATION_PARAMETER_COMPRESS_LEVEL: - p->has_compress_level =3D true; - visit_type_int(v, param, &p->compress_level, &err); - break; - case MIGRATION_PARAMETER_COMPRESS_THREADS: - p->has_compress_threads =3D true; - visit_type_int(v, param, &p->compress_threads, &err); - break; - case MIGRATION_PARAMETER_DECOMPRESS_THREADS: - p->has_decompress_threads =3D true; - visit_type_int(v, param, &p->decompress_threads, &err); - break; - case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL: - p->has_cpu_throttle_initial =3D true; - visit_type_int(v, param, &p->cpu_throttle_initial, &err); - break; - case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT: - p->has_cpu_throttle_increment =3D true; - visit_type_int(v, param, &p->cpu_throttle_increment, &err); - break; - case MIGRATION_PARAMETER_TLS_CREDS: - p->has_tls_creds =3D true; - p->tls_creds =3D g_new0(StrOrNull, 1); - p->tls_creds->type =3D QTYPE_QSTRING; - visit_type_str(v, param, &p->tls_creds->u.s, &err); - break; - case MIGRATION_PARAMETER_TLS_HOSTNAME: - p->has_tls_hostname =3D true; - p->tls_hostname =3D g_new0(StrOrNull, 1); - p->tls_hostname->type =3D QTYPE_QSTRING; - visit_type_str(v, param, &p->tls_hostname->u.s, &err); - break; - case MIGRATION_PARAMETER_MAX_BANDWIDTH: - p->has_max_bandwidth =3D true; - /* - * Can't use visit_type_size() here, because it - * defaults to Bytes rather than Mebibytes. - */ - ret =3D qemu_strtosz_MiB(valuestr, NULL, &valuebw); - if (ret < 0 || valuebw > INT64_MAX - || (size_t)valuebw !=3D valuebw) { - error_setg(&err, "Invalid size %s", valuestr); - break; - } - p->max_bandwidth =3D valuebw; - break; - case MIGRATION_PARAMETER_DOWNTIME_LIMIT: - p->has_downtime_limit =3D true; - visit_type_int(v, param, &p->downtime_limit, &err); - break; - case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY: - p->has_x_checkpoint_delay =3D true; - visit_type_int(v, param, &p->x_checkpoint_delay, &err); - break; - case MIGRATION_PARAMETER_BLOCK_INCREMENTAL: - p->has_block_incremental =3D true; - visit_type_bool(v, param, &p->block_incremental, &err); - break; - } + int val, ret; =20 - if (err) { - goto cleanup; - } - - qmp_migrate_set_parameters(p, &err); + val =3D qapi_enum_parse(MigrationParameter_lookup, param, + MIGRATION_PARAMETER__MAX, -1, &err); + if (val < 0) { + goto cleanup; + } + + switch (val) { + case MIGRATION_PARAMETER_COMPRESS_LEVEL: + p->has_compress_level =3D true; + visit_type_int(v, param, &p->compress_level, &err); + break; + case MIGRATION_PARAMETER_COMPRESS_THREADS: + p->has_compress_threads =3D true; + visit_type_int(v, param, &p->compress_threads, &err); + break; + case MIGRATION_PARAMETER_DECOMPRESS_THREADS: + p->has_decompress_threads =3D true; + visit_type_int(v, param, &p->decompress_threads, &err); + break; + case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL: + p->has_cpu_throttle_initial =3D true; + visit_type_int(v, param, &p->cpu_throttle_initial, &err); + break; + case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT: + p->has_cpu_throttle_increment =3D true; + visit_type_int(v, param, &p->cpu_throttle_increment, &err); + break; + case MIGRATION_PARAMETER_TLS_CREDS: + p->has_tls_creds =3D true; + p->tls_creds =3D g_new0(StrOrNull, 1); + p->tls_creds->type =3D QTYPE_QSTRING; + visit_type_str(v, param, &p->tls_creds->u.s, &err); + break; + case MIGRATION_PARAMETER_TLS_HOSTNAME: + p->has_tls_hostname =3D true; + p->tls_hostname =3D g_new0(StrOrNull, 1); + p->tls_hostname->type =3D QTYPE_QSTRING; + visit_type_str(v, param, &p->tls_hostname->u.s, &err); + break; + case MIGRATION_PARAMETER_MAX_BANDWIDTH: + p->has_max_bandwidth =3D true; + /* + * Can't use visit_type_size() here, because it + * defaults to Bytes rather than Mebibytes. + */ + ret =3D qemu_strtosz_MiB(valuestr, NULL, &valuebw); + if (ret < 0 || valuebw > INT64_MAX + || (size_t)valuebw !=3D valuebw) { + error_setg(&err, "Invalid size %s", valuestr); break; } + p->max_bandwidth =3D valuebw; + break; + case MIGRATION_PARAMETER_DOWNTIME_LIMIT: + p->has_downtime_limit =3D true; + visit_type_int(v, param, &p->downtime_limit, &err); + break; + case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY: + p->has_x_checkpoint_delay =3D true; + visit_type_int(v, param, &p->x_checkpoint_delay, &err); + break; + case MIGRATION_PARAMETER_BLOCK_INCREMENTAL: + p->has_block_incremental =3D true; + visit_type_bool(v, param, &p->block_incremental, &err); + break; } =20 - if (i =3D=3D MIGRATION_PARAMETER__MAX) { - error_setg(&err, QERR_INVALID_PARAMETER, param); + if (err) { + goto cleanup; } =20 + qmp_migrate_set_parameters(p, &err); + cleanup: qapi_free_MigrateSetParameters(p); visit_free(v); --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 1503409270400128.00644893159006; Tue, 22 Aug 2017 06:41:10 -0700 (PDT) Received: from localhost ([::1]:46966 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9Qb-0005Zv-5K for importer@patchew.org; Tue, 22 Aug 2017 09:41:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54664) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9HW-0006Oi-Ut for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:31:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9HR-0005mJ-2x for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:31:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55034) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9HJ-0005cS-Ro; Tue, 22 Aug 2017 09:31:34 -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 3251740430A; Tue, 22 Aug 2017 13:23:51 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id BA6BF61786; Tue, 22 Aug 2017 13:23:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3251740430A 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: Tue, 22 Aug 2017 15:22:11 +0200 Message-Id: <20170822132255.23945-11-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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.38]); Tue, 22 Aug 2017 13:23:51 +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/54] block: use qemu_enum_parse() in blkdebug_debug_breakpoint 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: Kevin Wolf , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "open list:blkdebug" , Max Reitz 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" This slightly change the error report message from "Invalid event name" to "Invalid parameter". Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Markus Armbruster --- block/blkdebug.c | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/block/blkdebug.c b/block/blkdebug.c index c19ab28f07..50edda2a31 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -32,6 +32,7 @@ #include "qapi/qmp/qbool.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qstring.h" +#include "qapi/util.h" #include "sysemu/qtest.h" =20 typedef struct BDRVBlkdebugState { @@ -149,20 +150,6 @@ static QemuOptsList *config_groups[] =3D { NULL }; =20 -static int get_event_by_name(const char *name, BlkdebugEvent *event) -{ - int i; - - for (i =3D 0; i < BLKDBG__MAX; i++) { - if (!strcmp(BlkdebugEvent_lookup[i], name)) { - *event =3D i; - return 0; - } - } - - return -1; -} - struct add_rule_data { BDRVBlkdebugState *s; int action; @@ -173,7 +160,7 @@ static int add_rule(void *opaque, QemuOpts *opts, Error= **errp) struct add_rule_data *d =3D opaque; BDRVBlkdebugState *s =3D d->s; const char* event_name; - BlkdebugEvent event; + int event; struct BlkdebugRule *rule; int64_t sector; =20 @@ -182,8 +169,9 @@ static int add_rule(void *opaque, QemuOpts *opts, Error= **errp) if (!event_name) { error_setg(errp, "Missing event name for rule"); return -1; - } else if (get_event_by_name(event_name, &event) < 0) { - error_setg(errp, "Invalid event name \"%s\"", event_name); + } + event =3D qapi_enum_parse(BlkdebugEvent_lookup, event_name, BLKDBG__MA= X, -1, errp); + if (event < 0) { return -1; } =20 @@ -743,13 +731,13 @@ static int blkdebug_debug_breakpoint(BlockDriverState= *bs, const char *event, { BDRVBlkdebugState *s =3D bs->opaque; struct BlkdebugRule *rule; - BlkdebugEvent blkdebug_event; + int blkdebug_event; =20 - if (get_event_by_name(event, &blkdebug_event) < 0) { + blkdebug_event =3D qapi_enum_parse(BlkdebugEvent_lookup, event, BLKDBG= __MAX, -1, NULL); + if (blkdebug_event < 0) { return -ENOENT; } =20 - rule =3D g_malloc(sizeof(*rule)); *rule =3D (struct BlkdebugRule) { .event =3D blkdebug_event, --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 1503410166336906.258060390365; Tue, 22 Aug 2017 06:56:06 -0700 (PDT) Received: from localhost ([::1]:47193 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9ez-00020z-8Q for importer@patchew.org; Tue, 22 Aug 2017 09:56:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54906) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9I6-0006yH-84 for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:32:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9I5-0006JV-C7 for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:32:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60281) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9Hy-0006F0-7s; Tue, 22 Aug 2017 09:32:14 -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 8D4B520A89; Tue, 22 Aug 2017 13:23:53 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7A54E6CDD0; Tue, 22 Aug 2017 13:23:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8D4B520A89 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: Tue, 22 Aug 2017 15:22:12 +0200 Message-Id: <20170822132255.23945-12-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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.30]); Tue, 22 Aug 2017 13:23:53 +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/54] quorum: use qapi_enum_parse() in quorum_open 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: Kevin Wolf , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Alberto Garcia , "open list:Quorum" , Max Reitz 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: Alberto Garcia --- block/quorum.c | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/block/quorum.c b/block/quorum.c index d04da4f430..e4271caa7a 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -22,6 +22,7 @@ #include "qapi/qmp/qjson.h" #include "qapi/qmp/qlist.h" #include "qapi/qmp/qstring.h" +#include "qapi/util.h" #include "qapi-event.h" #include "crypto/hash.h" =20 @@ -867,24 +868,6 @@ static QemuOptsList quorum_runtime_opts =3D { }, }; =20 -static int parse_read_pattern(const char *opt) -{ - int i; - - if (!opt) { - /* Set quorum as default */ - return QUORUM_READ_PATTERN_QUORUM; - } - - for (i =3D 0; i < QUORUM_READ_PATTERN__MAX; i++) { - if (!strcmp(opt, QuorumReadPattern_lookup[i])) { - return i; - } - } - - return -EINVAL; -} - static int quorum_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) { @@ -925,7 +908,13 @@ static int quorum_open(BlockDriverState *bs, QDict *op= tions, int flags, goto exit; } =20 - ret =3D parse_read_pattern(qemu_opt_get(opts, QUORUM_OPT_READ_PATTERN)= ); + if (!qemu_opt_get(opts, QUORUM_OPT_READ_PATTERN)) { + ret =3D QUORUM_READ_PATTERN_QUORUM; + } else { + ret =3D qapi_enum_parse(QuorumReadPattern_lookup, + qemu_opt_get(opts, QUORUM_OPT_READ_PATTERN), + QUORUM_READ_PATTERN__MAX, -EINVAL, NULL); + } if (ret < 0) { error_setg(&local_err, "Please set read-pattern as fifo or quorum"= ); goto exit; --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 1503411266844621.0622651512531; Tue, 22 Aug 2017 07:14:26 -0700 (PDT) Received: from localhost ([::1]:47367 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9wn-000092-5L for importer@patchew.org; Tue, 22 Aug 2017 10:14:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55419) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9Jk-0008OS-KY for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:34:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9Jd-0007Dg-PY for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:34:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38468) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9JO-00072M-Ud; Tue, 22 Aug 2017 09:33:43 -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 57F607ACA4; Tue, 22 Aug 2017 13:24:07 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5827481B49; Tue, 22 Aug 2017 13:23:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 57F607ACA4 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: Tue, 22 Aug 2017 15:22:13 +0200 Message-Id: <20170822132255.23945-13-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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.26]); Tue, 22 Aug 2017 13:24:07 +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/54] qapi: change enum lookup structure 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: "open list:Sheepdog" , Stefan Hajnoczi , "Michael S. Tsirkin" , Jeff Cody , Michael Roth , Gerd Hoffmann , "Denis V. Lunev" , Josh Durgin , Alberto Garcia , zhanghailiang , "open list:Block layer core" , Juan Quintela , Markus Armbruster , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Liu Yuan , Jason Wang , Eduardo Habkost , Stefan Weil , Peter Lieven , "Dr. David Alan Gilbert" , Ronnie Sahlberg , Igor Mammedov , John Snow , Kevin Wolf , Hitoshi Mitake , Max Reitz , Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= 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" Store the length in the lookup table, i.e. change it from const char *const[] to struct { int n, const char *const s[] }. The following conditional enum entry change will create "hole" elements in the generated lookup array, that should be skipped. Signed-off-by: Marc-Andr=C3=A9 Lureau --- include/qapi/visitor.h | 2 +- scripts/qapi.py | 11 +++++-- scripts/qapi-types.py | 6 ++++ scripts/qapi-visit.py | 2 +- include/hw/qdev-core.h | 2 +- include/qapi/util.h | 6 ++-- include/qom/object.h | 4 +-- qapi/qapi-visit-core.c | 24 +++++++------- backends/hostmem.c | 4 +-- block.c | 3 +- block/backup.c | 2 +- block/blkdebug.c | 4 +-- block/file-posix.c | 17 +++++----- block/file-win32.c | 6 ++-- block/gluster.c | 12 +++---- block/iscsi.c | 2 +- block/nfs.c | 2 +- block/parallels.c | 10 ++++-- block/qcow2.c | 14 ++++---- block/qed.c | 2 +- block/quorum.c | 4 +-- block/rbd.c | 2 +- block/sheepdog.c | 2 +- blockdev.c | 7 ++-- blockjob.c | 6 ++-- chardev/char.c | 4 +-- crypto/block-luks.c | 38 +++++++++------------- crypto/block.c | 4 +-- crypto/cipher-afalg.c | 2 +- crypto/cipher-builtin.c | 8 ++--- crypto/cipher-gcrypt.c | 4 +-- crypto/cipher-nettle.c | 8 ++--- crypto/hmac-gcrypt.c | 2 +- crypto/hmac-glib.c | 2 +- crypto/hmac-nettle.c | 2 +- crypto/pbkdf-gcrypt.c | 2 +- crypto/pbkdf-nettle.c | 2 +- crypto/secret.c | 2 +- crypto/tlscreds.c | 2 +- hmp.c | 64 +++++++++++++++++----------------= ---- hw/block/fdc.c | 6 ++-- hw/char/escc.c | 2 +- hw/core/qdev-properties.c | 10 +++--- hw/input/virtio-input-hid.c | 4 +-- migration/colo-failover.c | 4 +-- migration/colo.c | 14 ++++---- migration/global_state.c | 5 ++- monitor.c | 20 ++++++------ net/filter.c | 2 +- net/net.c | 4 +-- qapi/qapi-util.c | 13 ++++---- qapi/qmp-dispatch.c | 2 +- qemu-img.c | 6 ++-- qemu-nbd.c | 3 +- qom/object.c | 16 +++++----- tests/check-qom-proplist.c | 7 +++- tests/test-qapi-util.c | 17 ++++------ tests/test-qobject-input-visitor.c | 8 ++--- tests/test-qobject-output-visitor.c | 2 +- tests/test-string-input-visitor.c | 4 +-- tests/test-string-output-visitor.c | 4 +-- tpm.c | 4 +-- ui/input-legacy.c | 6 ++-- ui/input.c | 12 +++---- ui/vnc.c | 6 ++-- vl.c | 6 ++-- 66 files changed, 241 insertions(+), 248 deletions(-) diff --git a/include/qapi/visitor.h b/include/qapi/visitor.h index 0f3b8cb459..62a51a54cb 100644 --- a/include/qapi/visitor.h +++ b/include/qapi/visitor.h @@ -469,7 +469,7 @@ bool visit_optional(Visitor *v, const char *name, bool = *present); * that visit_type_str() must have no unwelcome side effects. */ void visit_type_enum(Visitor *v, const char *name, int *obj, - const char *const strings[], Error **errp); + const QEnumLookup *lookup, Error **errp); =20 /* * Check if visitor is an input visitor. diff --git a/scripts/qapi.py b/scripts/qapi.py index a3ac799535..314d7e0365 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -1851,7 +1851,7 @@ def guardend(name): def gen_enum_lookup(name, values, prefix=3DNone): ret =3D mcgen(''' =20 -const char *const %(c_name)s_lookup[] =3D { +static const char *const %(c_name)s_array[] =3D { ''', c_name=3Dc_name(name)) for value in values: @@ -1865,8 +1865,13 @@ const char *const %(c_name)s_lookup[] =3D { ret +=3D mcgen(''' [%(max_index)s] =3D NULL, }; + +const QEnumLookup %(c_name)s_lookup =3D { + .array =3D %(c_name)s_array, + .size =3D %(max_index)s +}; ''', - max_index=3Dmax_index) + max_index=3Dmax_index, c_name=3Dc_name(name)) return ret =20 =20 @@ -1896,7 +1901,7 @@ typedef enum %(c_name)s { =20 ret +=3D mcgen(''' =20 -extern const char *const %(c_name)s_lookup[]; +extern const QEnumLookup %(c_name)s_lookup; ''', c_name=3Dc_name(name)) return ret diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index b45e7b5634..dc05268917 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -179,6 +179,12 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): self.defn =3D '' self._fwdecl =3D '' self._btin =3D guardstart('QAPI_TYPES_BUILTIN') + self._btin +=3D ''' +typedef struct QEnumLookup { + const char *const *array; + int size; +} QEnumLookup; +''' =20 def visit_end(self): self.decl =3D self._fwdecl + self.decl diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py index bd0b742236..7e1cfc13f0 100644 --- a/scripts/qapi-visit.py +++ b/scripts/qapi-visit.py @@ -153,7 +153,7 @@ def gen_visit_enum(name): void visit_type_%(c_name)s(Visitor *v, const char *name, %(c_name)s *obj, = Error **errp) { int value =3D *obj; - visit_type_enum(v, name, &value, %(c_name)s_lookup, errp); + visit_type_enum(v, name, &value, &%(c_name)s_lookup, errp); *obj =3D value; } ''', diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index ae317286a4..089146197f 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -249,7 +249,7 @@ struct Property { struct PropertyInfo { const char *name; const char *description; - const char * const *enum_table; + const QEnumLookup *enum_table; int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len); void (*set_default_value)(Object *obj, const Property *prop); void (*create)(Object *obj, Property *prop, Error **errp); diff --git a/include/qapi/util.h b/include/qapi/util.h index 60733b6a80..613f82bdcd 100644 --- a/include/qapi/util.h +++ b/include/qapi/util.h @@ -11,10 +11,10 @@ #ifndef QAPI_UTIL_H #define QAPI_UTIL_H =20 -const char *qapi_enum_lookup(const char * const lookup[], int val); +const char *qapi_enum_lookup(const QEnumLookup *lookup, int val); =20 -int qapi_enum_parse(const char * const lookup[], const char *buf, - int max, int def, Error **errp); +int qapi_enum_parse(const QEnumLookup *lookup, const char *buf, + int def, Error **errp); =20 int parse_qapi_name(const char *name, bool complete); =20 diff --git a/include/qom/object.h b/include/qom/object.h index 1b828994fa..f3e5cff37a 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -1415,14 +1415,14 @@ void object_class_property_add_bool(ObjectClass *kl= ass, const char *name, */ void object_property_add_enum(Object *obj, const char *name, const char *typename, - const char * const *strings, + const QEnumLookup *lookup, int (*get)(Object *, Error **), void (*set)(Object *, int, Error **), Error **errp); =20 void object_class_property_add_enum(ObjectClass *klass, const char *name, const char *typename, - const char * const *strings, + const QEnumLookup *lookup, int (*get)(Object *, Error **), void (*set)(Object *, int, Error **), Error **errp); diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c index ed6d2af462..8876ecf0cd 100644 --- a/qapi/qapi-visit-core.c +++ b/qapi/qapi-visit-core.c @@ -333,24 +333,22 @@ void visit_type_null(Visitor *v, const char *name, QN= ull **obj, } =20 static void output_type_enum(Visitor *v, const char *name, int *obj, - const char *const strings[], Error **errp) + const QEnumLookup *lookup, Error **errp) { - int i =3D 0; int value =3D *obj; char *enum_str; =20 - while (strings[i++] !=3D NULL); - if (value < 0 || value >=3D i - 1) { + if (value < 0 || value > lookup->size || !lookup->array[value]) { error_setg(errp, QERR_INVALID_PARAMETER, name ? name : "null"); return; } =20 - enum_str =3D (char *)strings[value]; + enum_str =3D (char *)lookup->array[value]; visit_type_str(v, name, &enum_str, errp); } =20 static void input_type_enum(Visitor *v, const char *name, int *obj, - const char *const strings[], Error **errp) + const QEnumLookup *lookup, Error **errp) { Error *local_err =3D NULL; int64_t value =3D 0; @@ -362,14 +360,14 @@ static void input_type_enum(Visitor *v, const char *n= ame, int *obj, return; } =20 - while (strings[value] !=3D NULL) { - if (strcmp(strings[value], enum_str) =3D=3D 0) { + while (value < lookup->size) { + if (!g_strcmp0(lookup->array[value], enum_str)) { break; } value++; } =20 - if (strings[value] =3D=3D NULL) { + if (value =3D=3D lookup->size) { error_setg(errp, QERR_INVALID_PARAMETER, enum_str); g_free(enum_str); return; @@ -380,16 +378,16 @@ static void input_type_enum(Visitor *v, const char *n= ame, int *obj, } =20 void visit_type_enum(Visitor *v, const char *name, int *obj, - const char *const strings[], Error **errp) + const QEnumLookup *lookup, Error **errp) { - assert(obj && strings); + assert(obj && lookup); trace_visit_type_enum(v, name, obj); switch (v->type) { case VISITOR_INPUT: - input_type_enum(v, name, obj, strings, errp); + input_type_enum(v, name, obj, lookup, errp); break; case VISITOR_OUTPUT: - output_type_enum(v, name, obj, strings, errp); + output_type_enum(v, name, obj, lookup, errp); break; case VISITOR_CLONE: /* nothing further to do, scalar value was already copied by diff --git a/backends/hostmem.c b/backends/hostmem.c index c4f795475c..ce430f1d14 100644 --- a/backends/hostmem.c +++ b/backends/hostmem.c @@ -305,7 +305,7 @@ host_memory_backend_memory_complete(UserCreatable *uc, = Error **errp) return; } else if (maxnode =3D=3D 0 && backend->policy !=3D MPOL_DEFAULT) { error_setg(errp, "host-nodes must be set for policy %s", - qapi_enum_lookup(HostMemPolicy_lookup, backend->policy)); + qapi_enum_lookup(&HostMemPolicy_lookup, backend->policy)); return; } =20 @@ -396,7 +396,7 @@ host_memory_backend_class_init(ObjectClass *oc, void *d= ata) host_memory_backend_set_host_nodes, NULL, NULL, &error_abort); object_class_property_add_enum(oc, "policy", "HostMemPolicy", - HostMemPolicy_lookup, + &HostMemPolicy_lookup, host_memory_backend_get_policy, host_memory_backend_set_policy, &error_abort); object_class_property_add_str(oc, "id", get_id, set_id, &error_abort); diff --git a/block.c b/block.c index 3615a6809e..ffb1f8db13 100644 --- a/block.c +++ b/block.c @@ -1333,9 +1333,8 @@ static int bdrv_open_common(BlockDriverState *bs, Blo= ckBackend *file, detect_zeroes =3D qemu_opt_get(opts, "detect-zeroes"); if (detect_zeroes) { BlockdevDetectZeroesOptions value =3D - qapi_enum_parse(BlockdevDetectZeroesOptions_lookup, + qapi_enum_parse(&BlockdevDetectZeroesOptions_lookup, detect_zeroes, - BLOCKDEV_DETECT_ZEROES_OPTIONS__MAX, BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF, &local_err); if (local_err) { diff --git a/block/backup.c b/block/backup.c index a700cc0315..8d4f3bcc13 100644 --- a/block/backup.c +++ b/block/backup.c @@ -597,7 +597,7 @@ BlockJob *backup_job_create(const char *job_id, BlockDr= iverState *bs, error_setg(errp, "a sync_bitmap was provided to backup_run, " "but received an incompatible sync_mode (%s)", - qapi_enum_lookup(MirrorSyncMode_lookup, sync_mode)); + qapi_enum_lookup(&MirrorSyncMode_lookup, sync_mode)); return NULL; } =20 diff --git a/block/blkdebug.c b/block/blkdebug.c index 50edda2a31..94068156dc 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -170,7 +170,7 @@ static int add_rule(void *opaque, QemuOpts *opts, Error= **errp) error_setg(errp, "Missing event name for rule"); return -1; } - event =3D qapi_enum_parse(BlkdebugEvent_lookup, event_name, BLKDBG__MA= X, -1, errp); + event =3D qapi_enum_parse(&BlkdebugEvent_lookup, event_name, -1, errp); if (event < 0) { return -1; } @@ -733,7 +733,7 @@ static int blkdebug_debug_breakpoint(BlockDriverState *= bs, const char *event, struct BlkdebugRule *rule; int blkdebug_event; =20 - blkdebug_event =3D qapi_enum_parse(BlkdebugEvent_lookup, event, BLKDBG= __MAX, -1, NULL); + blkdebug_event =3D qapi_enum_parse(&BlkdebugEvent_lookup, event, -1, N= ULL); if (blkdebug_event < 0) { return -ENOENT; } diff --git a/block/file-posix.c b/block/file-posix.c index 48200aef0b..578f9aae39 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -438,8 +438,8 @@ static int raw_open_common(BlockDriverState *bs, QDict = *options, aio_default =3D (bdrv_flags & BDRV_O_NATIVE_AIO) ? BLOCKDEV_AIO_OPTIONS_NATIVE : BLOCKDEV_AIO_OPTIONS_THREADS; - aio =3D qapi_enum_parse(BlockdevAioOptions_lookup, qemu_opt_get(opts, = "aio"), - BLOCKDEV_AIO_OPTIONS__MAX, aio_default, &local_e= rr); + aio =3D qapi_enum_parse(&BlockdevAioOptions_lookup, qemu_opt_get(opts,= "aio"), + aio_default, &local_err); if (local_err) { error_propagate(errp, local_err); ret =3D -EINVAL; @@ -447,8 +447,8 @@ static int raw_open_common(BlockDriverState *bs, QDict = *options, } s->use_linux_aio =3D (aio =3D=3D BLOCKDEV_AIO_OPTIONS_NATIVE); =20 - locking =3D qapi_enum_parse(OnOffAuto_lookup, qemu_opt_get(opts, "lock= ing"), - ON_OFF_AUTO__MAX, ON_OFF_AUTO_AUTO, &local_e= rr); + locking =3D qapi_enum_parse(&OnOffAuto_lookup, qemu_opt_get(opts, "loc= king"), + ON_OFF_AUTO_AUTO, &local_err); if (local_err) { error_propagate(errp, local_err); ret =3D -EINVAL; @@ -1725,7 +1725,7 @@ static int raw_regular_truncate(int fd, int64_t offse= t, PreallocMode prealloc, default: result =3D -ENOTSUP; error_setg(errp, "Unsupported preallocation mode: %s", - qapi_enum_lookup(PreallocMode_lookup, prealloc)); + qapi_enum_lookup(&PreallocMode_lookup, prealloc)); return result; } =20 @@ -1760,7 +1760,7 @@ static int raw_truncate(BlockDriverState *bs, int64_t= offset, =20 if (prealloc !=3D PREALLOC_MODE_OFF) { error_setg(errp, "Preallocation mode '%s' unsupported for this " - "non-regular file", qapi_enum_lookup(PreallocMode_looku= p, + "non-regular file", qapi_enum_lookup(&PreallocMode_look= up, prealloc)); return -ENOTSUP; } @@ -1975,9 +1975,8 @@ static int raw_create(const char *filename, QemuOpts = *opts, Error **errp) BDRV_SECTOR_SIZE); nocow =3D qemu_opt_get_bool(opts, BLOCK_OPT_NOCOW, false); buf =3D qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC); - prealloc =3D qapi_enum_parse(PreallocMode_lookup, buf, - PREALLOC_MODE__MAX, PREALLOC_MODE_OFF, - &local_err); + prealloc =3D qapi_enum_parse(&PreallocMode_lookup, buf, + PREALLOC_MODE_OFF, &local_err); g_free(buf); if (local_err) { error_propagate(errp, local_err); diff --git a/block/file-win32.c b/block/file-win32.c index 2f3975f040..be4146e030 100644 --- a/block/file-win32.c +++ b/block/file-win32.c @@ -303,8 +303,8 @@ static bool get_aio_option(QemuOpts *opts, int flags, E= rror **errp) =20 aio_default =3D (flags & BDRV_O_NATIVE_AIO) ? BLOCKDEV_AIO_OPTIONS_NAT= IVE : BLOCKDEV_AIO_OPTIONS_THREA= DS; - aio =3D qapi_enum_parse(BlockdevAioOptions_lookup, qemu_opt_get(opts, = "aio"), - BLOCKDEV_AIO_OPTIONS__MAX, aio_default, errp); + aio =3D qapi_enum_parse(&BlockdevAioOptions_lookup, qemu_opt_get(opts,= "aio"), + aio_default, errp); =20 switch (aio) { case BLOCKDEV_AIO_OPTIONS_NATIVE: @@ -470,7 +470,7 @@ static int raw_truncate(BlockDriverState *bs, int64_t o= ffset, =20 if (prealloc !=3D PREALLOC_MODE_OFF) { error_setg(errp, "Unsupported preallocation mode '%s'", - qapi_enum_lookup(reallocMode_lookup, prealloc)); + qapi_enum_lookup(&reallocMode_lookup, prealloc)); return -ENOTSUP; } =20 diff --git a/block/gluster.c b/block/gluster.c index 934f459014..bc8eff5dd3 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -544,8 +544,7 @@ static int qemu_gluster_parse_json(BlockdevOptionsGlust= er *gconf, if (!strcmp(ptr, "tcp")) { ptr =3D "inet"; /* accept legacy "tcp" */ } - type =3D qapi_enum_parse(SocketAddressType_lookup, ptr, - SOCKET_ADDRESS_TYPE__MAX, -1, NULL); + type =3D qapi_enum_parse(&SocketAddressType_lookup, ptr, -1, NULL); if (type !=3D SOCKET_ADDRESS_TYPE_INET && type !=3D SOCKET_ADDRESS_TYPE_UNIX) { error_setg(&local_err, @@ -1002,9 +1001,8 @@ static int qemu_gluster_create(const char *filename, BDRV_SECTOR_SIZE); =20 tmp =3D qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC); - prealloc =3D qapi_enum_parse(PreallocMode_lookup, tmp, - PREALLOC_MODE__MAX, PREALLOC_MODE_OFF, - &local_err); + prealloc =3D qapi_enum_parse(&PreallocMode_lookup, tmp, + PREALLOC_MODE_OFF, &local_err); g_free(tmp); if (local_err) { error_propagate(errp, local_err); @@ -1050,7 +1048,7 @@ static int qemu_gluster_create(const char *filename, default: ret =3D -EINVAL; error_setg(errp, "Unsupported preallocation mode: %s", - qapi_enum_lookup(PreallocMode_lookup, prealloc)); + qapi_enum_lookup(&PreallocMode_lookup, prealloc)); break; } =20 @@ -1102,7 +1100,7 @@ static int qemu_gluster_truncate(BlockDriverState *bs= , int64_t offset, =20 if (prealloc !=3D PREALLOC_MODE_OFF) { error_setg(errp, "Unsupported preallocation mode '%s'", - qapi_enum_lookup(PreallocMode_lookup, prealloc)); + qapi_enum_lookup(&PreallocMode_lookup, prealloc)); return -ENOTSUP; } =20 diff --git a/block/iscsi.c b/block/iscsi.c index 5c1870340b..c6bb0049bf 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -2088,7 +2088,7 @@ static int iscsi_truncate(BlockDriverState *bs, int64= _t offset, =20 if (prealloc !=3D PREALLOC_MODE_OFF) { error_setg(errp, "Unsupported preallocation mode '%s'", - qapi_enum_lookup(PreallocMode_lookup, prealloc)); + qapi_enum_lookup(&PreallocMode_lookup, prealloc)); return -ENOTSUP; } =20 diff --git a/block/nfs.c b/block/nfs.c index 953728ae31..f0ac050169 100644 --- a/block/nfs.c +++ b/block/nfs.c @@ -773,7 +773,7 @@ static int nfs_file_truncate(BlockDriverState *bs, int6= 4_t offset, =20 if (prealloc !=3D PREALLOC_MODE_OFF) { error_setg(errp, "Unsupported preallocation mode '%s'", - qapi_enum_lookup(PreallocMode_lookup, prealloc)); + qapi_enum_lookup(&PreallocMode_lookup, prealloc)); return -ENOTSUP; } =20 diff --git a/block/parallels.c b/block/parallels.c index e1e06d23cc..f870bbac3e 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -69,12 +69,16 @@ typedef enum ParallelsPreallocMode { PRL_PREALLOC_MODE__MAX =3D 2, } ParallelsPreallocMode; =20 -static const char *prealloc_mode_lookup[] =3D { +static const char *prealloc_mode_array[] =3D { "falloc", "truncate", NULL, }; =20 +static QEnumLookup prealloc_mode_lookup =3D { + .array =3D prealloc_mode_array, + .size =3D G_N_ELEMENTS(prealloc_mode_array), +}; =20 typedef struct BDRVParallelsState { /** Locking is conservative, the lock protects @@ -696,8 +700,8 @@ static int parallels_open(BlockDriverState *bs, QDict *= options, int flags, qemu_opt_get_size_del(opts, PARALLELS_OPT_PREALLOC_SIZE, 0); s->prealloc_size =3D MAX(s->tracks, s->prealloc_size >> BDRV_SECTOR_BI= TS); buf =3D qemu_opt_get_del(opts, PARALLELS_OPT_PREALLOC_MODE); - s->prealloc_mode =3D qapi_enum_parse(prealloc_mode_lookup, buf, - PRL_PREALLOC_MODE__MAX, PRL_PREALLOC_MODE_FALLOCATE, &local_er= r); + s->prealloc_mode =3D qapi_enum_parse(&prealloc_mode_lookup, buf, + PRL_PREALLOC_MODE_FALLOCATE, &local= _err); g_free(buf); if (local_err !=3D NULL) { goto fail_options; diff --git a/block/qcow2.c b/block/qcow2.c index 45b0579caa..c72fa2b476 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2733,7 +2733,7 @@ static int qcow2_create2(const char *filename, int64_= t total_size, qcow2_calc_prealloc_size(total_size, cluster_size, refcount_or= der); qemu_opt_set_number(opts, BLOCK_OPT_SIZE, prealloc_size, &error_ab= ort); qemu_opt_set(opts, BLOCK_OPT_PREALLOC, - qapi_enum_lookup(PreallocMode_lookup, prealloc), + qapi_enum_lookup(&PreallocMode_lookup, prealloc), &error_abort); } =20 @@ -2933,9 +2933,8 @@ static int qcow2_create(const char *filename, QemuOpt= s *opts, Error **errp) goto finish; } buf =3D qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC); - prealloc =3D qapi_enum_parse(PreallocMode_lookup, buf, - PREALLOC_MODE__MAX, PREALLOC_MODE_OFF, - &local_err); + prealloc =3D qapi_enum_parse(&PreallocMode_lookup, buf, + PREALLOC_MODE_OFF, &local_err); if (local_err) { error_propagate(errp, local_err); ret =3D -EINVAL; @@ -3099,7 +3098,7 @@ static int qcow2_truncate(BlockDriverState *bs, int64= _t offset, prealloc !=3D PREALLOC_MODE_FALLOC && prealloc !=3D PREALLOC_MODE_= FULL) { error_setg(errp, "Unsupported preallocation mode '%s'", - qapi_enum_lookup(PreallocMode_lookup, prealloc)); + qapi_enum_lookup(&PreallocMode_lookup, prealloc)); return -ENOTSUP; } =20 @@ -3624,9 +3623,8 @@ static BlockMeasureInfo *qcow2_measure(QemuOpts *opts= , BlockDriverState *in_bs, } =20 optstr =3D qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC); - prealloc =3D qapi_enum_parse(PreallocMode_lookup, optstr, - PREALLOC_MODE__MAX, PREALLOC_MODE_OFF, - &local_err); + prealloc =3D qapi_enum_parse(&PreallocMode_lookup, optstr, + PREALLOC_MODE_OFF, &local_err); g_free(optstr); if (local_err) { goto err; diff --git a/block/qed.c b/block/qed.c index 756fcb85a7..aec2a559ce 100644 --- a/block/qed.c +++ b/block/qed.c @@ -1400,7 +1400,7 @@ static int bdrv_qed_truncate(BlockDriverState *bs, in= t64_t offset, =20 if (prealloc !=3D PREALLOC_MODE_OFF) { error_setg(errp, "Unsupported preallocation mode '%s'", - qapi_enum_lookup(PreallocMode_lookup, prealloc)); + qapi_enum_lookup(&PreallocMode_lookup, prealloc)); return -ENOTSUP; } =20 diff --git a/block/quorum.c b/block/quorum.c index e4271caa7a..44acd2702c 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -911,9 +911,9 @@ static int quorum_open(BlockDriverState *bs, QDict *opt= ions, int flags, if (!qemu_opt_get(opts, QUORUM_OPT_READ_PATTERN)) { ret =3D QUORUM_READ_PATTERN_QUORUM; } else { - ret =3D qapi_enum_parse(QuorumReadPattern_lookup, + ret =3D qapi_enum_parse(&QuorumReadPattern_lookup, qemu_opt_get(opts, QUORUM_OPT_READ_PATTERN), - QUORUM_READ_PATTERN__MAX, -EINVAL, NULL); + -EINVAL, NULL); } if (ret < 0) { error_setg(&local_err, "Please set read-pattern as fifo or quorum"= ); diff --git a/block/rbd.c b/block/rbd.c index 09f8d18d1b..ff71259f05 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -945,7 +945,7 @@ static int qemu_rbd_truncate(BlockDriverState *bs, int6= 4_t offset, =20 if (prealloc !=3D PREALLOC_MODE_OFF) { error_setg(errp, "Unsupported preallocation mode '%s'", - qapi_enum_lookup(PreallocMode_lookup, prealloc)); + qapi_enum_lookup(&PreallocMode_lookup, prealloc)); return -ENOTSUP; } =20 diff --git a/block/sheepdog.c b/block/sheepdog.c index 69d49fb720..9eac7c0ec7 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -2177,7 +2177,7 @@ static int sd_truncate(BlockDriverState *bs, int64_t = offset, =20 if (prealloc !=3D PREALLOC_MODE_OFF) { error_setg(errp, "Unsupported preallocation mode '%s'", - qapi_enum_lookup(PreallocMode_lookup, prealloc)); + qapi_enum_lookup(&PreallocMode_lookup, prealloc)); return -ENOTSUP; } =20 diff --git a/blockdev.c b/blockdev.c index 6a067e81bf..7834b8830e 100644 --- a/blockdev.c +++ b/blockdev.c @@ -438,9 +438,8 @@ static void extract_common_blockdev_options(QemuOpts *o= pts, int *bdrv_flags, =20 if (detect_zeroes) { *detect_zeroes =3D - qapi_enum_parse(BlockdevDetectZeroesOptions_lookup, + qapi_enum_parse(&BlockdevDetectZeroesOptions_lookup, qemu_opt_get(opts, "detect-zeroes"), - BLOCKDEV_DETECT_ZEROES_OPTIONS__MAX, BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF, &local_error); if (local_error) { @@ -1468,9 +1467,9 @@ static int action_check_completion_mode(BlkActionStat= e *s, Error **errp) error_setg(errp, "Action '%s' does not support Transaction property " "completion-mode =3D %s", - qapi_enum_lookup(TransactionActionKind_lookup, + qapi_enum_lookup(&TransactionActionKind_lookup, s->action->type), - qapi_enum_lookup(ActionCompletionMode_lookup, + qapi_enum_lookup(&ActionCompletionMode_lookup, s->txn_props->completion_mode)); return -1; } diff --git a/blockjob.c b/blockjob.c index fca71123e0..3c815b89e4 100644 --- a/blockjob.c +++ b/blockjob.c @@ -209,7 +209,7 @@ static char *child_job_get_parent_desc(BdrvChild *c) { BlockJob *job =3D c->opaque; return g_strdup_printf("%s job '%s'", - qapi_enum_lookup(BlockJobType_lookup, + qapi_enum_lookup(&BlockJobType_lookup, job->driver->job_type), job->id); } @@ -555,7 +555,7 @@ BlockJobInfo *block_job_query(BlockJob *job, Error **er= rp) return NULL; } info =3D g_new0(BlockJobInfo, 1); - info->type =3D g_strdup(qapi_enum_lookup(BlockJobType_lookup, + info->type =3D g_strdup(qapi_enum_lookup(&BlockJobType_lookup, job->driver->job_type)); info->device =3D g_strdup(job->id); info->len =3D job->len; @@ -669,7 +669,7 @@ void *block_job_create(const char *job_id, const BlockJ= obDriver *driver, job->refcnt =3D 1; =20 error_setg(&job->blocker, "block device is in use by block job: %s", - qapi_enum_lookup(BlockJobType_lookup, driver->job_type)); + qapi_enum_lookup(&BlockJobType_lookup, driver->job_type)); block_job_add_bdrv(job, "main node", bs, 0, BLK_PERM_ALL, &error_abort= ); bs->job =3D job; =20 diff --git a/chardev/char.c b/chardev/char.c index 4408d12a08..ba2d110ae5 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -932,7 +932,7 @@ ChardevReturn *qmp_chardev_add(const char *id, ChardevB= ackend *backend, ChardevReturn *ret; Chardev *chr; =20 - cc =3D char_get_class(qapi_enum_lookup(ChardevBackendKind_lookup, + cc =3D char_get_class(qapi_enum_lookup(&ChardevBackendKind_lookup, backend->type), errp); if (!cc) { return NULL; @@ -991,7 +991,7 @@ ChardevReturn *qmp_chardev_change(const char *id, Chard= evBackend *backend, return NULL; } =20 - cc =3D char_get_class(qapi_enum_lookup(ChardevBackendKind_lookup, + cc =3D char_get_class(qapi_enum_lookup(&ChardevBackendKind_lookup, backend->type), errp); if (!cc) { return NULL; diff --git a/crypto/block-luks.c b/crypto/block-luks.c index b78a6345f3..a3c96d768b 100644 --- a/crypto/block-luks.c +++ b/crypto/block-luks.c @@ -258,47 +258,39 @@ qcrypto_block_luks_cipher_alg_lookup(QCryptoCipherAlg= orithm alg, } =20 error_setg(errp, "Algorithm '%s' not supported", - qapi_enum_lookup(QCryptoCipherAlgorithm_lookup, alg)); + qapi_enum_lookup(&QCryptoCipherAlgorithm_lookup, alg)); return NULL; } =20 -/* XXX replace with qapi_enum_parse() in future, when we can +/* XXX replace with qapi_enum_parse(&) in future, when we can * make that function emit a more friendly error message */ static int qcrypto_block_luks_name_lookup(const char *name, - const char *const *map, - size_t maplen, + const QEnumLookup *lookup, const char *type, Error **errp) { - size_t i; - for (i =3D 0; i < maplen; i++) { - if (g_str_equal(map[i], name)) { - return i; - } + int i =3D qapi_enum_parse(lookup, name, -1, NULL); + if (i < 0) { + error_setg(errp, "%s %s not supported", type, name); } - - error_setg(errp, "%s %s not supported", type, name); - return 0; + return i; } =20 #define qcrypto_block_luks_cipher_mode_lookup(name, errp) \ qcrypto_block_luks_name_lookup(name, \ - QCryptoCipherMode_lookup, \ - QCRYPTO_CIPHER_MODE__MAX, \ + &QCryptoCipherMode_lookup, \ "Cipher mode", \ errp) =20 #define qcrypto_block_luks_hash_name_lookup(name, errp) \ qcrypto_block_luks_name_lookup(name, \ - QCryptoHashAlgorithm_lookup, \ - QCRYPTO_HASH_ALG__MAX, \ + &QCryptoHashAlgorithm_lookup, \ "Hash algorithm", \ errp) =20 #define qcrypto_block_luks_ivgen_name_lookup(name, errp) \ qcrypto_block_luks_name_lookup(name, \ - QCryptoIVGenAlgorithm_lookup, \ - QCRYPTO_IVGEN_ALG__MAX, \ + &QCryptoIVGenAlgorithm_lookup, \ "IV generator", \ errp) =20 @@ -399,7 +391,7 @@ qcrypto_block_luks_essiv_cipher(QCryptoCipherAlgorithm = cipher, break; default: error_setg(errp, "Cipher %s not supported with essiv", - qapi_enum_lookup(QCryptoCipherAlgorithm_lookup, cipher)= ); + qapi_enum_lookup(&QCryptoCipherAlgorithm_lookup, cipher= )); return 0; } } @@ -969,19 +961,19 @@ qcrypto_block_luks_create(QCryptoBlock *block, goto error; } =20 - cipher_mode =3D qapi_enum_lookup(QCryptoCipherMode_lookup, + cipher_mode =3D qapi_enum_lookup(&QCryptoCipherMode_lookup, luks_opts.cipher_mode); - ivgen_alg =3D qapi_enum_lookup(QCryptoIVGenAlgorithm_lookup, + ivgen_alg =3D qapi_enum_lookup(&QCryptoIVGenAlgorithm_lookup, luks_opts.ivgen_alg); if (luks_opts.has_ivgen_hash_alg) { - ivgen_hash_alg =3D qapi_enum_lookup(QCryptoHashAlgorithm_lookup, + ivgen_hash_alg =3D qapi_enum_lookup(&QCryptoHashAlgorithm_lookup, luks_opts.ivgen_hash_alg); cipher_mode_spec =3D g_strdup_printf("%s-%s:%s", cipher_mode, ivge= n_alg, ivgen_hash_alg); } else { cipher_mode_spec =3D g_strdup_printf("%s-%s", cipher_mode, ivgen_a= lg); } - hash_alg =3D qapi_enum_lookup(QCryptoHashAlgorithm_lookup, + hash_alg =3D qapi_enum_lookup(&QCryptoHashAlgorithm_lookup, luks_opts.hash_alg); =20 =20 diff --git a/crypto/block.c b/crypto/block.c index 2140e55426..99606fe63a 100644 --- a/crypto/block.c +++ b/crypto/block.c @@ -62,7 +62,7 @@ QCryptoBlock *qcrypto_block_open(QCryptoBlockOpenOptions = *options, if (options->format >=3D G_N_ELEMENTS(qcrypto_block_drivers) || !qcrypto_block_drivers[options->format]) { error_setg(errp, "Unsupported block driver %s", - qapi_enum_lookup(QCryptoBlockFormat_lookup, options->format)); + qapi_enum_lookup(&QCryptoBlockFormat_lookup, options->format)); g_free(block); return NULL; } @@ -93,7 +93,7 @@ QCryptoBlock *qcrypto_block_create(QCryptoBlockCreateOpti= ons *options, if (options->format >=3D G_N_ELEMENTS(qcrypto_block_drivers) || !qcrypto_block_drivers[options->format]) { error_setg(errp, "Unsupported block driver %s", - qapi_enum_lookup(QCryptoBlockFormat_lookup, options->format)); + qapi_enum_lookup(&QCryptoBlockFormat_lookup, options->format)); g_free(block); return NULL; } diff --git a/crypto/cipher-afalg.c b/crypto/cipher-afalg.c index 24d7ba8277..f15fb2a9c8 100644 --- a/crypto/cipher-afalg.c +++ b/crypto/cipher-afalg.c @@ -52,7 +52,7 @@ qcrypto_afalg_cipher_format_name(QCryptoCipherAlgorithm a= lg, return NULL; } =20 - mode_name =3D qapi_enum_lookup(QCryptoCipherMode_lookup, mode); + mode_name =3D qapi_enum_lookup(&QCryptoCipherMode_lookup, mode); name =3D g_strdup_printf("%s(%s)", mode_name, alg_name); =20 return name; diff --git a/crypto/cipher-builtin.c b/crypto/cipher-builtin.c index 76c76fb05b..e956cc5a53 100644 --- a/crypto/cipher-builtin.c +++ b/crypto/cipher-builtin.c @@ -247,7 +247,7 @@ qcrypto_cipher_init_aes(QCryptoCipherMode mode, mode !=3D QCRYPTO_CIPHER_MODE_ECB && mode !=3D QCRYPTO_CIPHER_MODE_XTS) { error_setg(errp, "Unsupported cipher mode %s", - qapi_enum_lookup(QCryptoCipherMode_lookup, mode)); + qapi_enum_lookup(&QCryptoCipherMode_lookup, mode)); return NULL; } =20 @@ -379,7 +379,7 @@ qcrypto_cipher_init_des_rfb(QCryptoCipherMode mode, =20 if (mode !=3D QCRYPTO_CIPHER_MODE_ECB) { error_setg(errp, "Unsupported cipher mode %s", - qapi_enum_lookup(QCryptoCipherMode_lookup, mode)); + qapi_enum_lookup(&QCryptoCipherMode_lookup, mode)); return NULL; } =20 @@ -440,7 +440,7 @@ static QCryptoCipherBuiltin *qcrypto_cipher_ctx_new(QCr= yptoCipherAlgorithm alg, break; default: error_setg(errp, "Unsupported cipher mode %s", - qapi_enum_lookup(QCryptoCipherMode_lookup, mode)); + qapi_enum_lookup(&QCryptoCipherMode_lookup, mode)); return NULL; } =20 @@ -460,7 +460,7 @@ static QCryptoCipherBuiltin *qcrypto_cipher_ctx_new(QCr= yptoCipherAlgorithm alg, default: error_setg(errp, "Unsupported cipher algorithm %s", - qapi_enum_lookup(QCryptoCipherAlgorithm_lookup, alg)); + qapi_enum_lookup(&QCryptoCipherAlgorithm_lookup, alg)); return NULL; } =20 diff --git a/crypto/cipher-gcrypt.c b/crypto/cipher-gcrypt.c index 09210195a4..3e46ee7502 100644 --- a/crypto/cipher-gcrypt.c +++ b/crypto/cipher-gcrypt.c @@ -105,7 +105,7 @@ static QCryptoCipherGcrypt *qcrypto_cipher_ctx_new(QCry= ptoCipherAlgorithm alg, break; default: error_setg(errp, "Unsupported cipher mode %s", - qapi_enum_lookup(QCryptoCipherMode_lookup, mode)); + qapi_enum_lookup(&QCryptoCipherMode_lookup, mode)); return NULL; } =20 @@ -160,7 +160,7 @@ static QCryptoCipherGcrypt *qcrypto_cipher_ctx_new(QCry= ptoCipherAlgorithm alg, =20 default: error_setg(errp, "Unsupported cipher algorithm %s", - qapi_enum_lookup(QCryptoCipherAlgorithm_lookup, alg)); + qapi_enum_lookup(&QCryptoCipherAlgorithm_lookup, alg)); return NULL; } =20 diff --git a/crypto/cipher-nettle.c b/crypto/cipher-nettle.c index 7c02b3e7a2..5e70c7984a 100644 --- a/crypto/cipher-nettle.c +++ b/crypto/cipher-nettle.c @@ -281,7 +281,7 @@ static QCryptoCipherNettle *qcrypto_cipher_ctx_new(QCry= ptoCipherAlgorithm alg, break; default: error_setg(errp, "Unsupported cipher mode %s", - qapi_enum_lookup(QCryptoCipherMode_lookup, mode)); + qapi_enum_lookup(&QCryptoCipherMode_lookup, mode)); return NULL; } =20 @@ -420,7 +420,7 @@ static QCryptoCipherNettle *qcrypto_cipher_ctx_new(QCry= ptoCipherAlgorithm alg, =20 default: error_setg(errp, "Unsupported cipher algorithm %s", - qapi_enum_lookup(QCryptoCipherAlgorithm_lookup, alg)); + qapi_enum_lookup(&QCryptoCipherAlgorithm_lookup, alg)); goto error; } =20 @@ -491,7 +491,7 @@ qcrypto_nettle_cipher_encrypt(QCryptoCipher *cipher, =20 default: error_setg(errp, "Unsupported cipher mode %s", - qapi_enum_lookup(QCryptoCipherMode_lookup, cipher->mode= )); + qapi_enum_lookup(&QCryptoCipherMode_lookup, cipher->mod= e)); return -1; } return 0; @@ -537,7 +537,7 @@ qcrypto_nettle_cipher_decrypt(QCryptoCipher *cipher, =20 default: error_setg(errp, "Unsupported cipher mode %s", - qapi_enum_lookup(QCryptoCipherMode_lookup, cipher->mode= )); + qapi_enum_lookup(&QCryptoCipherMode_lookup, cipher->mod= e)); return -1; } return 0; diff --git a/crypto/hmac-gcrypt.c b/crypto/hmac-gcrypt.c index 0784795269..f24d5a48c2 100644 --- a/crypto/hmac-gcrypt.c +++ b/crypto/hmac-gcrypt.c @@ -52,7 +52,7 @@ void *qcrypto_hmac_ctx_new(QCryptoHashAlgorithm alg, =20 if (!qcrypto_hmac_supports(alg)) { error_setg(errp, "Unsupported hmac algorithm %s", - qapi_enum_lookup(QCryptoHashAlgorithm_lookup, alg)); + qapi_enum_lookup(&QCryptoHashAlgorithm_lookup, alg)); return NULL; } =20 diff --git a/crypto/hmac-glib.c b/crypto/hmac-glib.c index 56b71dbf85..aac4b217c0 100644 --- a/crypto/hmac-glib.c +++ b/crypto/hmac-glib.c @@ -59,7 +59,7 @@ void *qcrypto_hmac_ctx_new(QCryptoHashAlgorithm alg, =20 if (!qcrypto_hmac_supports(alg)) { error_setg(errp, "Unsupported hmac algorithm %s", - qapi_enum_lookup(QCryptoHashAlgorithm_lookup, alg)); + qapi_enum_lookup(&QCryptoHashAlgorithm_lookup, alg)); return NULL; } =20 diff --git a/crypto/hmac-nettle.c b/crypto/hmac-nettle.c index be43511252..07cc8af9b9 100644 --- a/crypto/hmac-nettle.c +++ b/crypto/hmac-nettle.c @@ -107,7 +107,7 @@ void *qcrypto_hmac_ctx_new(QCryptoHashAlgorithm alg, =20 if (!qcrypto_hmac_supports(alg)) { error_setg(errp, "Unsupported hmac algorithm %s", - qapi_enum_lookup(QCryptoHashAlgorithm_lookup, alg)); + qapi_enum_lookup(&QCryptoHashAlgorithm_lookup, alg)); return NULL; } =20 diff --git a/crypto/pbkdf-gcrypt.c b/crypto/pbkdf-gcrypt.c index a815138c46..eff037f08f 100644 --- a/crypto/pbkdf-gcrypt.c +++ b/crypto/pbkdf-gcrypt.c @@ -69,7 +69,7 @@ int qcrypto_pbkdf2(QCryptoHashAlgorithm hash, hash_map[hash] =3D=3D GCRY_MD_NONE) { error_setg_errno(errp, ENOSYS, "PBKDF does not support hash algorithm %s", - qapi_enum_lookup(QCryptoHashAlgorithm_lookup, has= h)); + qapi_enum_lookup(&QCryptoHashAlgorithm_lookup, ha= sh)); return -1; } =20 diff --git a/crypto/pbkdf-nettle.c b/crypto/pbkdf-nettle.c index 84977fdd69..bb6454b80c 100644 --- a/crypto/pbkdf-nettle.c +++ b/crypto/pbkdf-nettle.c @@ -110,7 +110,7 @@ int qcrypto_pbkdf2(QCryptoHashAlgorithm hash, default: error_setg_errno(errp, ENOSYS, "PBKDF does not support hash algorithm %s", - qapi_enum_lookup(QCryptoHashAlgorithm_lookup, has= h)); + qapi_enum_lookup(&QCryptoHashAlgorithm_lookup, ha= sh)); return -1; } return 0; diff --git a/crypto/secret.c b/crypto/secret.c index 285ab7a63c..388abd7df5 100644 --- a/crypto/secret.c +++ b/crypto/secret.c @@ -378,7 +378,7 @@ qcrypto_secret_class_init(ObjectClass *oc, void *data) NULL); object_class_property_add_enum(oc, "format", "QCryptoSecretFormat", - QCryptoSecretFormat_lookup, + &QCryptoSecretFormat_lookup, qcrypto_secret_prop_get_format, qcrypto_secret_prop_set_format, NULL); diff --git a/crypto/tlscreds.c b/crypto/tlscreds.c index a8965531b6..3cd41035bb 100644 --- a/crypto/tlscreds.c +++ b/crypto/tlscreds.c @@ -233,7 +233,7 @@ qcrypto_tls_creds_class_init(ObjectClass *oc, void *dat= a) NULL); object_class_property_add_enum(oc, "endpoint", "QCryptoTLSCredsEndpoint", - QCryptoTLSCredsEndpoint_lookup, + &QCryptoTLSCredsEndpoint_lookup, qcrypto_tls_creds_prop_get_endpoint, qcrypto_tls_creds_prop_set_endpoint, NULL); diff --git a/hmp.c b/hmp.c index ccc58e6d88..0eb318f938 100644 --- a/hmp.c +++ b/hmp.c @@ -108,7 +108,7 @@ void hmp_info_status(Monitor *mon, const QDict *qdict) =20 if (!info->running && info->status !=3D RUN_STATE_PAUSED) { monitor_printf(mon, " (%s)", - qapi_enum_lookup(RunState_lookup, info->status)); + qapi_enum_lookup(&RunState_lookup, info->status)); } =20 monitor_printf(mon, "\n"); @@ -173,7 +173,7 @@ void hmp_info_migrate(Monitor *mon, const QDict *qdict) monitor_printf(mon, "capabilities: "); for (cap =3D caps; cap; cap =3D cap->next) { monitor_printf(mon, "%s: %s ", - qapi_enum_lookup(MigrationCapability_lookup, + qapi_enum_lookup(&MigrationCapability_lookup, cap->value->capability), cap->value->state ? "on" : "off"); } @@ -182,7 +182,7 @@ void hmp_info_migrate(Monitor *mon, const QDict *qdict) =20 if (info->has_status) { monitor_printf(mon, "Migration status: %s", - qapi_enum_lookup(MigrationStatus_lookup, info->stat= us)); + qapi_enum_lookup(&MigrationStatus_lookup, info->sta= tus)); if (info->status =3D=3D MIGRATION_STATUS_FAILED && info->has_error_desc) { monitor_printf(mon, " (%s)\n", info->error_desc); @@ -280,7 +280,7 @@ void hmp_info_migrate_capabilities(Monitor *mon, const = QDict *qdict) if (caps) { for (cap =3D caps; cap; cap =3D cap->next) { monitor_printf(mon, "%s: %s\n", - qapi_enum_lookup(MigrationCapability_lookup, + qapi_enum_lookup(&MigrationCapability_lookup, cap->value->capability), cap->value->state ? "on" : "off"); } @@ -298,57 +298,57 @@ void hmp_info_migrate_parameters(Monitor *mon, const = QDict *qdict) if (params) { assert(params->has_compress_level); monitor_printf(mon, "%s: %" PRId64 "\n", - qapi_enum_lookup(MigrationParameter_lookup, + qapi_enum_lookup(&MigrationParameter_lookup, MIGRATION_PARAMETER_COMPRESS_LEVEL), params->compress_level); assert(params->has_compress_threads); monitor_printf(mon, "%s: %" PRId64 "\n", - qapi_enum_lookup(MigrationParameter_lookup, + qapi_enum_lookup(&MigrationParameter_lookup, MIGRATION_PARAMETER_COMPRESS_THREADS), params->compress_threads); assert(params->has_decompress_threads); monitor_printf(mon, "%s: %" PRId64 "\n", - qapi_enum_lookup(MigrationParameter_lookup, + qapi_enum_lookup(&MigrationParameter_lookup, MIGRATION_PARAMETER_DECOMPRESS_THREADS), params->decompress_threads); assert(params->has_cpu_throttle_initial); monitor_printf(mon, "%s: %" PRId64 "\n", - qapi_enum_lookup(MigrationParameter_lookup, + qapi_enum_lookup(&MigrationParameter_lookup, MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL), params->cpu_throttle_initial); assert(params->has_cpu_throttle_increment); monitor_printf(mon, "%s: %" PRId64 "\n", - qapi_enum_lookup(MigrationParameter_lookup, + qapi_enum_lookup(&MigrationParameter_lookup, MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT), params->cpu_throttle_increment); assert(params->has_tls_creds); monitor_printf(mon, "%s: '%s'\n", - qapi_enum_lookup(MigrationParameter_lookup, + qapi_enum_lookup(&MigrationParameter_lookup, MIGRATION_PARAMETER_TLS_CREDS), params->tls_creds); assert(params->has_tls_hostname); monitor_printf(mon, "%s: '%s'\n", - qapi_enum_lookup(MigrationParameter_lookup, + qapi_enum_lookup(&MigrationParameter_lookup, MIGRATION_PARAMETER_TLS_HOSTNAME), params->tls_hostname); assert(params->has_max_bandwidth); monitor_printf(mon, "%s: %" PRId64 " bytes/second\n", - qapi_enum_lookup(MigrationParameter_lookup, + qapi_enum_lookup(&MigrationParameter_lookup, MIGRATION_PARAMETER_MAX_BANDWIDTH), params->max_bandwidth); assert(params->has_downtime_limit); monitor_printf(mon, "%s: %" PRId64 " milliseconds\n", - qapi_enum_lookup(MigrationParameter_lookup, + qapi_enum_lookup(&MigrationParameter_lookup, MIGRATION_PARAMETER_DOWNTIME_LIMIT), params->downtime_limit); assert(params->has_x_checkpoint_delay); monitor_printf(mon, "%s: %" PRId64 "\n", - qapi_enum_lookup(MigrationParameter_lookup, + qapi_enum_lookup(&MigrationParameter_lookup, MIGRATION_PARAMETER_X_CHECKPOINT_DELAY), params->x_checkpoint_delay); assert(params->has_block_incremental); monitor_printf(mon, "%s: %s\n", - qapi_enum_lookup(MigrationParameter_lookup, + qapi_enum_lookup(&MigrationParameter_lookup, MIGRATION_PARAMETER_BLOCK_INCREMENTAL), params->block_incremental ? "on" : "off"); } @@ -446,7 +446,7 @@ static void print_block_info(Monitor *mon, BlockInfo *i= nfo, } if (info->has_io_status && info->io_status !=3D BLOCK_DEVICE_IO_ST= ATUS_OK) { monitor_printf(mon, " I/O status: %s\n", - qapi_enum_lookup(BlockDeviceIoStatus_lookup, info->io_stat= us)); + qapi_enum_lookup(&BlockDeviceIoStatus_lookup, info->io_sta= tus)); } =20 if (info->removable) { @@ -476,7 +476,7 @@ static void print_block_info(Monitor *mon, BlockInfo *i= nfo, =20 if (inserted->detect_zeroes !=3D BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) { monitor_printf(mon, " Detect zeroes: %s\n", - qapi_enum_lookup(BlockdevDetectZeroesOptions_lookup, + qapi_enum_lookup(&BlockdevDetectZeroesOptions_lookup, inserted->detect_zeroes)); } =20 @@ -628,7 +628,7 @@ static void hmp_info_VncBasicInfo(Monitor *mon, VncBasi= cInfo *info, name, info->host, info->service, - qapi_enum_lookup(NetworkAddressFamily_lookup, info->fam= ily), + qapi_enum_lookup(&NetworkAddressFamily_lookup, info->fa= mily), info->websocket ? " (Websocket)" : ""); } =20 @@ -638,8 +638,8 @@ static void hmp_info_vnc_authcrypt(Monitor *mon, const = char *indent, VncVencryptSubAuth *vencrypt) { monitor_printf(mon, "%sAuth: %s (Sub: %s)\n", indent, - qapi_enum_lookup(VncPrimaryAuth_lookup, auth), - vencrypt ? qapi_enum_lookup(VncVencryptSubAuth_lookup, *vencrypt) + qapi_enum_lookup(&VncPrimaryAuth_lookup, auth), + vencrypt ? qapi_enum_lookup(&VncVencryptSubAuth_lookup, *vencrypt) : "none"); } =20 @@ -755,7 +755,7 @@ void hmp_info_spice(Monitor *mon, const QDict *qdict) monitor_printf(mon, " auth: %s\n", info->auth); monitor_printf(mon, " compiled: %s\n", info->compiled_version); monitor_printf(mon, " mouse-mode: %s\n", - qapi_enum_lookup(SpiceQueryMouseMode_lookup, info->mouse_mode)); + qapi_enum_lookup(&SpiceQueryMouseMode_lookup, info->mouse_mode)); =20 if (!info->has_channels || info->channels =3D=3D NULL) { monitor_printf(mon, "Channels: none\n"); @@ -1026,10 +1026,10 @@ void hmp_info_tpm(Monitor *mon, const QDict *qdict) for (info =3D info_list; info; info =3D info->next) { TPMInfo *ti =3D info->value; monitor_printf(mon, " tpm%d: model=3D%s\n", - c, qapi_enum_lookup(TpmModel_lookup, ti->model)); + c, qapi_enum_lookup(&TpmModel_lookup, ti->model)); =20 monitor_printf(mon, " \\ %s: type=3D%s", - ti->id, qapi_enum_lookup(TpmTypeOptionsKind_lookup, + ti->id, qapi_enum_lookup(&TpmTypeOptionsKind_lookup, ti->options->type)); =20 switch (ti->options->type) { @@ -1546,8 +1546,7 @@ void hmp_migrate_set_capability(Monitor *mon, const Q= Dict *qdict) MigrationCapabilityStatusList *caps =3D g_malloc0(sizeof(*caps)); int val; =20 - val =3D qapi_enum_parse(MigrationCapability_lookup, cap, - MIGRATION_CAPABILITY__MAX, -1, &err); + val =3D qapi_enum_parse(&MigrationCapability_lookup, cap, -1, &err); if (val < 0) { goto end; } @@ -1576,8 +1575,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QD= ict *qdict) Error *err =3D NULL; int val, ret; =20 - val =3D qapi_enum_parse(MigrationParameter_lookup, param, - MIGRATION_PARAMETER__MAX, -1, &err); + val =3D qapi_enum_parse(&MigrationParameter_lookup, param, -1, &err); if (val < 0) { goto cleanup; } @@ -1752,10 +1750,8 @@ void hmp_change(Monitor *mon, const QDict *qdict) qmp_change("vnc", target, !!arg, arg, &err); } else { if (read_only) { - read_only_mode =3D - qapi_enum_parse(BlockdevChangeReadOnlyMode_lookup, - read_only, BLOCKDEV_CHANGE_READ_ONLY_MODE_= _MAX, - BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &er= r); + read_only_mode =3D qapi_enum_parse(&BlockdevChangeReadOnlyMode= _lookup, + read_only, BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err); if (err) { hmp_handle_error(mon, &err); return; @@ -2386,7 +2382,7 @@ void hmp_info_memdev(Monitor *mon, const QDict *qdict) monitor_printf(mon, " prealloc: %s\n", m->value->prealloc ? "true" : "false"); monitor_printf(mon, " policy: %s\n", - qapi_enum_lookup(HostMemPolicy_lookup, m->value->policy)); + qapi_enum_lookup(&HostMemPolicy_lookup, m->value->policy)); visit_complete(v, &str); monitor_printf(mon, " host nodes: %s\n", str); =20 @@ -2417,7 +2413,7 @@ void hmp_info_memory_devices(Monitor *mon, const QDic= t *qdict) di =3D value->u.dimm.data; =20 monitor_printf(mon, "Memory device [%s]: \"%s\"\n", - qapi_enum_lookup(MemoryDeviceInfoKind_lookup, value->t= ype), + qapi_enum_lookup(&MemoryDeviceInfoKind_lookup, value->= type), di->id ? di->id : ""); monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr); monitor_printf(mon, " slot: %" PRId64 "\n", di->slot); @@ -2812,7 +2808,7 @@ void hmp_info_dump(Monitor *mon, const QDict *qdict) =20 assert(result && result->status < DUMP_STATUS__MAX); monitor_printf(mon, "Status: %s\n", - qapi_enum_lookup(DumpStatus_lookup, result->status)); + qapi_enum_lookup(&DumpStatus_lookup, result->status)); =20 if (result->status =3D=3D DUMP_STATUS_ACTIVE) { float percent =3D 0; diff --git a/hw/block/fdc.c b/hw/block/fdc.c index 8ebe08d1af..df35f3e1cc 100644 --- a/hw/block/fdc.c +++ b/hw/block/fdc.c @@ -393,10 +393,10 @@ static int pick_geometry(FDrive *drv) FLOPPY_DPRINTF("User requested floppy drive type '%s', " "but inserted medium appears to be a " "%"PRId64" sector '%s' type\n", - qapi_enum_lookup(FloppyDriveType_lookup, + qapi_enum_lookup(&FloppyDriveType_lookup, drv->drive), nb_sectors, - qapi_enum_lookup(FloppyDriveType_lookup, + qapi_enum_lookup(&FloppyDriveType_lookup, parse->drive)); } match =3D type_match; @@ -406,7 +406,7 @@ static int pick_geometry(FDrive *drv) if (match =3D=3D -1) { error_setg(&error_abort, "No candidate geometries present in table= " " for floppy drive type '%s'", - qapi_enum_lookup(FloppyDriveType_lookup, drv->drive)); + qapi_enum_lookup(&FloppyDriveType_lookup, drv->drive)); } =20 parse =3D &(fd_formats[match]); diff --git a/hw/char/escc.c b/hw/char/escc.c index 5c1d7b0e29..d5aba2a8a4 100644 --- a/hw/char/escc.c +++ b/hw/char/escc.c @@ -849,7 +849,7 @@ static void sunkbd_handle_event(DeviceState *dev, QemuC= onsole *src, assert(evt->type =3D=3D INPUT_EVENT_KIND_KEY); key =3D evt->u.key.data; qcode =3D qemu_input_key_value_to_qcode(key->key); - trace_escc_sunkbd_event_in(qcode, qapi_enum_lookup(QKeyCode_lookup, qc= ode), + trace_escc_sunkbd_event_in(qcode, qapi_enum_lookup(&QKeyCode_lookup, q= code), key->down); =20 if (qcode =3D=3D Q_KEY_CODE_CAPS_LOCK) { diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index c82c693bca..ee4fc9812b 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -587,7 +587,7 @@ const PropertyInfo qdev_prop_macaddr =3D { const PropertyInfo qdev_prop_on_off_auto =3D { .name =3D "OnOffAuto", .description =3D "on/off/auto", - .enum_table =3D OnOffAuto_lookup, + .enum_table =3D &OnOffAuto_lookup, .get =3D get_enum, .set =3D set_enum, .set_default_value =3D set_default_value_enum, @@ -599,7 +599,7 @@ QEMU_BUILD_BUG_ON(sizeof(LostTickPolicy) !=3D sizeof(in= t)); =20 const PropertyInfo qdev_prop_losttickpolicy =3D { .name =3D "LostTickPolicy", - .enum_table =3D LostTickPolicy_lookup, + .enum_table =3D &LostTickPolicy_lookup, .get =3D get_enum, .set =3D set_enum, .set_default_value =3D set_default_value_enum, @@ -613,7 +613,7 @@ const PropertyInfo qdev_prop_blockdev_on_error =3D { .name =3D "BlockdevOnError", .description =3D "Error handling policy, " "report/ignore/enospc/stop/auto", - .enum_table =3D BlockdevOnError_lookup, + .enum_table =3D &BlockdevOnError_lookup, .get =3D get_enum, .set =3D set_enum, .set_default_value =3D set_default_value_enum, @@ -627,7 +627,7 @@ const PropertyInfo qdev_prop_bios_chs_trans =3D { .name =3D "BiosAtaTranslation", .description =3D "Logical CHS translation algorithm, " "auto/none/lba/large/rechs", - .enum_table =3D BiosAtaTranslation_lookup, + .enum_table =3D &BiosAtaTranslation_lookup, .get =3D get_enum, .set =3D set_enum, .set_default_value =3D set_default_value_enum, @@ -639,7 +639,7 @@ const PropertyInfo qdev_prop_fdc_drive_type =3D { .name =3D "FdcDriveType", .description =3D "FDC drive type, " "144/288/120/none/auto", - .enum_table =3D FloppyDriveType_lookup, + .enum_table =3D &FloppyDriveType_lookup, .get =3D get_enum, .set =3D set_enum, .set_default_value =3D set_default_value_enum, diff --git a/hw/input/virtio-input-hid.c b/hw/input/virtio-input-hid.c index 64039236f1..235b11082f 100644 --- a/hw/input/virtio-input-hid.c +++ b/hw/input/virtio-input-hid.c @@ -210,7 +210,7 @@ static void virtio_input_handle_event(DeviceState *dev,= QemuConsole *src, } else { if (key->down) { fprintf(stderr, "%s: unmapped key: %d [%s]\n", __func__, - qcode, qapi_enum_lookup(QKeyCode_lookup, qcode)); + qcode, qapi_enum_lookup(&QKeyCode_lookup, qcode)); } } break; @@ -225,7 +225,7 @@ static void virtio_input_handle_event(DeviceState *dev,= QemuConsole *src, if (btn->down) { fprintf(stderr, "%s: unmapped button: %d [%s]\n", __func__, btn->button, - qapi_enum_lookup(InputButton_lookup, btn->button)); + qapi_enum_lookup(&InputButton_lookup, btn->button)= ); } } break; diff --git a/migration/colo-failover.c b/migration/colo-failover.c index e5394ba631..c3dd0969d6 100644 --- a/migration/colo-failover.c +++ b/migration/colo-failover.c @@ -35,7 +35,7 @@ static void colo_failover_bh(void *opaque) FAILOVER_STATUS_ACTIVE); if (old_state !=3D FAILOVER_STATUS_REQUIRE) { error_report("Unknown error for failover, old_state =3D %s", - qapi_enum_lookup(FailoverStatus_lookup, old_state)); + qapi_enum_lookup(&FailoverStatus_lookup, old_state)); return; } =20 @@ -65,7 +65,7 @@ FailoverStatus failover_set_state(FailoverStatus old_stat= e, =20 old =3D atomic_cmpxchg(&failover_state, old_state, new_state); if (old =3D=3D old_state) { - trace_colo_failover_set_state(qapi_enum_lookup(FailoverStatus_look= up, + trace_colo_failover_set_state(qapi_enum_lookup(&FailoverStatus_loo= kup, new_state)); } return old; diff --git a/migration/colo.c b/migration/colo.c index 2b683a0afc..8bd7ef0531 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -63,7 +63,7 @@ static void secondary_vm_do_failover(void) if (old_state !=3D FAILOVER_STATUS_ACTIVE) { error_report("Unknown error while do failover for secondary VM= ," "old_state: %s", - qapi_enum_lookup(FailoverStatus_lookup, old_state= )); + qapi_enum_lookup(&FailoverStatus_lookup, old_stat= e)); } return; } @@ -94,7 +94,7 @@ static void secondary_vm_do_failover(void) if (old_state !=3D FAILOVER_STATUS_ACTIVE) { error_report("Incorrect state (%s) while doing failover for " "secondary VM", - qapi_enum_lookup(FailoverStatus_lookup, old_state)); + qapi_enum_lookup(&FailoverStatus_lookup, old_state)); return; } /* Notify COLO incoming thread that failover work is finished */ @@ -129,7 +129,7 @@ static void primary_vm_do_failover(void) FAILOVER_STATUS_COMPLETED); if (old_state !=3D FAILOVER_STATUS_ACTIVE) { error_report("Incorrect state (%s) while doing failover for Primar= y VM", - qapi_enum_lookup(FailoverStatus_lookup, old_state)); + qapi_enum_lookup(&FailoverStatus_lookup, old_state)); return; } /* Notify COLO thread that failover work is finished */ @@ -225,7 +225,7 @@ static void colo_send_message(QEMUFile *f, COLOMessage = msg, if (ret < 0) { error_setg_errno(errp, -ret, "Can't send COLO message"); } - trace_colo_send_message(qapi_enum_lookup(COLOMessage_lookup, msg)); + trace_colo_send_message(qapi_enum_lookup(&COLOMessage_lookup, msg)); } =20 static void colo_send_message_value(QEMUFile *f, COLOMessage msg, @@ -245,7 +245,7 @@ static void colo_send_message_value(QEMUFile *f, COLOMe= ssage msg, ret =3D qemu_file_get_error(f); if (ret < 0) { error_setg_errno(errp, -ret, "Failed to send value for message:%s", - qapi_enum_lookup(COLOMessage_lookup, msg)); + qapi_enum_lookup(&COLOMessage_lookup, msg)); } } =20 @@ -264,7 +264,7 @@ static COLOMessage colo_receive_message(QEMUFile *f, Er= ror **errp) error_setg(errp, "%s: Invalid message", __func__); return msg; } - trace_colo_receive_message(qapi_enum_lookup(COLOMessage_lookup, msg)); + trace_colo_receive_message(qapi_enum_lookup(&COLOMessage_lookup, msg)); return msg; } =20 @@ -302,7 +302,7 @@ static uint64_t colo_receive_message_value(QEMUFile *f,= uint32_t expect_msg, ret =3D qemu_file_get_error(f); if (ret < 0) { error_setg_errno(errp, -ret, "Failed to get value for COLO message= : %s", - qapi_enum_lookup(COLOMessage_lookup, expect_msg)); + qapi_enum_lookup(&COLOMessage_lookup, expect_msg)= ); } return value; } diff --git a/migration/global_state.c b/migration/global_state.c index 4d57a9c5f2..486979c4cc 100644 --- a/migration/global_state.c +++ b/migration/global_state.c @@ -42,7 +42,7 @@ int global_state_store(void) =20 void global_state_store_running(void) { - const char *state =3D qapi_enum_lookup(RunState_lookup, RUN_STATE_RUNN= ING); + const char *state =3D qapi_enum_lookup(&RunState_lookup, RUN_STATE_RUN= NING); strncpy((char *)global_state.runstate, state, sizeof(global_state.runstate)); } @@ -89,8 +89,7 @@ static int global_state_post_load(void *opaque, int versi= on_id) s->received =3D true; trace_migrate_global_state_post_load(runstate); =20 - r =3D qapi_enum_parse(RunState_lookup, runstate, RUN_STATE__MAX, - -1, &local_err); + r =3D qapi_enum_parse(&RunState_lookup, runstate, -1, &local_err); =20 if (r =3D=3D -1) { if (local_err) { diff --git a/monitor.c b/monitor.c index ee2fdfd4f1..228f246fcc 100644 --- a/monitor.c +++ b/monitor.c @@ -929,7 +929,7 @@ EventInfoList *qmp_query_events(Error **errp) QAPIEvent e; =20 for (e =3D 0 ; e < QAPI_EVENT__MAX ; e++) { - const char *event_name =3D qapi_enum_lookup(QAPIEvent_lookup, e); + const char *event_name =3D qapi_enum_lookup(&QAPIEvent_lookup, e); assert(event_name !=3D NULL); info =3D g_malloc0(sizeof(*info)); info->value =3D g_malloc0(sizeof(*info->value)); @@ -3250,9 +3250,9 @@ void netdev_add_completion(ReadLineState *rs, int nb_= args, const char *str) } len =3D strlen(str); readline_set_completion_index(rs, len); - for (i =3D 0; qapi_enum_lookup(NetClientDriver_lookup, i); i++) { + for (i =3D 0; qapi_enum_lookup(&NetClientDriver_lookup, i); i++) { add_completion_option(rs, str, - qapi_enum_lookup(NetClientDriver_lookup, i)); + qapi_enum_lookup(&NetClientDriver_lookup, i)= ); } } =20 @@ -3436,8 +3436,8 @@ void sendkey_completion(ReadLineState *rs, int nb_arg= s, const char *str) len =3D strlen(str); readline_set_completion_index(rs, len); for (i =3D 0; i < Q_KEY_CODE__MAX; i++) { - if (!strncmp(str, qapi_enum_lookup(QKeyCode_lookup, i), len)) { - readline_add_completion(rs, qapi_enum_lookup(QKeyCode_lookup, = i)); + if (!strncmp(str, qapi_enum_lookup(&QKeyCode_lookup, i), len)) { + readline_add_completion(rs, qapi_enum_lookup(&QKeyCode_lookup,= i)); } } } @@ -3539,9 +3539,9 @@ void watchdog_action_completion(ReadLineState *rs, in= t nb_args, const char *str) return; } readline_set_completion_index(rs, strlen(str)); - for (i =3D 0; qapi_enum_lookup(WatchdogExpirationAction_lookup, i); i+= +) { + for (i =3D 0; qapi_enum_lookup(&WatchdogExpirationAction_lookup, i); i= ++) { add_completion_option(rs, str, - qapi_enum_lookup(WatchdogExpirationAction_lookup, i)); + qapi_enum_lookup(&WatchdogExpirationAction_lookup, i)); } } =20 @@ -3555,7 +3555,7 @@ void migrate_set_capability_completion(ReadLineState = *rs, int nb_args, if (nb_args =3D=3D 2) { int i; for (i =3D 0; i < MIGRATION_CAPABILITY__MAX; i++) { - const char *name =3D qapi_enum_lookup(MigrationCapability_look= up, i); + const char *name =3D qapi_enum_lookup(&MigrationCapability_loo= kup, i); if (!strncmp(str, name, len)) { readline_add_completion(rs, name); } @@ -3576,7 +3576,7 @@ void migrate_set_parameter_completion(ReadLineState *= rs, int nb_args, if (nb_args =3D=3D 2) { int i; for (i =3D 0; i < MIGRATION_PARAMETER__MAX; i++) { - const char *name =3D qapi_enum_lookup(MigrationParameter_looku= p, i); + const char *name =3D qapi_enum_lookup(&MigrationParameter_look= up, i); if (!strncmp(str, name, len)) { readline_add_completion(rs, name); } @@ -3855,7 +3855,7 @@ static void handle_qmp_command(JSONMessageParser *par= ser, GQueue *tokens) qdict =3D qdict_get_qdict(qobject_to_qdict(rsp), "error"); if (qdict && !g_strcmp0(qdict_get_try_str(qdict, "class"), - qapi_enum_lookup(QapiErrorClass_lookup, + qapi_enum_lookup(&QapiErrorClass_lookup, ERROR_CLASS_COMMAND_NOT_FOUND))= ) { /* Provide a more useful error message */ qdict_del(qdict, "desc"); diff --git a/net/filter.c b/net/filter.c index 1dfd2caa23..2fd7d7d663 100644 --- a/net/filter.c +++ b/net/filter.c @@ -179,7 +179,7 @@ static void netfilter_init(Object *obj) netfilter_get_netdev_id, netfilter_set_netdev_= id, NULL); object_property_add_enum(obj, "queue", "NetFilterDirection", - NetFilterDirection_lookup, + &NetFilterDirection_lookup, netfilter_get_direction, netfilter_set_direct= ion, NULL); object_property_add_str(obj, "status", diff --git a/net/net.c b/net/net.c index efe2252c59..f4b8739b0b 100644 --- a/net/net.c +++ b/net/net.c @@ -1065,7 +1065,7 @@ static int net_client_init1(const void *object, bool = is_netdev, Error **errp) /* FIXME drop when all init functions store an Error */ if (errp && !*errp) { error_setg(errp, QERR_DEVICE_INIT_FAILED, - qapi_enum_lookup(NetClientDriver_lookup, netdev->ty= pe)); + qapi_enum_lookup(&NetClientDriver_lookup, netdev->t= ype)); } return -1; } @@ -1289,7 +1289,7 @@ void print_net_client(Monitor *mon, NetClientState *n= c) =20 monitor_printf(mon, "%s: index=3D%d,type=3D%s,%s\n", nc->name, nc->queue_index, - qapi_enum_lookup(NetClientDriver_lookup, nc->info->type= ), + qapi_enum_lookup(&NetClientDriver_lookup, nc->info->typ= e), nc->info_str); if (!QTAILQ_EMPTY(&nc->filters)) { monitor_printf(mon, "filters:\n"); diff --git a/qapi/qapi-util.c b/qapi/qapi-util.c index 7677caa51e..363214efb1 100644 --- a/qapi/qapi-util.c +++ b/qapi/qapi-util.c @@ -15,8 +15,8 @@ #include "qemu-common.h" #include "qapi/util.h" =20 -int qapi_enum_parse(const char * const lookup[], const char *buf, - int max, int def, Error **errp) +int qapi_enum_parse(const QEnumLookup *lookup, const char *buf, + int def, Error **errp) { int i; =20 @@ -24,8 +24,8 @@ int qapi_enum_parse(const char * const lookup[], const ch= ar *buf, return def; } =20 - for (i =3D 0; i < max; i++) { - if (!strcmp(buf, lookup[i])) { + for (i =3D 0; i < lookup->size; i++) { + if (!g_strcmp0(buf, lookup->array[i])) { return i; } } @@ -34,11 +34,12 @@ int qapi_enum_parse(const char * const lookup[], const = char *buf, return def; } =20 -const char *qapi_enum_lookup(const char * const lookup[], int val) +const char *qapi_enum_lookup(const QEnumLookup *lookup, int val) { assert(val >=3D 0); + assert(val < lookup->size); =20 - return lookup[val]; + return lookup->array[val]; } =20 /* diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index 06f1470516..7f3302ad3c 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -119,7 +119,7 @@ static QObject *do_qmp_dispatch(QmpCommandList *cmds, Q= Object *request, QObject *qmp_build_error_object(Error *err) { return qobject_from_jsonf("{ 'class': %s, 'desc': %s }", - qapi_enum_lookup(QapiErrorClass_lookup, + qapi_enum_lookup(&QapiErrorClass_lookup, error_get_class(err)), error_get_pretty(err)); } diff --git a/qemu-img.c b/qemu-img.c index 56ef49e214..19f1996f90 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3490,10 +3490,8 @@ static int img_resize(int argc, char **argv) image_opts =3D true; break; case OPTION_PREALLOCATION: - prealloc =3D qapi_enum_parse(PreallocMode_lookup, optarg, - PREALLOC_MODE__MAX, PREALLOC_MODE__= MAX, - NULL); - if (prealloc =3D=3D PREALLOC_MODE__MAX) { + prealloc =3D qapi_enum_parse(&PreallocMode_lookup, optarg, -1,= NULL); + if (prealloc =3D=3D -1) { error_report("Invalid preallocation mode '%s'", optarg); return 1; } diff --git a/qemu-nbd.c b/qemu-nbd.c index 27164b8205..0dda0cce05 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -639,9 +639,8 @@ int main(int argc, char **argv) break; case QEMU_NBD_OPT_DETECT_ZEROES: detect_zeroes =3D - qapi_enum_parse(BlockdevDetectZeroesOptions_lookup, + qapi_enum_parse(&BlockdevDetectZeroesOptions_lookup, optarg, - BLOCKDEV_DETECT_ZEROES_OPTIONS__MAX, BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF, &local_err); if (local_err) { diff --git a/qom/object.c b/qom/object.c index fe6e744b4d..3e18537e9b 100644 --- a/qom/object.c +++ b/qom/object.c @@ -1246,7 +1246,7 @@ uint64_t object_property_get_uint(Object *obj, const = char *name, } =20 typedef struct EnumProperty { - const char * const *strings; + const QEnumLookup *lookup; int (*get)(Object *, Error **); void (*set)(Object *, int, Error **); } EnumProperty; @@ -1284,7 +1284,7 @@ int object_property_get_enum(Object *obj, const char = *name, visit_complete(v, &str); visit_free(v); v =3D string_input_visitor_new(str); - visit_type_enum(v, name, &ret, enumprop->strings, errp); + visit_type_enum(v, name, &ret, enumprop->lookup, errp); =20 g_free(str); visit_free(v); @@ -1950,7 +1950,7 @@ static void property_get_enum(Object *obj, Visitor *v= , const char *name, return; } =20 - visit_type_enum(v, name, &value, prop->strings, errp); + visit_type_enum(v, name, &value, prop->lookup, errp); } =20 static void property_set_enum(Object *obj, Visitor *v, const char *name, @@ -1960,7 +1960,7 @@ static void property_set_enum(Object *obj, Visitor *v= , const char *name, int value; Error *err =3D NULL; =20 - visit_type_enum(v, name, &value, prop->strings, &err); + visit_type_enum(v, name, &value, prop->lookup, &err); if (err) { error_propagate(errp, err); return; @@ -1977,7 +1977,7 @@ static void property_release_enum(Object *obj, const = char *name, =20 void object_property_add_enum(Object *obj, const char *name, const char *typename, - const char * const *strings, + const QEnumLookup *lookup, int (*get)(Object *, Error **), void (*set)(Object *, int, Error **), Error **errp) @@ -1985,7 +1985,7 @@ void object_property_add_enum(Object *obj, const char= *name, Error *local_err =3D NULL; EnumProperty *prop =3D g_malloc(sizeof(*prop)); =20 - prop->strings =3D strings; + prop->lookup =3D lookup; prop->get =3D get; prop->set =3D set; =20 @@ -2002,7 +2002,7 @@ void object_property_add_enum(Object *obj, const char= *name, =20 void object_class_property_add_enum(ObjectClass *klass, const char *name, const char *typename, - const char * const *strings, + const QEnumLookup *lookup, int (*get)(Object *, Error **), void (*set)(Object *, int, Error **), Error **errp) @@ -2010,7 +2010,7 @@ void object_class_property_add_enum(ObjectClass *klas= s, const char *name, Error *local_err =3D NULL; EnumProperty *prop =3D g_malloc(sizeof(*prop)); =20 - prop->strings =3D strings; + prop->lookup =3D lookup; prop->get =3D get; prop->set =3D set; =20 diff --git a/tests/check-qom-proplist.c b/tests/check-qom-proplist.c index c51e6e734d..0ba8b55ce1 100644 --- a/tests/check-qom-proplist.c +++ b/tests/check-qom-proplist.c @@ -53,6 +53,11 @@ static const char *const dummy_animal_map[DUMMY_LAST + 1= ] =3D { [DUMMY_LAST] =3D NULL, }; =20 +const QEnumLookup dummy_animal_lookup =3D { + .array =3D dummy_animal_map, + .size =3D DUMMY_LAST +}; + struct DummyObject { Object parent_obj; =20 @@ -142,7 +147,7 @@ static void dummy_class_init(ObjectClass *cls, void *da= ta) NULL); object_class_property_add_enum(cls, "av", "DummyAnimal", - dummy_animal_map, + &dummy_animal_lookup, dummy_get_av, dummy_set_av, NULL); diff --git a/tests/test-qapi-util.c b/tests/test-qapi-util.c index e8697577a5..fc9436ff94 100644 --- a/tests/test-qapi-util.c +++ b/tests/test-qapi-util.c @@ -20,24 +20,21 @@ static void test_qapi_enum_parse(void) Error *err =3D NULL; int ret; =20 - ret =3D qapi_enum_parse(QType_lookup, NULL, QTYPE__MAX, QTYPE_NONE, - &error_abort); + ret =3D qapi_enum_parse(&QType_lookup, NULL, QTYPE_NONE, &error_abort); g_assert_cmpint(ret, =3D=3D, QTYPE_NONE); =20 - ret =3D qapi_enum_parse(QType_lookup, "junk", QTYPE__MAX, -1, - NULL); + ret =3D qapi_enum_parse(&QType_lookup, "junk", -1, NULL); g_assert_cmpint(ret, =3D=3D, -1); =20 - ret =3D qapi_enum_parse(QType_lookup, "junk", QTYPE__MAX, -1, - &err); + ret =3D qapi_enum_parse(&QType_lookup, "junk", -1, &err); error_free_or_abort(&err); =20 - ret =3D qapi_enum_parse(QType_lookup, "none", QTYPE__MAX, -1, - &error_abort); + ret =3D qapi_enum_parse(&QType_lookup, "none", -1, &error_abort); g_assert_cmpint(ret, =3D=3D, QTYPE_NONE); =20 - ret =3D qapi_enum_parse(QType_lookup, QType_lookup[QTYPE__MAX - 1], - QTYPE__MAX, QTYPE__MAX - 1, + ret =3D qapi_enum_parse(&QType_lookup, + qapi_enum_lookup(&QType_lookup, QTYPE__MAX - 1), + QTYPE__MAX - 1, &error_abort); g_assert_cmpint(ret, =3D=3D, QTYPE__MAX - 1); } diff --git a/tests/test-qobject-input-visitor.c b/tests/test-qobject-input-= visitor.c index bdd00f6bd8..be7d7ea654 100644 --- a/tests/test-qobject-input-visitor.c +++ b/tests/test-qobject-input-visitor.c @@ -382,10 +382,10 @@ static void test_visitor_in_enum(TestInputVisitorData= *data, Visitor *v; EnumOne i; =20 - for (i =3D 0; EnumOne_lookup[i]; i++) { + for (i =3D 0; i < EnumOne_lookup.size; i++) { EnumOne res =3D -1; =20 - v =3D visitor_input_test_init(data, "%s", EnumOne_lookup[i]); + v =3D visitor_input_test_init(data, "%s", EnumOne_lookup.array[i]); =20 visit_type_EnumOne(v, NULL, &res, &error_abort); g_assert_cmpint(i, =3D=3D, res); @@ -699,7 +699,7 @@ static void test_native_list_integer_helper(TestInputVi= sitorData *data, } } g_string_append_printf(gstr_union, "{ 'type': '%s', 'data': [ %s ] }", - UserDefNativeListUnionKind_lookup[kind], + UserDefNativeListUnionKind_lookup.array[kind], gstr_list->str); v =3D visitor_input_test_init_raw(data, gstr_union->str); =20 @@ -1110,7 +1110,7 @@ static void test_visitor_in_fail_struct_missing(TestI= nputVisitorData *data, error_free_or_abort(&err); visit_optional(v, "optional", &present); g_assert(!present); - visit_type_enum(v, "enum", &en, EnumOne_lookup, &err); + visit_type_enum(v, "enum", &en, &EnumOne_lookup, &err); error_free_or_abort(&err); visit_type_int(v, "i64", &i64, &err); error_free_or_abort(&err); diff --git a/tests/test-qobject-output-visitor.c b/tests/test-qobject-outpu= t-visitor.c index bb2d66b666..55a8c932e0 100644 --- a/tests/test-qobject-output-visitor.c +++ b/tests/test-qobject-output-visitor.c @@ -135,7 +135,7 @@ static void test_visitor_out_enum(TestOutputVisitorData= *data, qstr =3D qobject_to_qstring(visitor_get(data)); g_assert(qstr); g_assert_cmpstr(qstring_get_str(qstr), =3D=3D, - qapi_enum_lookup(EnumOne_lookup, i)); + qapi_enum_lookup(&EnumOne_lookup, i)); visitor_reset(data); } } diff --git a/tests/test-string-input-visitor.c b/tests/test-string-input-vi= sitor.c index 79313a7f7a..5828359830 100644 --- a/tests/test-string-input-visitor.c +++ b/tests/test-string-input-visitor.c @@ -279,10 +279,10 @@ static void test_visitor_in_enum(TestInputVisitorData= *data, Visitor *v; EnumOne i; =20 - for (i =3D 0; EnumOne_lookup[i]; i++) { + for (i =3D 0; i < EnumOne_lookup.size; i++) { EnumOne res =3D -1; =20 - v =3D visitor_input_test_init(data, EnumOne_lookup[i]); + v =3D visitor_input_test_init(data, EnumOne_lookup.array[i]); =20 visit_type_EnumOne(v, NULL, &res, &err); g_assert(!err); diff --git a/tests/test-string-output-visitor.c b/tests/test-string-output-= visitor.c index 0b2087d312..a5d26ac0ca 100644 --- a/tests/test-string-output-visitor.c +++ b/tests/test-string-output-visitor.c @@ -196,12 +196,12 @@ static void test_visitor_out_enum(TestOutputVisitorDa= ta *data, str =3D visitor_get(data); if (data->human) { char *str_human =3D - g_strdup_printf("\"%s\"", qapi_enum_lookup(EnumOne_lookup,= i)); + g_strdup_printf("\"%s\"", qapi_enum_lookup(&EnumOne_lookup= , i)); =20 g_assert_cmpstr(str, =3D=3D, str_human); g_free(str_human); } else { - g_assert_cmpstr(str, =3D=3D, qapi_enum_lookup(EnumOne_lookup, = i)); + g_assert_cmpstr(str, =3D=3D, qapi_enum_lookup(&EnumOne_lookup,= i)); } visitor_reset(data); } diff --git a/tpm.c b/tpm.c index f175661bfe..3ddd889906 100644 --- a/tpm.c +++ b/tpm.c @@ -63,7 +63,7 @@ static bool tpm_model_is_registered(enum TpmModel model) =20 const TPMDriverOps *tpm_get_backend_driver(const char *type) { - int i =3D qapi_enum_parse(TpmType_lookup, type, TPM_TYPE__MAX, -1, NUL= L); + int i =3D qapi_enum_parse(&TpmType_lookup, type, -1, NULL); =20 return i >=3D 0 ? be_drivers[i] : NULL; } @@ -92,7 +92,7 @@ static void tpm_display_backend_drivers(void) continue; } fprintf(stderr, "%12s %s\n", - qapi_enum_lookup(TpmType_lookup, i), + qapi_enum_lookup(&TpmType_lookup, i), be_drivers[i]->desc()); } fprintf(stderr, "\n"); diff --git a/ui/input-legacy.c b/ui/input-legacy.c index 7159747404..c597bdc711 100644 --- a/ui/input-legacy.c +++ b/ui/input-legacy.c @@ -61,9 +61,9 @@ int index_from_key(const char *key, size_t key_length) { int i; =20 - for (i =3D 0; QKeyCode_lookup[i] !=3D NULL; i++) { - if (!strncmp(key, QKeyCode_lookup[i], key_length) && - !QKeyCode_lookup[i][key_length]) { + for (i =3D 0; QKeyCode_lookup.array[i] !=3D NULL; i++) { + if (!strncmp(key, QKeyCode_lookup.array[i], key_length) && + !QKeyCode_lookup.array[i][key_length]) { break; } } diff --git a/ui/input.c b/ui/input.c index 6bceb6b825..dfae347154 100644 --- a/ui/input.c +++ b/ui/input.c @@ -152,7 +152,7 @@ void qmp_input_send_event(bool has_device, const char *= device, if (!qemu_input_find_handler(1 << event->type, con)) { error_setg(errp, "Input handler not found for " "event type %s", - qapi_enum_lookup(InputEventKind_lookup, event->type= )); + qapi_enum_lookup(&InputEventKind_lookup, event->typ= e)); return; } } @@ -214,12 +214,12 @@ static void qemu_input_event_trace(QemuConsole *src, = InputEvent *evt) switch (key->key->type) { case KEY_VALUE_KIND_NUMBER: qcode =3D qemu_input_key_number_to_qcode(key->key->u.number.da= ta); - name =3D qapi_enum_lookup(QKeyCode_lookup, qcode); + name =3D qapi_enum_lookup(&QKeyCode_lookup, qcode); trace_input_event_key_number(idx, key->key->u.number.data, name, key->down); break; case KEY_VALUE_KIND_QCODE: - name =3D qapi_enum_lookup(QKeyCode_lookup, key->key->u.qcode.d= ata); + name =3D qapi_enum_lookup(&QKeyCode_lookup, key->key->u.qcode.= data); trace_input_event_key_qcode(idx, name, key->down); break; case KEY_VALUE_KIND__MAX: @@ -229,17 +229,17 @@ static void qemu_input_event_trace(QemuConsole *src, = InputEvent *evt) break; case INPUT_EVENT_KIND_BTN: btn =3D evt->u.btn.data; - name =3D qapi_enum_lookup(InputButton_lookup, btn->button); + name =3D qapi_enum_lookup(&InputButton_lookup, btn->button); trace_input_event_btn(idx, name, btn->down); break; case INPUT_EVENT_KIND_REL: move =3D evt->u.rel.data; - name =3D qapi_enum_lookup(InputAxis_lookup, move->axis); + name =3D qapi_enum_lookup(&InputAxis_lookup, move->axis); trace_input_event_rel(idx, name, move->value); break; case INPUT_EVENT_KIND_ABS: move =3D evt->u.abs.data; - name =3D qapi_enum_lookup(InputAxis_lookup, move->axis); + name =3D qapi_enum_lookup(&InputAxis_lookup, move->axis); trace_input_event_abs(idx, name, move->value); break; case INPUT_EVENT_KIND__MAX: diff --git a/ui/vnc.c b/ui/vnc.c index 20a45a7241..afe46dd8ae 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -132,7 +132,7 @@ static void vnc_init_basic_info(SocketAddress *addr, case SOCKET_ADDRESS_TYPE_VSOCK: case SOCKET_ADDRESS_TYPE_FD: error_setg(errp, "Unsupported socket address type %s", - qapi_enum_lookup(SocketAddressType_lookup, addr->type)); + qapi_enum_lookup(&SocketAddressType_lookup, addr->type)= ); break; default: abort(); @@ -417,7 +417,7 @@ VncInfo *qmp_query_vnc(Error **errp) case SOCKET_ADDRESS_TYPE_VSOCK: case SOCKET_ADDRESS_TYPE_FD: error_setg(errp, "Unsupported socket address type %s", - qapi_enum_lookup(SocketAddressType_lookup, addr->ty= pe)); + qapi_enum_lookup(&SocketAddressType_lookup, addr->t= ype)); goto out_error; default: abort(); @@ -1840,7 +1840,7 @@ static void vnc_release_modifiers(VncState *vs) =20 static const char *code2name(int keycode) { - return qapi_enum_lookup(QKeyCode_lookup, + return qapi_enum_lookup(&QKeyCode_lookup, qemu_input_key_number_to_qcode(keycode)); } =20 diff --git a/vl.c b/vl.c index def4f5f05f..adeb6ed479 100644 --- a/vl.c +++ b/vl.c @@ -689,7 +689,7 @@ bool runstate_check(RunState state) =20 bool runstate_store(char *str, size_t size) { - const char *state =3D qapi_enum_lookup(RunState_lookup, current_run_st= ate); + const char *state =3D qapi_enum_lookup(&RunState_lookup, current_run_s= tate); size_t len =3D strlen(state) + 1; =20 if (len > size) { @@ -722,8 +722,8 @@ void runstate_set(RunState new_state) =20 if (!runstate_valid_transitions[current_run_state][new_state]) { error_report("invalid runstate transition: '%s' -> '%s'", - qapi_enum_lookup(RunState_lookup, current_run_state), - qapi_enum_lookup(RunState_lookup, new_state)); + qapi_enum_lookup(&RunState_lookup, current_run_state), + qapi_enum_lookup(&RunState_lookup, new_state)); abort(); } trace_runstate_set(new_state); --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 1503410577499793.0155986523691; Tue, 22 Aug 2017 07:02:57 -0700 (PDT) Received: from localhost ([::1]:47271 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9lg-00081q-Aj for importer@patchew.org; Tue, 22 Aug 2017 10:02:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55348) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9JX-0008Bo-Eq for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9JW-00079T-Gu for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38446) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9JO-00072C-TL; Tue, 22 Aug 2017 09:33:43 -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 89606806BE; Tue, 22 Aug 2017 13:24:18 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3633061786; Tue, 22 Aug 2017 13:24:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 89606806BE 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: Tue, 22 Aug 2017 15:22:14 +0200 Message-Id: <20170822132255.23945-14-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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.26]); Tue, 22 Aug 2017 13:24:18 +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/54] qapi: drop the sentinel in enum array 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: Kevin Wolf , Michael Roth , "open list:parallels" , Markus Armbruster , Max Reitz , Gerd Hoffmann , Stefan Hajnoczi , "Denis V. Lunev" , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= 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" Now that all usages have been converted to user lookup helpers. Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi.py | 1 - block/parallels.c | 1 - ui/input-legacy.c | 2 +- 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/qapi.py b/scripts/qapi.py index 314d7e0365..73adb90379 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -1863,7 +1863,6 @@ static const char *const %(c_name)s_array[] =3D { =20 max_index =3D c_enum_const(name, '_MAX', prefix) ret +=3D mcgen(''' - [%(max_index)s] =3D NULL, }; =20 const QEnumLookup %(c_name)s_lookup =3D { diff --git a/block/parallels.c b/block/parallels.c index f870bbac3e..d5de692c9c 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -72,7 +72,6 @@ typedef enum ParallelsPreallocMode { static const char *prealloc_mode_array[] =3D { "falloc", "truncate", - NULL, }; =20 static QEnumLookup prealloc_mode_lookup =3D { diff --git a/ui/input-legacy.c b/ui/input-legacy.c index c597bdc711..d50a18a505 100644 --- a/ui/input-legacy.c +++ b/ui/input-legacy.c @@ -61,7 +61,7 @@ int index_from_key(const char *key, size_t key_length) { int i; =20 - for (i =3D 0; QKeyCode_lookup.array[i] !=3D NULL; i++) { + for (i =3D 0; i < QKeyCode_lookup.size; i++) { if (!strncmp(key, QKeyCode_lookup.array[i], key_length) && !QKeyCode_lookup.array[i][key_length]) { break; --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 1503409350946644.1729705201344; Tue, 22 Aug 2017 06:42:30 -0700 (PDT) Received: from localhost ([::1]:47037 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9Rs-0006qN-PH for importer@patchew.org; Tue, 22 Aug 2017 09:42:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54698) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9Hc-0006TJ-OE for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:31:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9HZ-0005wR-3D for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:31:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53946) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9HY-0005w4-Sb for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:31:48 -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 AE2957EA90; Tue, 22 Aug 2017 13:24:23 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id AE3C163740; Tue, 22 Aug 2017 13:24:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com AE2957EA90 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: Tue, 22 Aug 2017 15:22:15 +0200 Message-Id: <20170822132255.23945-15-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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]); Tue, 22 Aug 2017 13:24:23 +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/54] qapi2texi: minor python code simplification 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?= , Markus Armbruster , Michael Roth 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 Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- scripts/qapi2texi.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/scripts/qapi2texi.py b/scripts/qapi2texi.py index a317526e51..8b542f9fff 100755 --- a/scripts/qapi2texi.py +++ b/scripts/qapi2texi.py @@ -136,10 +136,9 @@ def texi_enum_value(value): def texi_member(member, suffix=3D''): """Format a table of members item for an object type member""" typ =3D member.type.doc_type() - return '@item @code{%s%s%s}%s%s\n' % ( - member.name, - ': ' if typ else '', - typ if typ else '', + membertype =3D ': %s' % typ if typ else '' + return '@item @code{%s%s}%s%s\n' % ( + member.name, membertype, ' (optional)' if member.optional else '', suffix) =20 --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 1503409812152845.6601858607539; Tue, 22 Aug 2017 06:50:12 -0700 (PDT) Received: from localhost ([::1]:47132 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9ZK-00058T-SH for importer@patchew.org; Tue, 22 Aug 2017 09:50:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54463) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9H3-0005xz-74 for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:31:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9Gz-0005KR-4O for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:31:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:63581) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9Gy-0005K2-Ru for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:31:13 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 12C2F769E1; Tue, 22 Aug 2017 13:24:28 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9802460606; Tue, 22 Aug 2017 13:24:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 12C2F769E1 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: Tue, 22 Aug 2017 15:22:16 +0200 Message-Id: <20170822132255.23945-16-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 22 Aug 2017 13:24:28 +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 15/54] qapi: add 'if' to top-level expressions 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?= , Markus Armbruster , Michael Roth 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" Accept 'if' key in top-level elements, accepted as string or list of string type. The following patches will modify the test visitor to check the value is correctly saved, and generate #if/#endif code (as a single #if/endif line or a series for a list). Example of 'if' key: { 'struct': 'TestIfStruct', 'data': { 'foo': 'int' }, = = 'if': 'define= d(TEST_IF_STRUCT)' } A following patch for qapi-code-gen.txt will provide more complete documentation for 'if' usage. Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi.py | 13 +++++++++++++ tests/test-qmp-commands.c | 6 ++++++ tests/qapi-schema/qapi-schema-test.json | 20 ++++++++++++++++++++ tests/qapi-schema/qapi-schema-test.out | 22 ++++++++++++++++++++++ 4 files changed, 61 insertions(+) diff --git a/scripts/qapi.py b/scripts/qapi.py index 73adb90379..a94d93ada4 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -639,6 +639,16 @@ def add_name(name, info, meta, implicit=3DFalse): all_names[name] =3D meta =20 =20 +def check_if(expr, info): + ifcond =3D expr.get('if') + if not ifcond or isinstance(ifcond, str): + return + if (not isinstance(ifcond, list) or + any([not isinstance(elt, str) for elt in ifcond])): + raise QAPISemError(info, "'if' condition requires a string or " + "a list of string") + + def check_type(info, source, value, allow_array=3DFalse, allow_dict=3DFalse, allow_optional=3DFalse, allow_metas=3D[]): @@ -865,6 +875,7 @@ def check_keys(expr_elem, meta, required, optional=3D[]= ): expr =3D expr_elem['expr'] info =3D expr_elem['info'] name =3D expr[meta] + optional =3D optional + ['if'] # all top-level elem accept if if not isinstance(name, str): raise QAPISemError(info, "'%s' key must have a string value" % met= a) required =3D required + [meta] @@ -880,6 +891,8 @@ def check_keys(expr_elem, meta, required, optional=3D[]= ): raise QAPISemError(info, "'%s' of %s '%s' should only use true value" % (key, meta, name)) + if key =3D=3D 'if': + check_if(expr, info) for key in required: if key not in expr: raise QAPISemError(info, "Key '%s' is missing from %s '%s'" diff --git a/tests/test-qmp-commands.c b/tests/test-qmp-commands.c index 904c89d4d4..9b9a7ffee7 100644 --- a/tests/test-qmp-commands.c +++ b/tests/test-qmp-commands.c @@ -10,6 +10,12 @@ =20 static QmpCommandList qmp_commands; =20 +/* #if defined(TEST_IF_CMD) */ +void qmp_TestIfCmd(TestIfStruct *foo, Error **errp) +{ +} +/* #endif */ + void qmp_user_def_cmd(Error **errp) { } diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qa= pi-schema-test.json index c72dbd8050..dc2c444fc1 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -188,3 +188,23 @@ 'data': { 'a': ['__org.qemu_x-Enum'], 'b': ['__org.qemu_x-Struct'], 'c': '__org.qemu_x-Union2', 'd': '__org.qemu_x-Alt' }, 'returns': '__org.qemu_x-Union1' } + +# test 'if' condition handling + +{ 'struct': 'TestIfStruct', 'data': { 'foo': 'int' }, + 'if': 'defined(TEST_IF_STRUCT)' } + +{ 'enum': 'TestIfEnum', 'data': [ 'foo', 'bar' ], + 'if': 'defined(TEST_IF_ENUM)' } + +{ 'union': 'TestIfUnion', 'data': { 'foo': 'TestStruct' }, + 'if': 'defined(TEST_IF_UNION) && defined(TEST_IF_STRUCT)' } + +{ 'alternate': 'TestIfAlternate', 'data': { 'foo': 'int', 'bar': 'TestStru= ct' }, + 'if': 'defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT)' } + +{ 'command': 'TestIfCmd', 'data': { 'foo': 'TestIfStruct' }, + 'if': 'defined(TEST_IF_CMD) && defined(TEST_IF_STRUCT)' } + +{ 'event': 'TestIfEvent', 'data': { 'foo': 'TestIfStruct' }, + 'if': 'defined(TEST_IF_EVT) && defined(TEST_IF_STRUCT)' } diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index 3b1e9082d3..7fbaea19bc 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -52,6 +52,22 @@ enum QEnumTwo ['value1', 'value2'] prefix QENUM_TWO enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool'] prefix QTYPE +alternate TestIfAlternate + tag type + case foo: int + case bar: TestStruct +command TestIfCmd q_obj_TestIfCmd-arg -> None + gen=3DTrue success_response=3DTrue boxed=3DFalse +enum TestIfEnum ['foo', 'bar'] +event TestIfEvent q_obj_TestIfEvent-arg + boxed=3DFalse +object TestIfStruct + member foo: int optional=3DFalse +object TestIfUnion + member type: TestIfUnionKind optional=3DFalse + tag type + case foo: q_obj_TestStruct-wrapper +enum TestIfUnionKind ['foo'] object TestStruct member integer: int optional=3DFalse member boolean: bool optional=3DFalse @@ -172,6 +188,12 @@ object q_obj_EVENT_D-arg member b: str optional=3DFalse member c: str optional=3DTrue member enum3: EnumOne optional=3DTrue +object q_obj_TestIfCmd-arg + member foo: TestIfStruct optional=3DFalse +object q_obj_TestIfEvent-arg + member foo: TestIfStruct optional=3DFalse +object q_obj_TestStruct-wrapper + member data: TestStruct optional=3DFalse object q_obj_UserDefFlatUnion2-base member integer: int optional=3DTrue member string: str optional=3DFalse --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 1503410628699750.4612611161505; Tue, 22 Aug 2017 07:03:48 -0700 (PDT) Received: from localhost ([::1]:47273 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9mV-0000Ar-J2 for importer@patchew.org; Tue, 22 Aug 2017 10:03:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55182) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9JL-000822-BM for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9JJ-0006yT-0E for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58420) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9JI-0006xs-Qe for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:36 -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 13B57C047B8F; Tue, 22 Aug 2017 13:24:33 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id E773266FE0; Tue, 22 Aug 2017 13:24:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 13B57C047B8F 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: Tue, 22 Aug 2017 15:22:17 +0200 Message-Id: <20170822132255.23945-17-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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]); Tue, 22 Aug 2017 13:24: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 16/54] qapi: add a test for invalid 'if' 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?= , Markus Armbruster , Michael Roth 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/Makefile.include | 1 + tests/qapi-schema/bad-if.err | 1 + tests/qapi-schema/bad-if.exit | 1 + tests/qapi-schema/bad-if.json | 3 +++ tests/qapi-schema/bad-if.out | 0 5 files changed, 6 insertions(+) create mode 100644 tests/qapi-schema/bad-if.err create mode 100644 tests/qapi-schema/bad-if.exit create mode 100644 tests/qapi-schema/bad-if.json create mode 100644 tests/qapi-schema/bad-if.out diff --git a/tests/Makefile.include b/tests/Makefile.include index 3653c7b40a..1f1d8f075b 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -396,6 +396,7 @@ qapi-schema +=3D args-unknown.json qapi-schema +=3D bad-base.json qapi-schema +=3D bad-data.json qapi-schema +=3D bad-ident.json +qapi-schema +=3D bad-if.json qapi-schema +=3D bad-type-bool.json qapi-schema +=3D bad-type-dict.json qapi-schema +=3D bad-type-int.json diff --git a/tests/qapi-schema/bad-if.err b/tests/qapi-schema/bad-if.err new file mode 100644 index 0000000000..8054fbb143 --- /dev/null +++ b/tests/qapi-schema/bad-if.err @@ -0,0 +1 @@ +tests/qapi-schema/bad-if.json:2: 'if' condition requires a string or a lis= t of string diff --git a/tests/qapi-schema/bad-if.exit b/tests/qapi-schema/bad-if.exit new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/tests/qapi-schema/bad-if.exit @@ -0,0 +1 @@ +1 diff --git a/tests/qapi-schema/bad-if.json b/tests/qapi-schema/bad-if.json new file mode 100644 index 0000000000..3edd1a0bf2 --- /dev/null +++ b/tests/qapi-schema/bad-if.json @@ -0,0 +1,3 @@ +# check invalid 'if' type +{ 'struct': 'TestIfStruct', 'data': { 'foo': 'int' }, + 'if': { 'value': 'defined(TEST_IF_STRUCT)' } } diff --git a/tests/qapi-schema/bad-if.out b/tests/qapi-schema/bad-if.out new file mode 100644 index 0000000000..e69de29bb2 --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 1503410648204130.71982260317475; Tue, 22 Aug 2017 07:04:08 -0700 (PDT) Received: from localhost ([::1]:47275 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9mo-0000P1-Ru for importer@patchew.org; Tue, 22 Aug 2017 10:04:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55214) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9JN-00083l-0p for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9JI-0006xl-5u for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58296) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9JH-0006wh-SL for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:36 -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 D7B6FC04D2B3; Tue, 22 Aug 2017 13:24:37 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5A8BE60466; Tue, 22 Aug 2017 13:24:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D7B6FC04D2B3 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: Tue, 22 Aug 2017 15:22:18 +0200 Message-Id: <20170822132255.23945-18-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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.31]); Tue, 22 Aug 2017 13:24:38 +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 17/54] qapi: add 'if' condition on entity objects 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?= , Markus Armbruster , Michael Roth 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" Take 'if' from expression, and use it to construct entity objects. Shared implicit objects must share the same 'if' condition. Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi.py | 81 +++++++++++++++++++++++++++++++++++++----------------= ---- 1 file changed, 53 insertions(+), 28 deletions(-) diff --git a/scripts/qapi.py b/scripts/qapi.py index a94d93ada4..dc40d74abb 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -992,7 +992,7 @@ def check_exprs(exprs): # =20 class QAPISchemaEntity(object): - def __init__(self, name, info, doc): + def __init__(self, name, info, doc, ifcond=3DNone): assert isinstance(name, str) self.name =3D name # For explicitly defined entities, info points to the (explicit) @@ -1002,6 +1002,7 @@ class QAPISchemaEntity(object): # such place). self.info =3D info self.doc =3D doc + self.ifcond =3D ifcond =20 def c_name(self): return c_name(self.name) @@ -1118,8 +1119,8 @@ class QAPISchemaBuiltinType(QAPISchemaType): =20 =20 class QAPISchemaEnumType(QAPISchemaType): - def __init__(self, name, info, doc, values, prefix): - QAPISchemaType.__init__(self, name, info, doc) + def __init__(self, name, info, doc, values, prefix, ifcond=3DNone): + QAPISchemaType.__init__(self, name, info, doc, ifcond) for v in values: assert isinstance(v, QAPISchemaMember) v.set_owner(name) @@ -1162,6 +1163,7 @@ class QAPISchemaArrayType(QAPISchemaType): def check(self, schema): self.element_type =3D schema.lookup_type(self._element_type_name) assert self.element_type + self.ifcond =3D self.element_type.ifcond =20 def is_implicit(self): return True @@ -1183,11 +1185,12 @@ class QAPISchemaArrayType(QAPISchemaType): =20 =20 class QAPISchemaObjectType(QAPISchemaType): - def __init__(self, name, info, doc, base, local_members, variants): + def __init__(self, name, info, doc, base, local_members, variants, + ifcond=3DNone): # struct has local_members, optional base, and no variants # flat union has base, variants, and no local_members # simple union has local_members, variants, and no base - QAPISchemaType.__init__(self, name, info, doc) + QAPISchemaType.__init__(self, name, info, doc, ifcond) assert base is None or isinstance(base, str) for m in local_members: assert isinstance(m, QAPISchemaObjectTypeMember) @@ -1375,8 +1378,8 @@ class QAPISchemaObjectTypeVariant(QAPISchemaObjectTyp= eMember): =20 =20 class QAPISchemaAlternateType(QAPISchemaType): - def __init__(self, name, info, doc, variants): - QAPISchemaType.__init__(self, name, info, doc) + def __init__(self, name, info, doc, variants, ifcond): + QAPISchemaType.__init__(self, name, info, doc, ifcond) assert isinstance(variants, QAPISchemaObjectTypeVariants) assert variants.tag_member variants.set_owner(name) @@ -1413,8 +1416,8 @@ class QAPISchemaAlternateType(QAPISchemaType): =20 class QAPISchemaCommand(QAPISchemaEntity): def __init__(self, name, info, doc, arg_type, ret_type, - gen, success_response, boxed): - QAPISchemaEntity.__init__(self, name, info, doc) + gen, success_response, boxed, ifcond): + QAPISchemaEntity.__init__(self, name, info, doc, ifcond) assert not arg_type or isinstance(arg_type, str) assert not ret_type or isinstance(ret_type, str) self._arg_type_name =3D arg_type @@ -1451,8 +1454,8 @@ class QAPISchemaCommand(QAPISchemaEntity): =20 =20 class QAPISchemaEvent(QAPISchemaEntity): - def __init__(self, name, info, doc, arg_type, boxed): - QAPISchemaEntity.__init__(self, name, info, doc) + def __init__(self, name, info, doc, arg_type, boxed, ifcond): + QAPISchemaEntity.__init__(self, name, info, doc, ifcond) assert not arg_type or isinstance(arg_type, str) self._arg_type_name =3D arg_type self.arg_type =3D None @@ -1547,11 +1550,11 @@ class QAPISchema(object): def _make_enum_members(self, values): return [QAPISchemaMember(v) for v in values] =20 - def _make_implicit_enum_type(self, name, info, values): + def _make_implicit_enum_type(self, name, info, values, ifcond): # See also QAPISchemaObjectTypeMember._pretty_owner() name =3D name + 'Kind' # Use namespace reserved by add_name() self._def_entity(QAPISchemaEnumType( - name, info, None, self._make_enum_members(values), None)) + name, info, None, self._make_enum_members(values), None, ifcon= d)) return name =20 def _make_array_type(self, element_type, info): @@ -1560,22 +1563,29 @@ class QAPISchema(object): self._def_entity(QAPISchemaArrayType(name, info, element_type)) return name =20 - def _make_implicit_object_type(self, name, info, doc, role, members): + def _make_implicit_object_type(self, name, info, doc, role, members, + ifcond=3DNone): if not members: return None # See also QAPISchemaObjectTypeMember._pretty_owner() name =3D 'q_obj_%s-%s' % (name, role) - if not self.lookup_entity(name, QAPISchemaObjectType): + typ =3D self.lookup_entity(name, QAPISchemaObjectType) + if typ: + # FIXME: generating the disjunction of all conditions + assert ifcond =3D=3D typ.ifcond + else: self._def_entity(QAPISchemaObjectType(name, info, doc, None, - members, None)) + members, None, ifcond)) return name =20 def _def_enum_type(self, expr, info, doc): name =3D expr['enum'] data =3D expr['data'] prefix =3D expr.get('prefix') + ifcond =3D expr.get('if') self._def_entity(QAPISchemaEnumType( - name, info, doc, self._make_enum_members(data), prefix)) + name, info, doc, self._make_enum_members(data), prefix, + ifcond)) =20 def _make_member(self, name, typ, info): optional =3D False @@ -1595,9 +1605,10 @@ class QAPISchema(object): name =3D expr['struct'] base =3D expr.get('base') data =3D expr['data'] + ifcond =3D expr.get('if') self._def_entity(QAPISchemaObjectType(name, info, doc, base, self._make_members(data, inf= o), - None)) + None, ifcond)) =20 def _make_variant(self, case, typ): return QAPISchemaObjectTypeVariant(case, typ) @@ -1606,19 +1617,23 @@ class QAPISchema(object): if isinstance(typ, list): assert len(typ) =3D=3D 1 typ =3D self._make_array_type(typ[0], info) + type_entity =3D self.lookup_type(typ) typ =3D self._make_implicit_object_type( - typ, info, None, 'wrapper', [self._make_member('data', typ, in= fo)]) + typ, info, None, 'wrapper', + [self._make_member('data', typ, info)], type_entity.ifcond) return QAPISchemaObjectTypeVariant(case, typ) =20 def _def_union_type(self, expr, info, doc): name =3D expr['union'] data =3D expr['data'] base =3D expr.get('base') + ifcond =3D expr.get('if') tag_name =3D expr.get('discriminator') tag_member =3D None if isinstance(base, dict): - base =3D (self._make_implicit_object_type( - name, info, doc, 'base', self._make_members(base, info))) + base =3D self._make_implicit_object_type( + name, info, doc, 'base', self._make_members(base, info), + ifcond) if tag_name: variants =3D [self._make_variant(key, value) for (key, value) in data.iteritems()] @@ -1627,18 +1642,21 @@ class QAPISchema(object): variants =3D [self._make_simple_variant(key, value, info) for (key, value) in data.iteritems()] typ =3D self._make_implicit_enum_type(name, info, - [v.name for v in variants]) + [v.name for v in variants], + ifcond) tag_member =3D QAPISchemaObjectTypeMember('type', typ, False) members =3D [tag_member] self._def_entity( QAPISchemaObjectType(name, info, doc, base, members, QAPISchemaObjectTypeVariants(tag_name, tag_member, - variants))) + variants), + ifcond)) =20 def _def_alternate_type(self, expr, info, doc): name =3D expr['alternate'] data =3D expr['data'] + ifcond =3D expr.get('if') variants =3D [self._make_variant(key, value) for (key, value) in data.iteritems()] tag_member =3D QAPISchemaObjectTypeMember('type', 'QType', False) @@ -1646,7 +1664,8 @@ class QAPISchema(object): QAPISchemaAlternateType(name, info, doc, QAPISchemaObjectTypeVariants(None, tag_membe= r, - variants)= )) + variants), + ifcond)) =20 def _def_command(self, expr, info, doc): name =3D expr['command'] @@ -1655,23 +1674,29 @@ class QAPISchema(object): gen =3D expr.get('gen', True) success_response =3D expr.get('success-response', True) boxed =3D expr.get('boxed', False) + ifcond =3D expr.get('if') if isinstance(data, OrderedDict): data =3D self._make_implicit_object_type( - name, info, doc, 'arg', self._make_members(data, info)) + name, info, doc, 'arg', self._make_members(data, info), + ifcond) if isinstance(rets, list): assert len(rets) =3D=3D 1 rets =3D self._make_array_type(rets[0], info) self._def_entity(QAPISchemaCommand(name, info, doc, data, rets, - gen, success_response, boxed)) + gen, success_response, boxed, + ifcond)) =20 def _def_event(self, expr, info, doc): name =3D expr['event'] data =3D expr.get('data') boxed =3D expr.get('boxed', False) + ifcond =3D expr.get('if') if isinstance(data, OrderedDict): data =3D self._make_implicit_object_type( - name, info, doc, 'arg', self._make_members(data, info)) - self._def_entity(QAPISchemaEvent(name, info, doc, data, boxed)) + name, info, doc, 'arg', self._make_members(data, info), + ifcond) + self._def_entity(QAPISchemaEvent(name, info, doc, data, boxed, + ifcond)) =20 def _def_exprs(self): for expr_elem in self.exprs: --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 1503409091394804.3326261138521; Tue, 22 Aug 2017 06:38:11 -0700 (PDT) Received: from localhost ([::1]:46917 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9Nh-0002qf-0d for importer@patchew.org; Tue, 22 Aug 2017 09:38:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54562) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9HN-0006Gz-CR for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:31:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9HL-0005dy-40 for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:31:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32984) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9HK-0005dY-Qv for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:31:35 -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 AE18C404333; Tue, 22 Aug 2017 13:24:43 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 58CFE617BE; Tue, 22 Aug 2017 13:24:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com AE18C404333 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: Tue, 22 Aug 2017 15:22:19 +0200 Message-Id: <20170822132255.23945-19-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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.38]); Tue, 22 Aug 2017 13:24:43 +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 18/54] qapi: add 'ifcond' to visitor methods 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?= , Markus Armbruster , Michael Roth 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" Modify the test visitor to check correct passing of values. Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi.py | 34 ++++++++++++++++++++----------= ---- scripts/qapi-commands.py | 2 +- scripts/qapi-event.py | 2 +- scripts/qapi-introspect.py | 12 ++++++------ scripts/qapi-types.py | 8 ++++---- scripts/qapi-visit.py | 8 ++++---- scripts/qapi2texi.py | 10 +++++----- tests/qapi-schema/qapi-schema-test.out | 9 +++++++++ tests/qapi-schema/test-qapi.py | 21 ++++++++++++++++----- 9 files changed, 66 insertions(+), 40 deletions(-) diff --git a/scripts/qapi.py b/scripts/qapi.py index dc40d74abb..86845a28f9 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -1031,26 +1031,26 @@ class QAPISchemaVisitor(object): def visit_builtin_type(self, name, info, json_type): pass =20 - def visit_enum_type(self, name, info, values, prefix): + def visit_enum_type(self, name, info, values, prefix, ifcond): pass =20 - def visit_array_type(self, name, info, element_type): + def visit_array_type(self, name, info, element_type, ifcond): pass =20 - def visit_object_type(self, name, info, base, members, variants): + def visit_object_type(self, name, info, base, members, variants, ifcon= d): pass =20 - def visit_object_type_flat(self, name, info, members, variants): + def visit_object_type_flat(self, name, info, members, variants, ifcond= ): pass =20 - def visit_alternate_type(self, name, info, variants): + def visit_alternate_type(self, name, info, variants, ifcond): pass =20 def visit_command(self, name, info, arg_type, ret_type, - gen, success_response, boxed): + gen, success_response, boxed, ifcond): pass =20 - def visit_event(self, name, info, arg_type, boxed): + def visit_event(self, name, info, arg_type, boxed, ifcond): pass =20 =20 @@ -1150,7 +1150,7 @@ class QAPISchemaEnumType(QAPISchemaType): =20 def visit(self, visitor): visitor.visit_enum_type(self.name, self.info, - self.member_names(), self.prefix) + self.member_names(), self.prefix, self.ifc= ond) =20 =20 class QAPISchemaArrayType(QAPISchemaType): @@ -1181,7 +1181,8 @@ class QAPISchemaArrayType(QAPISchemaType): return 'array of ' + elt_doc_type =20 def visit(self, visitor): - visitor.visit_array_type(self.name, self.info, self.element_type) + visitor.visit_array_type(self.name, self.info, self.element_type, + self.ifcond) =20 =20 class QAPISchemaObjectType(QAPISchemaType): @@ -1263,9 +1264,11 @@ class QAPISchemaObjectType(QAPISchemaType): =20 def visit(self, visitor): visitor.visit_object_type(self.name, self.info, - self.base, self.local_members, self.vari= ants) + self.base, self.local_members, self.vari= ants, + self.ifcond) visitor.visit_object_type_flat(self.name, self.info, - self.members, self.variants) + self.members, self.variants, + self.ifcond) =20 =20 class QAPISchemaMember(object): @@ -1408,7 +1411,8 @@ class QAPISchemaAlternateType(QAPISchemaType): return 'value' =20 def visit(self, visitor): - visitor.visit_alternate_type(self.name, self.info, self.variants) + visitor.visit_alternate_type(self.name, self.info, + self.variants, self.ifcond) =20 def is_empty(self): return False @@ -1450,7 +1454,8 @@ class QAPISchemaCommand(QAPISchemaEntity): def visit(self, visitor): visitor.visit_command(self.name, self.info, self.arg_type, self.ret_type, - self.gen, self.success_response, self.boxed) + self.gen, self.success_response, self.boxed, + self.ifcond) =20 =20 class QAPISchemaEvent(QAPISchemaEntity): @@ -1478,7 +1483,8 @@ class QAPISchemaEvent(QAPISchemaEntity): raise QAPISemError(self.info, "Use of 'boxed' requires 'data'") =20 def visit(self, visitor): - visitor.visit_event(self.name, self.info, self.arg_type, self.boxe= d) + visitor.visit_event(self.name, self.info, self.arg_type, self.boxe= d, + self.ifcond) =20 =20 class QAPISchema(object): diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py index 974d0a4a80..5eb96b2d95 100644 --- a/scripts/qapi-commands.py +++ b/scripts/qapi-commands.py @@ -241,7 +241,7 @@ class QAPISchemaGenCommandVisitor(QAPISchemaVisitor): self._visited_ret_types =3D None =20 def visit_command(self, name, info, arg_type, ret_type, - gen, success_response, boxed): + gen, success_response, boxed, ifcond): if not gen: return self.decl +=3D gen_command_decl(name, arg_type, boxed, ret_type) diff --git a/scripts/qapi-event.py b/scripts/qapi-event.py index bcbef1035f..fec27fe2e1 100644 --- a/scripts/qapi-event.py +++ b/scripts/qapi-event.py @@ -163,7 +163,7 @@ class QAPISchemaGenEventVisitor(QAPISchemaVisitor): self.defn +=3D gen_enum_lookup(event_enum_name, self._event_names) self._event_names =3D None =20 - def visit_event(self, name, info, arg_type, boxed): + def visit_event(self, name, info, arg_type, boxed, ifcond): self.decl +=3D gen_event_send_decl(name, arg_type, boxed) self.defn +=3D gen_event_send(name, arg_type, boxed) self._event_names.append(name) diff --git a/scripts/qapi-introspect.py b/scripts/qapi-introspect.py index 1b96926fa7..4c437d60ec 100644 --- a/scripts/qapi-introspect.py +++ b/scripts/qapi-introspect.py @@ -142,34 +142,34 @@ const QLitObject %(c_name)s =3D %(c_string)s; def visit_builtin_type(self, name, info, json_type): self._gen_qlit(name, 'builtin', {'json-type': json_type}) =20 - def visit_enum_type(self, name, info, values, prefix): + def visit_enum_type(self, name, info, values, prefix, ifcond): self._gen_qlit(name, 'enum', {'values': values}) =20 - def visit_array_type(self, name, info, element_type): + def visit_array_type(self, name, info, element_type, ifcond): element =3D self._use_type(element_type) self._gen_qlit('[' + element + ']', 'array', {'element-type': elem= ent}) =20 - def visit_object_type_flat(self, name, info, members, variants): + def visit_object_type_flat(self, name, info, members, variants, ifcond= ): 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_qlit(name, 'object', obj) =20 - def visit_alternate_type(self, name, info, variants): + def visit_alternate_type(self, name, info, variants, ifcond): self._gen_qlit(name, 'alternate', {'members': [{'type': self._use_type(m.type)} for m in variants.variants]}) =20 def visit_command(self, name, info, arg_type, ret_type, - gen, success_response, boxed): + gen, success_response, boxed, ifcond): 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_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): + def visit_event(self, name, info, arg_type, boxed, ifcond): arg_type =3D arg_type or self._schema.the_empty_object_type self._gen_qlit(name, 'event', {'arg-type': self._use_type(arg_type= )}) =20 diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index dc05268917..6f06720adc 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -201,7 +201,7 @@ typedef struct QEnumLookup { self.decl +=3D gen_type_cleanup_decl(name) self.defn +=3D gen_type_cleanup(name) =20 - def visit_enum_type(self, name, info, values, prefix): + def visit_enum_type(self, name, info, values, prefix, ifcond): # Special case for our lone builtin enum type # TODO use something cleaner than existence of info if not info: @@ -212,7 +212,7 @@ typedef struct QEnumLookup { self._fwdecl +=3D gen_enum(name, values, prefix) self.defn +=3D gen_enum_lookup(name, values, prefix) =20 - def visit_array_type(self, name, info, element_type): + def visit_array_type(self, name, info, element_type, ifcond): if isinstance(element_type, QAPISchemaBuiltinType): self._btin +=3D gen_fwd_object_or_array(name) self._btin +=3D gen_array(name, element_type) @@ -224,7 +224,7 @@ typedef struct QEnumLookup { self.decl +=3D gen_array(name, element_type) self._gen_type_cleanup(name) =20 - def visit_object_type(self, name, info, base, members, variants): + def visit_object_type(self, name, info, base, members, variants, ifcon= d): # Nothing to do for the special empty builtin if name =3D=3D 'q_empty': return @@ -238,7 +238,7 @@ typedef struct QEnumLookup { # implicit types won't be directly allocated/freed self._gen_type_cleanup(name) =20 - def visit_alternate_type(self, name, info, variants): + def visit_alternate_type(self, name, info, variants, ifcond): self._fwdecl +=3D gen_fwd_object_or_array(name) self.decl +=3D gen_object(name, None, [variants.tag_member], varia= nts) self._gen_type_cleanup(name) diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py index 7e1cfc13f0..c29c2d869e 100644 --- a/scripts/qapi-visit.py +++ b/scripts/qapi-visit.py @@ -282,7 +282,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor): self.decl =3D self._btin + self.decl self._btin =3D None =20 - def visit_enum_type(self, name, info, values, prefix): + def visit_enum_type(self, name, info, values, prefix, ifcond): # Special case for our lone builtin enum type # TODO use something cleaner than existence of info if not info: @@ -293,7 +293,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor): self.decl +=3D gen_visit_decl(name, scalar=3DTrue) self.defn +=3D gen_visit_enum(name) =20 - def visit_array_type(self, name, info, element_type): + def visit_array_type(self, name, info, element_type, ifcond): decl =3D gen_visit_decl(name) defn =3D gen_visit_list(name, element_type) if isinstance(element_type, QAPISchemaBuiltinType): @@ -304,7 +304,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor): self.decl +=3D decl self.defn +=3D defn =20 - def visit_object_type(self, name, info, base, members, variants): + def visit_object_type(self, name, info, base, members, variants, ifcon= d): # Nothing to do for the special empty builtin if name =3D=3D 'q_empty': return @@ -317,7 +317,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor): self.decl +=3D gen_visit_decl(name) self.defn +=3D gen_visit_object(name, base, members, variants) =20 - def visit_alternate_type(self, name, info, variants): + def visit_alternate_type(self, name, info, variants, ifcond): self.decl +=3D gen_visit_decl(name) self.defn +=3D gen_visit_alternate(name, variants) =20 diff --git a/scripts/qapi2texi.py b/scripts/qapi2texi.py index 8b542f9fff..ae7920aa87 100755 --- a/scripts/qapi2texi.py +++ b/scripts/qapi2texi.py @@ -207,7 +207,7 @@ class QAPISchemaGenDocVisitor(qapi.QAPISchemaVisitor): def visit_begin(self, schema): self.out =3D '' =20 - def visit_enum_type(self, name, info, values, prefix): + def visit_enum_type(self, name, info, values, prefix, ifcond): doc =3D self.cur_doc if self.out: self.out +=3D '\n' @@ -216,7 +216,7 @@ class QAPISchemaGenDocVisitor(qapi.QAPISchemaVisitor): body=3Dtexi_entity(doc, 'Values', member_func=3Dtexi_enum_valu= e)) =20 - def visit_object_type(self, name, info, base, members, variants): + def visit_object_type(self, name, info, base, members, variants, ifcon= d): doc =3D self.cur_doc if base and base.is_implicit(): base =3D None @@ -226,7 +226,7 @@ class QAPISchemaGenDocVisitor(qapi.QAPISchemaVisitor): name=3Ddoc.symbol, body=3Dtexi_entity(doc, 'Members', base, vari= ants)) =20 - def visit_alternate_type(self, name, info, variants): + def visit_alternate_type(self, name, info, variants, ifcond): doc =3D self.cur_doc if self.out: self.out +=3D '\n' @@ -235,7 +235,7 @@ class QAPISchemaGenDocVisitor(qapi.QAPISchemaVisitor): body=3Dtexi_entity(doc, 'Members')) =20 def visit_command(self, name, info, arg_type, ret_type, - gen, success_response, boxed): + gen, success_response, boxed, ifcond): doc =3D self.cur_doc if self.out: self.out +=3D '\n' @@ -249,7 +249,7 @@ class QAPISchemaGenDocVisitor(qapi.QAPISchemaVisitor): name=3Ddoc.symbol, body=3Dbody) =20 - def visit_event(self, name, info, arg_type, boxed): + def visit_event(self, name, info, arg_type, boxed, ifcond): doc =3D self.cur_doc if self.out: self.out +=3D '\n' diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index 7fbaea19bc..fc5fd25f1b 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -56,18 +56,25 @@ alternate TestIfAlternate tag type case foo: int case bar: TestStruct + if defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT) command TestIfCmd q_obj_TestIfCmd-arg -> None gen=3DTrue success_response=3DTrue boxed=3DFalse + if defined(TEST_IF_CMD) && defined(TEST_IF_STRUCT) enum TestIfEnum ['foo', 'bar'] + if defined(TEST_IF_ENUM) event TestIfEvent q_obj_TestIfEvent-arg boxed=3DFalse + if defined(TEST_IF_EVT) && defined(TEST_IF_STRUCT) object TestIfStruct member foo: int optional=3DFalse + if defined(TEST_IF_STRUCT) object TestIfUnion member type: TestIfUnionKind optional=3DFalse tag type case foo: q_obj_TestStruct-wrapper + if defined(TEST_IF_UNION) && defined(TEST_IF_STRUCT) enum TestIfUnionKind ['foo'] + if defined(TEST_IF_UNION) && defined(TEST_IF_STRUCT) object TestStruct member integer: int optional=3DFalse member boolean: bool optional=3DFalse @@ -190,8 +197,10 @@ object q_obj_EVENT_D-arg member enum3: EnumOne optional=3DTrue object q_obj_TestIfCmd-arg member foo: TestIfStruct optional=3DFalse + if defined(TEST_IF_CMD) && defined(TEST_IF_STRUCT) object q_obj_TestIfEvent-arg member foo: TestIfStruct optional=3DFalse + if defined(TEST_IF_EVT) && defined(TEST_IF_STRUCT) object q_obj_TestStruct-wrapper member data: TestStruct optional=3DFalse object q_obj_UserDefFlatUnion2-base diff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi.py index c7724d3437..17fd975812 100644 --- a/tests/qapi-schema/test-qapi.py +++ b/tests/qapi-schema/test-qapi.py @@ -17,12 +17,13 @@ import sys =20 =20 class QAPISchemaTestVisitor(QAPISchemaVisitor): - def visit_enum_type(self, name, info, values, prefix): + def visit_enum_type(self, name, info, values, prefix, ifcond): print 'enum %s %s' % (name, values) if prefix: print ' prefix %s' % prefix + self._print_if(ifcond) =20 - def visit_object_type(self, name, info, base, members, variants): + def visit_object_type(self, name, info, base, members, variants, ifcon= d): print 'object %s' % name if base: print ' base %s' % base.name @@ -30,21 +31,25 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): print ' member %s: %s optional=3D%s' % \ (m.name, m.type.name, m.optional) self._print_variants(variants) + self._print_if(ifcond) =20 - def visit_alternate_type(self, name, info, variants): + def visit_alternate_type(self, name, info, variants, ifcond): print 'alternate %s' % name self._print_variants(variants) + self._print_if(ifcond) =20 def visit_command(self, name, info, arg_type, ret_type, - gen, success_response, boxed): + gen, success_response, boxed, ifcond): print 'command %s %s -> %s' % \ (name, arg_type and arg_type.name, ret_type and ret_type.name) print ' gen=3D%s success_response=3D%s boxed=3D%s' % \ (gen, success_response, boxed) + self._print_if(ifcond) =20 - def visit_event(self, name, info, arg_type, boxed): + def visit_event(self, name, info, arg_type, boxed, ifcond): print 'event %s %s' % (name, arg_type and arg_type.name) print ' boxed=3D%s' % boxed + self._print_if(ifcond) =20 @staticmethod def _print_variants(variants): @@ -53,6 +58,12 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): for v in variants.variants: print ' case %s: %s' % (v.name, v.type.name) =20 + @staticmethod + def _print_if(ifcond): + if ifcond: + print ' if %s' % ifcond + + schema =3D QAPISchema(sys.argv[1]) schema.visit(QAPISchemaTestVisitor()) =20 --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 1503410454333306.7732497557547; Tue, 22 Aug 2017 07:00:54 -0700 (PDT) Received: from localhost ([::1]:47254 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9jh-00069l-4B for importer@patchew.org; Tue, 22 Aug 2017 10:00:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55186) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9JL-000825-C6 for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9JI-0006xN-38 for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58302) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9JH-0006wk-SP for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:36 -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 CBA0DC0467DC; Tue, 22 Aug 2017 13:24:45 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id DE3807E22E; Tue, 22 Aug 2017 13:24:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CBA0DC0467DC 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: Tue, 22 Aug 2017 15:22:20 +0200 Message-Id: <20170822132255.23945-20-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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.31]); Tue, 22 Aug 2017 13:24:45 +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 19/54] qapi: add #if/#endif helpers 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?= , Markus Armbruster , Michael Roth 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" Add helpers to generate #if/#endif and wrap visitor methods generating code. Used in the following patches. Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/scripts/qapi.py b/scripts/qapi.py index 86845a28f9..52099332f1 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -1892,6 +1892,57 @@ def guardend(name): name=3Dguardname(name)) =20 =20 +def gen_if(ifcond): + if not ifcond: + return '' + if isinstance(ifcond, str): + ifcond =3D [ifcond] + # Not using mcgen() because we don't want indent or \n stipped + ret =3D '\n' + for ifc in ifcond: + ret +=3D '#if %s\n' % ifc + ret +=3D '\n' + return ret + + +def gen_endif(ifcond): + if not ifcond: + return '' + if isinstance(ifcond, str): + ifcond =3D [ifcond] + # Not using mcgen() because we don't want indent or \n stipped + ret =3D '\n' + for ifc in reversed(ifcond): + ret +=3D '#endif /* %s */\n' % ifc + ret +=3D '\n' + return ret + + +# Wrap a method to add #if / #endif to generated code, only if some +# code was generated. +# self must have 'if_members' listing the attributes to wrap. +# The last argument of the wrapped function must be the 'ifcond'. +def ifcond_decorator(func): + + def func_wrapper(self, *args, **kwargs): + ifcond =3D args[-1] + save =3D {} + for mem in self.if_members: + save[mem] =3D getattr(self, mem) + func(self, *args, **kwargs) + for mem, val in save.items(): + newval =3D getattr(self, mem) + if newval !=3D val: + assert newval.startswith(val) + newval =3D newval[len(val):] + val +=3D gen_if(ifcond) + val +=3D newval + val +=3D gen_endif(ifcond) + setattr(self, mem, val) + + return func_wrapper + + def gen_enum_lookup(name, values, prefix=3DNone): ret =3D mcgen(''' =20 --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 150341018009683.28216816444433; Tue, 22 Aug 2017 06:56:20 -0700 (PDT) Received: from localhost ([::1]:47194 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9fG-0002D5-Pj for importer@patchew.org; Tue, 22 Aug 2017 09:56:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54598) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9HQ-0006JG-0m for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:31:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9HK-0005d4-2N for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:31:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55026) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9HJ-0005cQ-S0 for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:31:33 -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 05B864A6F0; Tue, 22 Aug 2017 13:24:48 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 424457E648; Tue, 22 Aug 2017 13:24:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 05B864A6F0 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: Tue, 22 Aug 2017 15:22:21 +0200 Message-Id: <20170822132255.23945-21-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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]); Tue, 22 Aug 2017 13:24:48 +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 20/54] qapi-introspect: modify to_qlit() to take an optional suffix 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?= , Markus Armbruster , Michael Roth 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" The following patch is going to break list entries with #if/#endif, so they should have the trailing ',' as suffix. Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi-introspect.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/qapi-introspect.py b/scripts/qapi-introspect.py index 4c437d60ec..dfb6d2ded4 100644 --- a/scripts/qapi-introspect.py +++ b/scripts/qapi-introspect.py @@ -16,7 +16,7 @@ def to_c_string(s): return '"' + s.replace('\\', r'\\').replace('"', r'\"') + '"' =20 =20 -def to_qlit(obj, level=3D0, first_indent=3DTrue): +def to_qlit(obj, level=3D0, first_indent=3DTrue, suffix=3D''): =20 def indent(level): return level * 4 * ' ' @@ -29,11 +29,11 @@ def to_qlit(obj, level=3D0, first_indent=3DTrue): elif isinstance(obj, str): ret +=3D 'QLIT_QSTR(' + to_c_string(obj) + ')' elif isinstance(obj, list): - elts =3D [to_qlit(elt, level + 1) + elts =3D [to_qlit(elt, level + 1, suffix=3D',') for elt in obj] elts.append(indent(level + 1) + "{}") ret +=3D 'QLIT_QLIST(((QLitObject[]) {\n' - ret +=3D ',\n'.join(elts) + '\n' + ret +=3D '\n'.join(elts) + '\n' ret +=3D indent(level) + '}))' elif isinstance(obj, dict): elts =3D [] @@ -46,7 +46,7 @@ def to_qlit(obj, level=3D0, first_indent=3DTrue): ret +=3D indent(level) + '}))' else: assert False # not implemented - return ret + return ret + suffix =20 =20 class QAPISchemaGenIntrospectVisitor(QAPISchemaVisitor): --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 1503410350269284.2438920592999; Tue, 22 Aug 2017 06:59:10 -0700 (PDT) Received: from localhost ([::1]:47237 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9i0-0004Zf-Re for importer@patchew.org; Tue, 22 Aug 2017 09:59:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54744) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9Hk-0006ba-SP for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:32:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9Hk-000642-49 for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:32:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33396) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9Hj-00063O-TX for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:32:00 -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 DAE576148B; Tue, 22 Aug 2017 13:24:49 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3EFF8617BB; Tue, 22 Aug 2017 13:24:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com DAE576148B 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: Tue, 22 Aug 2017 15:22:22 +0200 Message-Id: <20170822132255.23945-22-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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.39]); Tue, 22 Aug 2017 13:24:50 +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 21/54] qapi-introspect: modify to_qlit() to generate #if code 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?= , Markus Armbruster , Michael Roth 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" The generator now accepts (obj, condition) tuples to wrap generated QLit objects with #if/#endif conditions. Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi-introspect.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/qapi-introspect.py b/scripts/qapi-introspect.py index dfb6d2ded4..9ef6f271d4 100644 --- a/scripts/qapi-introspect.py +++ b/scripts/qapi-introspect.py @@ -26,6 +26,12 @@ def to_qlit(obj, level=3D0, first_indent=3DTrue, suffix= =3D''): ret +=3D indent(level) if obj is None: ret +=3D 'QLIT_QNULL' + elif isinstance(obj, tuple): + obj, ifcond =3D obj + ret +=3D gen_if(ifcond) + ret +=3D to_qlit(obj, level, first_indent=3DFalse) + suffix + ret +=3D gen_endif(ifcond) + suffix =3D '' elif isinstance(obj, str): ret +=3D 'QLIT_QSTR(' + to_c_string(obj) + ')' elif isinstance(obj, list): --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 1503410395158937.7400998604302; Tue, 22 Aug 2017 06:59:55 -0700 (PDT) Received: from localhost ([::1]:47245 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9ij-0005GO-TD for importer@patchew.org; Tue, 22 Aug 2017 09:59:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55329) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9JW-0008AK-2B for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9JQ-00074a-4Y for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38642) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9JP-00073P-Rs for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:44 -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 B96D27DD05; Tue, 22 Aug 2017 13:24:51 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 491BA617BB; Tue, 22 Aug 2017 13:24:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B96D27DD05 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: Tue, 22 Aug 2017 15:22:23 +0200 Message-Id: <20170822132255.23945-23-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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.26]); Tue, 22 Aug 2017 13:24:51 +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 22/54] qapi-introspect: add preprocessor conditions to generated 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?= , Markus Armbruster , Michael Roth 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" Add 'ifcond' condition to QLit objects. to_qlit() handles the (obj, ifcond) tuples. Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi-introspect.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/scripts/qapi-introspect.py b/scripts/qapi-introspect.py index 9ef6f271d4..5e736a06df 100644 --- a/scripts/qapi-introspect.py +++ b/scripts/qapi-introspect.py @@ -125,12 +125,12 @@ const QLitObject %(c_name)s =3D %(c_string)s; return '[' + self._use_type(typ.element_type) + ']' return self._name(typ.name) =20 - def _gen_qlit(self, name, mtype, obj): + def _gen_qlit(self, name, mtype, obj, ifcond): if mtype not in ('command', 'event', 'builtin', 'array'): name =3D self._name(name) obj['name'] =3D name obj['meta-type'] =3D mtype - self._qlits.append(obj) + self._qlits.append((obj, ifcond)) =20 def _gen_member(self, member): ret =3D {'name': member.name, 'type': self._use_type(member.type)} @@ -146,26 +146,27 @@ const QLitObject %(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_qlit(name, 'builtin', {'json-type': json_type}) + self._gen_qlit(name, 'builtin', {'json-type': json_type}, None) =20 def visit_enum_type(self, name, info, values, prefix, ifcond): - self._gen_qlit(name, 'enum', {'values': values}) + self._gen_qlit(name, 'enum', {'values': values}, ifcond) =20 def visit_array_type(self, name, info, element_type, ifcond): element =3D self._use_type(element_type) - self._gen_qlit('[' + element + ']', 'array', {'element-type': elem= ent}) + self._gen_qlit('[' + element + ']', 'array', {'element-type': elem= ent}, + ifcond) =20 def visit_object_type_flat(self, name, info, members, variants, ifcond= ): 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_qlit(name, 'object', obj) + self._gen_qlit(name, 'object', obj, ifcond) =20 def visit_alternate_type(self, name, info, variants, ifcond): self._gen_qlit(name, 'alternate', {'members': [{'type': self._use_type(m.type)} - for m in variants.variants]}) + for m in variants.variants]}, ifcond) =20 def visit_command(self, name, info, arg_type, ret_type, gen, success_response, boxed, ifcond): @@ -173,11 +174,12 @@ const QLitObject %(c_name)s =3D %(c_string)s; ret_type =3D ret_type or self._schema.the_empty_object_type self._gen_qlit(name, 'command', {'arg-type': self._use_type(arg_type), - 'ret-type': self._use_type(ret_type)}) + 'ret-type': self._use_type(ret_type)}, ifcond) =20 def visit_event(self, name, info, arg_type, boxed, ifcond): arg_type =3D arg_type or self._schema.the_empty_object_type - self._gen_qlit(name, 'event', {'arg-type': self._use_type(arg_type= )}) + self._gen_qlit(name, 'event', {'arg-type': self._use_type(arg_type= )}, + ifcond) =20 # Debugging aid: unmask QAPI schema's type names # We normally mask them, because they're not QMP wire ABI --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 1503411170242548.588673368683; Tue, 22 Aug 2017 07:12:50 -0700 (PDT) Received: from localhost ([::1]:47364 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9vE-0007KF-K7 for importer@patchew.org; Tue, 22 Aug 2017 10:12:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55508) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9Ju-000087-JI for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:34:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9Jp-0007MZ-25 for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:34:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60052) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9Jo-0007ME-Sg for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:34:08 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 661ACC056870; Tue, 22 Aug 2017 13:24:58 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 34AE7183F6; Tue, 22 Aug 2017 13:24:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 661ACC056870 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: Tue, 22 Aug 2017 15:22:24 +0200 Message-Id: <20170822132255.23945-24-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 22 Aug 2017 13:24:58 +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 23/54] qapi-commands: add #if conditions to commands 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?= , Markus Armbruster , Michael Roth 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" Wrap generated code with #if/#endif using the ifcond_decorator. Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi-commands.py | 2 ++ tests/test-qmp-commands.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py index 5eb96b2d95..db45415c41 100644 --- a/scripts/qapi-commands.py +++ b/scripts/qapi-commands.py @@ -228,6 +228,7 @@ class QAPISchemaGenCommandVisitor(QAPISchemaVisitor): self.defn =3D None self._regy =3D None self._visited_ret_types =3D None + self.if_members =3D ['decl', 'defn', '_regy'] =20 def visit_begin(self, schema): self.decl =3D '' @@ -240,6 +241,7 @@ class QAPISchemaGenCommandVisitor(QAPISchemaVisitor): self._regy =3D None self._visited_ret_types =3D None =20 + @ifcond_decorator def visit_command(self, name, info, arg_type, ret_type, gen, success_response, boxed, ifcond): if not gen: diff --git a/tests/test-qmp-commands.c b/tests/test-qmp-commands.c index 9b9a7ffee7..ad7b6e4e1d 100644 --- a/tests/test-qmp-commands.c +++ b/tests/test-qmp-commands.c @@ -10,11 +10,11 @@ =20 static QmpCommandList qmp_commands; =20 -/* #if defined(TEST_IF_CMD) */ +#if defined(TEST_IF_CMD) void qmp_TestIfCmd(TestIfStruct *foo, Error **errp) { } -/* #endif */ +#endif =20 void qmp_user_def_cmd(Error **errp) { --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 1503409576129507.1061757342303; Tue, 22 Aug 2017 06:46:16 -0700 (PDT) Received: from localhost ([::1]:47112 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9VW-0001lv-QB for importer@patchew.org; Tue, 22 Aug 2017 09:46:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54706) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9He-0006Vg-Rk for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:31:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9HZ-0005wM-2f for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:31:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53940) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9HY-0005w5-Sf for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:31:49 -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 C99EA7EA93; Tue, 22 Aug 2017 13:25:05 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9721C7E58D; Tue, 22 Aug 2017 13:24:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C99EA7EA93 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: Tue, 22 Aug 2017 15:22:25 +0200 Message-Id: <20170822132255.23945-25-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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.28]); Tue, 22 Aug 2017 13:25:05 +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 24/54] qapi-event: add #if conditions to events 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?= , Markus Armbruster , Michael Roth 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" Wrap generated code with #if/#endif using the ifcond_decorator. Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi-event.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/qapi-event.py b/scripts/qapi-event.py index fec27fe2e1..f21ecd39f3 100644 --- a/scripts/qapi-event.py +++ b/scripts/qapi-event.py @@ -152,6 +152,7 @@ class QAPISchemaGenEventVisitor(QAPISchemaVisitor): self.decl =3D None self.defn =3D None self._event_names =3D None + self.if_members =3D ['decl', 'defn'] =20 def visit_begin(self, schema): self.decl =3D '' @@ -163,6 +164,7 @@ class QAPISchemaGenEventVisitor(QAPISchemaVisitor): self.defn +=3D gen_enum_lookup(event_enum_name, self._event_names) self._event_names =3D None =20 + @ifcond_decorator def visit_event(self, name, info, arg_type, boxed, ifcond): self.decl +=3D gen_event_send_decl(name, arg_type, boxed) self.defn +=3D gen_event_send(name, arg_type, boxed) --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 1503411209125280.0788674280341; Tue, 22 Aug 2017 07:13:29 -0700 (PDT) Received: from localhost ([::1]:47366 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9vr-0007s0-U9 for importer@patchew.org; Tue, 22 Aug 2017 10:13:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55245) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9JQ-00084P-1j for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9JP-000739-3u for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38466) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9JO-00072J-Th for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:43 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AB4327CB8A; Tue, 22 Aug 2017 13:25:08 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7A2EC6F996; Tue, 22 Aug 2017 13:25:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com AB4327CB8A 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: Tue, 22 Aug 2017 15:22:26 +0200 Message-Id: <20170822132255.23945-26-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 22 Aug 2017 13:25:08 +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 25/54] qapi-visit: add #if conditions to visitors 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?= , Markus Armbruster , Michael Roth 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" Wrap generated code with #if/#endif using the ifcond_decorator. Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi-visit.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py index c29c2d869e..bb18c9edee 100644 --- a/scripts/qapi-visit.py +++ b/scripts/qapi-visit.py @@ -267,6 +267,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor): self.decl =3D None self.defn =3D None self._btin =3D None + self.if_members =3D ['decl', 'defn', '_btin'] =20 def visit_begin(self, schema): self.decl =3D '' @@ -282,6 +283,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor): self.decl =3D self._btin + self.decl self._btin =3D None =20 + @ifcond_decorator def visit_enum_type(self, name, info, values, prefix, ifcond): # Special case for our lone builtin enum type # TODO use something cleaner than existence of info @@ -293,6 +295,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor): self.decl +=3D gen_visit_decl(name, scalar=3DTrue) self.defn +=3D gen_visit_enum(name) =20 + @ifcond_decorator def visit_array_type(self, name, info, element_type, ifcond): decl =3D gen_visit_decl(name) defn =3D gen_visit_list(name, element_type) @@ -304,6 +307,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor): self.decl +=3D decl self.defn +=3D defn =20 + @ifcond_decorator def visit_object_type(self, name, info, base, members, variants, ifcon= d): # Nothing to do for the special empty builtin if name =3D=3D 'q_empty': @@ -317,6 +321,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor): self.decl +=3D gen_visit_decl(name) self.defn +=3D gen_visit_object(name, base, members, variants) =20 + @ifcond_decorator def visit_alternate_type(self, name, info, variants, ifcond): self.decl +=3D gen_visit_decl(name) self.defn +=3D gen_visit_alternate(name, variants) --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 150340961686627.34017073969585; Tue, 22 Aug 2017 06:46:56 -0700 (PDT) Received: from localhost ([::1]:47113 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9WB-0002Gp-JI for importer@patchew.org; Tue, 22 Aug 2017 09:46:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54461) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9H3-0005xj-0i for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:31:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9Gz-0005KM-49 for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:31:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37992) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9Gy-0005K4-S5 for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:31:13 -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 266087E449; Tue, 22 Aug 2017 13:25:15 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3599083D8B; Tue, 22 Aug 2017 13:25:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 266087E449 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: Tue, 22 Aug 2017 15:22:27 +0200 Message-Id: <20170822132255.23945-27-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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.27]); Tue, 22 Aug 2017 13:25:15 +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 26/54] qapi-types: refactor variants handling 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?= , Markus Armbruster , Michael Roth 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" Generate variants objects outside gen_object(). This will allow to easily wrap gen_object() with ifcond_decorator in the following patch. Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi-types.py | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index 6f06720adc..05b0eee482 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -53,19 +53,23 @@ def gen_struct_members(members): return ret =20 =20 -def gen_object(name, base, members, variants): - if name in objects_seen: - return '' - objects_seen.add(name) - +def gen_variants_objects(variants): ret =3D '' if variants: for v in variants.variants: if isinstance(v.type, QAPISchemaObjectType): + ret +=3D gen_variants_objects(v.type.variants) ret +=3D gen_object(v.type.name, v.type.base, v.type.local_members, v.type.variants) + return ret =20 - ret +=3D mcgen(''' + +def gen_object(name, base, members, variants): + if name in objects_seen: + return '' + objects_seen.add(name) + + ret =3D mcgen(''' =20 struct %(c_name)s { ''', @@ -224,11 +228,7 @@ typedef struct QEnumLookup { self.decl +=3D gen_array(name, element_type) self._gen_type_cleanup(name) =20 - def visit_object_type(self, name, info, base, members, variants, ifcon= d): - # Nothing to do for the special empty builtin - if name =3D=3D 'q_empty': - return - self._fwdecl +=3D gen_fwd_object_or_array(name) + def _gen_object(self, name, info, base, members, variants): self.decl +=3D gen_object(name, base, members, variants) if base and not base.is_implicit(): self.decl +=3D gen_upcast(name, base) @@ -238,10 +238,18 @@ typedef struct QEnumLookup { # implicit types won't be directly allocated/freed self._gen_type_cleanup(name) =20 + def visit_object_type(self, name, info, base, members, variants, ifcon= d): + # Nothing to do for the special empty builtin + if name =3D=3D 'q_empty': + return + self._fwdecl +=3D gen_fwd_object_or_array(name) + self.decl +=3D gen_variants_objects(variants) + self._gen_object(name, info, base, members, variants) + def visit_alternate_type(self, name, info, variants, ifcond): self._fwdecl +=3D gen_fwd_object_or_array(name) - self.decl +=3D gen_object(name, None, [variants.tag_member], varia= nts) - self._gen_type_cleanup(name) + self.decl +=3D gen_variants_objects(variants) + self._gen_object(name, info, None, [variants.tag_member], variants) =20 # If you link code generated from multiple schemata, you want only one # instance of the code for built-in types. Generate it only when --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 1503410981623517.7905165450259; Tue, 22 Aug 2017 07:09:41 -0700 (PDT) Received: from localhost ([::1]:47337 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9sC-0004nV-8t for importer@patchew.org; Tue, 22 Aug 2017 10:09:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55494) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9Jt-00006N-2W for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:34:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9Jp-0007N1-59 for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:34:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60046) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9Jo-0007MB-Ra for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:34:09 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 87BF1C05678D; Tue, 22 Aug 2017 13:25:21 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9FDB21822A; Tue, 22 Aug 2017 13:25:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 87BF1C05678D 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: Tue, 22 Aug 2017 15:22:28 +0200 Message-Id: <20170822132255.23945-28-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 22 Aug 2017 13:25:21 +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 27/54] qapi-types: add #if conditions to types 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?= , Markus Armbruster , Michael Roth 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" Wrap generated code with #if/#endif using the ifcond_decorator. Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi-types.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index 05b0eee482..c1316312ac 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -175,6 +175,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor): self.defn =3D None self._fwdecl =3D None self._btin =3D None + self.if_members =3D ['decl', 'defn', '_fwdecl', '_btin'] =20 def visit_begin(self, schema): # gen_object() is recursive, ensure it doesn't visit the empty type @@ -201,10 +202,12 @@ typedef struct QEnumLookup { self.decl =3D self._btin + self.decl self._btin =3D None =20 - def _gen_type_cleanup(self, name): + @ifcond_decorator + def _gen_type_cleanup(self, name, ifcond): self.decl +=3D gen_type_cleanup_decl(name) self.defn +=3D gen_type_cleanup(name) =20 + @ifcond_decorator def visit_enum_type(self, name, info, values, prefix, ifcond): # Special case for our lone builtin enum type # TODO use something cleaner than existence of info @@ -216,6 +219,7 @@ typedef struct QEnumLookup { self._fwdecl +=3D gen_enum(name, values, prefix) self.defn +=3D gen_enum_lookup(name, values, prefix) =20 + @ifcond_decorator def visit_array_type(self, name, info, element_type, ifcond): if isinstance(element_type, QAPISchemaBuiltinType): self._btin +=3D gen_fwd_object_or_array(name) @@ -226,9 +230,10 @@ typedef struct QEnumLookup { else: self._fwdecl +=3D gen_fwd_object_or_array(name) self.decl +=3D gen_array(name, element_type) - self._gen_type_cleanup(name) + self._gen_type_cleanup(name, ifcond) =20 - def _gen_object(self, name, info, base, members, variants): + @ifcond_decorator + def _gen_object(self, name, info, base, members, variants, ifcond): self.decl +=3D gen_object(name, base, members, variants) if base and not base.is_implicit(): self.decl +=3D gen_upcast(name, base) @@ -236,7 +241,7 @@ typedef struct QEnumLookup { # directly use rather than repeat type.is_implicit()? if not name.startswith('q_'): # implicit types won't be directly allocated/freed - self._gen_type_cleanup(name) + self._gen_type_cleanup(name, ifcond) =20 def visit_object_type(self, name, info, base, members, variants, ifcon= d): # Nothing to do for the special empty builtin @@ -244,12 +249,13 @@ typedef struct QEnumLookup { return self._fwdecl +=3D gen_fwd_object_or_array(name) self.decl +=3D gen_variants_objects(variants) - self._gen_object(name, info, base, members, variants) + self._gen_object(name, info, base, members, variants, ifcond) =20 def visit_alternate_type(self, name, info, variants, ifcond): self._fwdecl +=3D gen_fwd_object_or_array(name) self.decl +=3D gen_variants_objects(variants) - self._gen_object(name, info, None, [variants.tag_member], variants) + self._gen_object(name, info, None, [variants.tag_member], + variants, ifcond) =20 # If you link code generated from multiple schemata, you want only one # instance of the code for built-in types. Generate it only when --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 1503408902462734.8115364116751; Tue, 22 Aug 2017 06:35:02 -0700 (PDT) Received: from localhost ([::1]:46716 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9Kf-0000Ix-4t for importer@patchew.org; Tue, 22 Aug 2017 09:35:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54560) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9HN-0006Gw-AQ for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:31:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9HK-0005dD-2X for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:31:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55040) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9HJ-0005cT-S8 for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:31:33 -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 E0A0061992; Tue, 22 Aug 2017 13:25:27 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0B9C182313; Tue, 22 Aug 2017 13:25:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E0A0061992 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: Tue, 22 Aug 2017 15:22:29 +0200 Message-Id: <20170822132255.23945-29-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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.38]); Tue, 22 Aug 2017 13:25:28 +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 28/54] qapi: do not define enumeration value explicitely 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?= , Markus Armbruster , Michael Roth 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" The C standard has the initial value at 0 and the subsequent values incremented by 1. No need to set this explicitely. This will prevent from artificial "gaps" when compiling out some enum values and having unnecessarily large MAX values & enums arrays. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- scripts/qapi.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/scripts/qapi.py b/scripts/qapi.py index 52099332f1..9d075440d3 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -1979,14 +1979,11 @@ typedef enum %(c_name)s { ''', c_name=3Dc_name(name)) =20 - i =3D 0 for value in enum_values: ret +=3D mcgen(''' - %(c_enum)s =3D %(i)d, + %(c_enum)s, ''', - c_enum=3Dc_enum_const(name, value, prefix), - i=3Di) - i +=3D 1 + c_enum=3Dc_enum_const(name, value, prefix)) =20 ret +=3D mcgen(''' } %(c_name)s; --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 1503409782521696.4295130769905; Tue, 22 Aug 2017 06:49:42 -0700 (PDT) Received: from localhost ([::1]:47130 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9Yr-0004eZ-3j for importer@patchew.org; Tue, 22 Aug 2017 09:49:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54767) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9Hl-0006co-T2 for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:32:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9Hk-00064T-7l for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:32:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33398) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9Hj-00063Q-UC for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:32:00 -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 C2AFF6147D; Tue, 22 Aug 2017 13:25:35 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1225683106; Tue, 22 Aug 2017 13:25:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C2AFF6147D 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: Tue, 22 Aug 2017 15:22:30 +0200 Message-Id: <20170822132255.23945-30-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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]); Tue, 22 Aug 2017 13:25:35 +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 29/54] qapi: add 'if' to enum members 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?= , Markus Armbruster , Michael Roth 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 --- scripts/qapi.py | 33 +++++++++++++++++++++++++++--= ---- tests/qapi-schema/enum-dict-member.err | 1 - tests/qapi-schema/enum-dict-member.exit | 2 +- tests/qapi-schema/enum-dict-member.json | 3 +-- tests/qapi-schema/enum-dict-member.out | 4 ++++ tests/qapi-schema/qapi-schema-test.json | 5 +++-- tests/qapi-schema/qapi-schema-test.out | 3 ++- tests/qapi-schema/test-qapi.py | 4 +++- 8 files changed, 41 insertions(+), 14 deletions(-) diff --git a/scripts/qapi.py b/scripts/qapi.py index 9d075440d3..9c7c01c11d 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -729,6 +729,10 @@ def check_event(expr, info): allow_metas=3Dmeta) =20 =20 +def enum_get_values(expr): + return [e if isinstance(e, str) else e['name'] for e in expr['data']] + + def check_union(expr, info): name =3D expr['union'] base =3D expr.get('base') @@ -788,7 +792,7 @@ def check_union(expr, info): # If the discriminator names an enum type, then all members # of 'data' must also be members of the enum type. if enum_define: - if key not in enum_define['data']: + if key not in enum_get_values(enum_define): raise QAPISemError(info, "Discriminator value '%s' is not found = in " "enum '%s'" @@ -796,7 +800,7 @@ def check_union(expr, info): =20 # If discriminator is user-defined, ensure all values are covered if enum_define: - for value in enum_define['data']: + for value in enum_get_values(enum_define): if value not in members.keys(): raise QAPISemError(info, "Union '%s' data missing '%s' bra= nch" % (name, value)) @@ -827,7 +831,7 @@ def check_alternate(expr, info): if qtype =3D=3D 'QTYPE_QSTRING': enum_expr =3D enum_types.get(value) if enum_expr: - for v in enum_expr['data']: + for v in enum_get_values(enum_expr): if v in ['on', 'off']: conflicting.add('QTYPE_QBOOL') if re.match(r'[-+0-9.]', v): # lazy, could be tightened @@ -857,6 +861,12 @@ def check_enum(expr, info): raise QAPISemError(info, "Enum '%s' requires a string for 'prefix'" % na= me) for member in members: + if isinstance(member, dict): + if not 'name' in member: + raise QAPISemError(info, "Dictionary member of enum '%s' m= ust " + "have a 'name' key" % name) + check_if(member, info) + member =3D member['name'] check_name(info, "Member of enum '%s'" % name, member, enum_member=3DTrue) =20 @@ -1145,12 +1155,15 @@ class QAPISchemaEnumType(QAPISchemaType): def member_names(self): return [v.name for v in self.values] =20 + def members(self): + return [(v.name, v.ifcond) for v in self.values] + def json_type(self): return 'string' =20 def visit(self, visitor): visitor.visit_enum_type(self.name, self.info, - self.member_names(), self.prefix, self.ifc= ond) + self.members(), self.prefix, self.ifcond) =20 =20 class QAPISchemaArrayType(QAPISchemaType): @@ -1274,9 +1287,11 @@ class QAPISchemaObjectType(QAPISchemaType): class QAPISchemaMember(object): role =3D 'member' =20 - def __init__(self, name): + def __init__(self, name, ifcond=3DNone): assert isinstance(name, str) + assert ifcond is None or isinstance(ifcond, str) self.name =3D name + self.ifcond =3D ifcond self.owner =3D None =20 def set_owner(self, name): @@ -1554,7 +1569,9 @@ class QAPISchema(object): qtype_values, 'QTYPE')) =20 def _make_enum_members(self, values): - return [QAPISchemaMember(v) for v in values] + return [QAPISchemaMember(v['name'], v.get('if')) if isinstance(v, = dict) + else QAPISchemaMember(v) + for v in values] =20 def _make_implicit_enum_type(self, name, info, values, ifcond): # See also QAPISchemaObjectTypeMember._pretty_owner() @@ -1950,6 +1967,8 @@ static const char *const %(c_name)s_array[] =3D { ''', c_name=3Dc_name(name)) for value in values: + if isinstance(value, tuple): + value, ifcond =3D value index =3D c_enum_const(name, value, prefix) ret +=3D mcgen(''' [%(index)s] =3D "%(value)s", @@ -1980,6 +1999,8 @@ typedef enum %(c_name)s { c_name=3Dc_name(name)) =20 for value in enum_values: + if isinstance(value, tuple): + value, ifcond =3D value ret +=3D mcgen(''' %(c_enum)s, ''', diff --git a/tests/qapi-schema/enum-dict-member.err b/tests/qapi-schema/enu= m-dict-member.err index 8ca146ea59..e69de29bb2 100644 --- a/tests/qapi-schema/enum-dict-member.err +++ b/tests/qapi-schema/enum-dict-member.err @@ -1 +0,0 @@ -tests/qapi-schema/enum-dict-member.json:2: Member of enum 'MyEnum' require= s a string name diff --git a/tests/qapi-schema/enum-dict-member.exit b/tests/qapi-schema/en= um-dict-member.exit index d00491fd7e..573541ac97 100644 --- a/tests/qapi-schema/enum-dict-member.exit +++ b/tests/qapi-schema/enum-dict-member.exit @@ -1 +1 @@ -1 +0 diff --git a/tests/qapi-schema/enum-dict-member.json b/tests/qapi-schema/en= um-dict-member.json index 79672e0f09..b09a83061c 100644 --- a/tests/qapi-schema/enum-dict-member.json +++ b/tests/qapi-schema/enum-dict-member.json @@ -1,2 +1 @@ -# we reject any enum member that is not a string -{ 'enum': 'MyEnum', 'data': [ { 'value': 'str' } ] } +{ 'enum': 'TestEnum', 'data': [ { 'name': 'foo' }, { 'name': 'bar' } ]} diff --git a/tests/qapi-schema/enum-dict-member.out b/tests/qapi-schema/enu= m-dict-member.out index e69de29bb2..cf8e3cce2b 100644 --- a/tests/qapi-schema/enum-dict-member.out +++ b/tests/qapi-schema/enum-dict-member.out @@ -0,0 +1,4 @@ +enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool'] + prefix QTYPE +enum TestEnum ['foo', 'bar'] +object q_empty diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qa= pi-schema-test.json index dc2c444fc1..ad2b405d83 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -194,7 +194,8 @@ { 'struct': 'TestIfStruct', 'data': { 'foo': 'int' }, 'if': 'defined(TEST_IF_STRUCT)' } =20 -{ 'enum': 'TestIfEnum', 'data': [ 'foo', 'bar' ], +{ 'enum': 'TestIfEnum', 'data': + [ 'foo', { 'name' : 'bar', 'if': 'defined(TEST_IF_ENUM_BAR)' } ], 'if': 'defined(TEST_IF_ENUM)' } =20 { 'union': 'TestIfUnion', 'data': { 'foo': 'TestStruct' }, @@ -203,7 +204,7 @@ { 'alternate': 'TestIfAlternate', 'data': { 'foo': 'int', 'bar': 'TestStru= ct' }, 'if': 'defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT)' } =20 -{ 'command': 'TestIfCmd', 'data': { 'foo': 'TestIfStruct' }, +{ 'command': 'TestIfCmd', 'data': { 'foo': 'TestIfStruct', 'bar': 'TestIfE= num' }, 'if': 'defined(TEST_IF_CMD) && defined(TEST_IF_STRUCT)' } =20 { 'event': 'TestIfEvent', 'data': { 'foo': 'TestIfStruct' }, diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index fc5fd25f1b..211c367632 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -60,7 +60,7 @@ alternate TestIfAlternate command TestIfCmd q_obj_TestIfCmd-arg -> None gen=3DTrue success_response=3DTrue boxed=3DFalse if defined(TEST_IF_CMD) && defined(TEST_IF_STRUCT) -enum TestIfEnum ['foo', 'bar'] +enum TestIfEnum ['foo', ('bar', 'defined(TEST_IF_ENUM_BAR)')] if defined(TEST_IF_ENUM) event TestIfEvent q_obj_TestIfEvent-arg boxed=3DFalse @@ -197,6 +197,7 @@ object q_obj_EVENT_D-arg member enum3: EnumOne optional=3DTrue object q_obj_TestIfCmd-arg member foo: TestIfStruct optional=3DFalse + member bar: TestIfEnum optional=3DFalse if defined(TEST_IF_CMD) && defined(TEST_IF_STRUCT) object q_obj_TestIfEvent-arg member foo: TestIfStruct optional=3DFalse diff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi.py index 17fd975812..70054848f0 100644 --- a/tests/qapi-schema/test-qapi.py +++ b/tests/qapi-schema/test-qapi.py @@ -18,7 +18,9 @@ import sys =20 class QAPISchemaTestVisitor(QAPISchemaVisitor): def visit_enum_type(self, name, info, values, prefix, ifcond): - print 'enum %s %s' % (name, values) + values =3D ', '.join(["'%s'" % v[0] if not v[1] else str(v) + for v in values]) + print 'enum %s [%s]' % (name, values) if prefix: print ' prefix %s' % prefix self._print_if(ifcond) --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 1503409931203996.9770013113114; Tue, 22 Aug 2017 06:52:11 -0700 (PDT) Received: from localhost ([::1]:47146 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9bB-00076N-Ru for importer@patchew.org; Tue, 22 Aug 2017 09:52:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54837) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9Hr-0006hn-QG for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:32:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9Hm-00066g-1n for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:32:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44196) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9Hl-00065Y-Rw for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:32:01 -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 2163A81243; Tue, 22 Aug 2017 13:25:40 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8E0F460466; Tue, 22 Aug 2017 13:25:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2163A81243 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: Tue, 22 Aug 2017 15:22:31 +0200 Message-Id: <20170822132255.23945-31-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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.25]); Tue, 22 Aug 2017 13:25:40 +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 30/54] qapi: add #if conditions on generated enum values 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?= , Markus Armbruster , Michael Roth 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 --- scripts/qapi.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/qapi.py b/scripts/qapi.py index 9c7c01c11d..201e425842 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -1967,13 +1967,16 @@ static const char *const %(c_name)s_array[] =3D { ''', c_name=3Dc_name(name)) for value in values: + ifcond =3D None if isinstance(value, tuple): value, ifcond =3D value + ret +=3D gen_if(ifcond) index =3D c_enum_const(name, value, prefix) ret +=3D mcgen(''' [%(index)s] =3D "%(value)s", ''', index=3Dindex, value=3Dvalue) + ret +=3D gen_endif(ifcond) =20 max_index =3D c_enum_const(name, '_MAX', prefix) ret +=3D mcgen(''' @@ -1999,12 +2002,15 @@ typedef enum %(c_name)s { c_name=3Dc_name(name)) =20 for value in enum_values: + ifcond =3D None if isinstance(value, tuple): value, ifcond =3D value + ret +=3D gen_if(ifcond) ret +=3D mcgen(''' %(c_enum)s, ''', c_enum=3Dc_enum_const(name, value, prefix)) + ret +=3D gen_endif(ifcond) =20 ret +=3D mcgen(''' } %(c_name)s; --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 1503410922370343.94394666374683; Tue, 22 Aug 2017 07:08:42 -0700 (PDT) Received: from localhost ([::1]:47331 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9rB-000414-U2 for importer@patchew.org; Tue, 22 Aug 2017 10:08:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55065) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9J3-0007nS-Ek for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9J0-0006nJ-6y for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36814) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9Iz-0006mn-TR for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:18 -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 E86DC490; Tue, 22 Aug 2017 13:25:42 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4C3F37DE57; Tue, 22 Aug 2017 13:25:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E86DC490 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: Tue, 22 Aug 2017 15:22:32 +0200 Message-Id: <20170822132255.23945-32-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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.29]); Tue, 22 Aug 2017 13:25:43 +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 31/54] tests: add some enum members 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?= , Markus Armbruster , Michael Roth 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/Makefile.include | 2 ++ tests/qapi-schema/enum-dict-member-invalid.err | 1 + tests/qapi-schema/enum-dict-member-invalid.exit | 1 + tests/qapi-schema/enum-dict-member-invalid.json | 2 ++ tests/qapi-schema/enum-dict-member-invalid.out | 0 tests/qapi-schema/enum-if-invalid.err | 1 + tests/qapi-schema/enum-if-invalid.exit | 1 + tests/qapi-schema/enum-if-invalid.json | 3 +++ tests/qapi-schema/enum-if-invalid.out | 0 9 files changed, 11 insertions(+) create mode 100644 tests/qapi-schema/enum-dict-member-invalid.err create mode 100644 tests/qapi-schema/enum-dict-member-invalid.exit create mode 100644 tests/qapi-schema/enum-dict-member-invalid.json create mode 100644 tests/qapi-schema/enum-dict-member-invalid.out create mode 100644 tests/qapi-schema/enum-if-invalid.err create mode 100644 tests/qapi-schema/enum-if-invalid.exit create mode 100644 tests/qapi-schema/enum-if-invalid.json create mode 100644 tests/qapi-schema/enum-if-invalid.out diff --git a/tests/Makefile.include b/tests/Makefile.include index 1f1d8f075b..1c5ce6519e 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -436,6 +436,8 @@ qapi-schema +=3D enum-bad-name.json qapi-schema +=3D enum-bad-prefix.json qapi-schema +=3D enum-clash-member.json qapi-schema +=3D enum-dict-member.json +qapi-schema +=3D enum-dict-member-invalid.json +qapi-schema +=3D enum-if-invalid.json qapi-schema +=3D enum-int-member.json qapi-schema +=3D enum-member-case.json qapi-schema +=3D enum-missing-data.json diff --git a/tests/qapi-schema/enum-dict-member-invalid.err b/tests/qapi-sc= hema/enum-dict-member-invalid.err new file mode 100644 index 0000000000..d12cca0df3 --- /dev/null +++ b/tests/qapi-schema/enum-dict-member-invalid.err @@ -0,0 +1 @@ +tests/qapi-schema/enum-dict-member-invalid.json:2: Dictionary member of en= um 'MyEnum' must have a 'name' key diff --git a/tests/qapi-schema/enum-dict-member-invalid.exit b/tests/qapi-s= chema/enum-dict-member-invalid.exit new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/tests/qapi-schema/enum-dict-member-invalid.exit @@ -0,0 +1 @@ +1 diff --git a/tests/qapi-schema/enum-dict-member-invalid.json b/tests/qapi-s= chema/enum-dict-member-invalid.json new file mode 100644 index 0000000000..9cf8406867 --- /dev/null +++ b/tests/qapi-schema/enum-dict-member-invalid.json @@ -0,0 +1,2 @@ +# we reject any enum member that is not a string or a dict with 'name' +{ 'enum': 'MyEnum', 'data': [ { 'value': 'str' } ] } diff --git a/tests/qapi-schema/enum-dict-member-invalid.out b/tests/qapi-sc= hema/enum-dict-member-invalid.out new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/qapi-schema/enum-if-invalid.err b/tests/qapi-schema/enum= -if-invalid.err new file mode 100644 index 0000000000..236b703e88 --- /dev/null +++ b/tests/qapi-schema/enum-if-invalid.err @@ -0,0 +1 @@ +tests/qapi-schema/enum-if-invalid.json:2: 'if' condition requires a string= or a list of string diff --git a/tests/qapi-schema/enum-if-invalid.exit b/tests/qapi-schema/enu= m-if-invalid.exit new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/tests/qapi-schema/enum-if-invalid.exit @@ -0,0 +1 @@ +1 diff --git a/tests/qapi-schema/enum-if-invalid.json b/tests/qapi-schema/enu= m-if-invalid.json new file mode 100644 index 0000000000..60bd0ef1d7 --- /dev/null +++ b/tests/qapi-schema/enum-if-invalid.json @@ -0,0 +1,3 @@ +# check invalid 'if' type +{ 'enum': 'TestIfEnum', 'data': + [ 'foo', { 'name' : 'bar', 'if': { 'val': 'foo' } } ] } diff --git a/tests/qapi-schema/enum-if-invalid.out b/tests/qapi-schema/enum= -if-invalid.out new file mode 100644 index 0000000000..e69de29bb2 --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 1503409455250739.8831756868686; Tue, 22 Aug 2017 06:44:15 -0700 (PDT) Received: from localhost ([::1]:47047 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9Ta-0008Kx-29 for importer@patchew.org; Tue, 22 Aug 2017 09:44:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54754) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9Hl-0006cJ-C0 for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:32:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9Hk-00064N-7C for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:32:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33400) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9Hj-00063S-UQ for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:32:00 -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 B207861477; Tue, 22 Aug 2017 13:25:47 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0CD3C7C155; Tue, 22 Aug 2017 13:25:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B207861477 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: Tue, 22 Aug 2017 15:22:33 +0200 Message-Id: <20170822132255.23945-33-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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.39]); Tue, 22 Aug 2017 13:25: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 32/54] qapi: add 'if' to struct members 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?= , Markus Armbruster , Michael Roth 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 --- scripts/qapi.py | 18 ++++++++++++++---- tests/qapi-schema/qapi-schema-test.json | 9 ++++++--- tests/qapi-schema/qapi-schema-test.out | 4 +++- tests/qapi-schema/test-qapi.py | 3 ++- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/scripts/qapi.py b/scripts/qapi.py index 201e425842..946df83854 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -678,7 +678,13 @@ def check_type(info, source, value, allow_array=3DFals= e, return =20 if not allow_dict: - raise QAPISemError(info, "%s should be a type name" % source) + if isinstance(value, dict) and 'type' in value: + check_type(info, source, value['type'], allow_array, + allow_dict, allow_optional, allow_metas) + check_if(value, info) + return + else: + raise QAPISemError(info, "%s should be a type name" % source) =20 if not isinstance(value, OrderedDict): raise QAPISemError(info, @@ -1332,8 +1338,8 @@ class QAPISchemaMember(object): =20 =20 class QAPISchemaObjectTypeMember(QAPISchemaMember): - def __init__(self, name, typ, optional): - QAPISchemaMember.__init__(self, name) + def __init__(self, name, typ, optional, ifcond=3DNone): + QAPISchemaMember.__init__(self, name, ifcond) assert isinstance(typ, str) assert isinstance(optional, bool) self._type_name =3D typ @@ -1612,13 +1618,17 @@ class QAPISchema(object): =20 def _make_member(self, name, typ, info): optional =3D False + ifcond =3D None if name.startswith('*'): name =3D name[1:] optional =3D True + if isinstance(typ, dict): + ifcond =3D typ.get('if') + typ =3D typ['type'] if isinstance(typ, list): assert len(typ) =3D=3D 1 typ =3D self._make_array_type(typ[0], info) - return QAPISchemaObjectTypeMember(name, typ, optional) + return QAPISchemaObjectTypeMember(name, typ, optional, ifcond) =20 def _make_members(self, data, info): return [self._make_member(key, value, info) diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qa= pi-schema-test.json index ad2b405d83..b136e4855f 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -191,7 +191,8 @@ =20 # test 'if' condition handling =20 -{ 'struct': 'TestIfStruct', 'data': { 'foo': 'int' }, +{ 'struct': 'TestIfStruct', 'data': + { 'foo': 'int', 'bar': { 'type': 'int', 'if': 'defined(TEST_IF_STRUCT_BA= R)'} }, 'if': 'defined(TEST_IF_STRUCT)' } =20 { 'enum': 'TestIfEnum', 'data': @@ -204,8 +205,10 @@ { 'alternate': 'TestIfAlternate', 'data': { 'foo': 'int', 'bar': 'TestStru= ct' }, 'if': 'defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT)' } =20 -{ 'command': 'TestIfCmd', 'data': { 'foo': 'TestIfStruct', 'bar': 'TestIfE= num' }, +{ 'command': 'TestIfCmd', 'data': + { 'foo': 'TestIfStruct', 'bar': { 'type': 'TestIfEnum', 'if': 'defined(T= EST_IF_CMD_BAR)' } }, 'if': 'defined(TEST_IF_CMD) && defined(TEST_IF_STRUCT)' } =20 -{ 'event': 'TestIfEvent', 'data': { 'foo': 'TestIfStruct' }, +{ 'event': 'TestIfEvent', 'data': + { 'foo': 'TestIfStruct', 'bar': { 'type': 'TestIfEnum', 'if': 'defined(T= EST_IF_EVT_BAR)' } }, 'if': 'defined(TEST_IF_EVT) && defined(TEST_IF_STRUCT)' } diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index 211c367632..5d2f18e4aa 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -67,6 +67,7 @@ event TestIfEvent q_obj_TestIfEvent-arg if defined(TEST_IF_EVT) && defined(TEST_IF_STRUCT) object TestIfStruct member foo: int optional=3DFalse + member bar: int optional=3DFalse if=3Ddefined(TEST_IF_STRUCT_BAR) if defined(TEST_IF_STRUCT) object TestIfUnion member type: TestIfUnionKind optional=3DFalse @@ -197,10 +198,11 @@ object q_obj_EVENT_D-arg member enum3: EnumOne optional=3DTrue object q_obj_TestIfCmd-arg member foo: TestIfStruct optional=3DFalse - member bar: TestIfEnum optional=3DFalse + member bar: TestIfEnum optional=3DFalse if=3Ddefined(TEST_IF_CMD_BAR) if defined(TEST_IF_CMD) && defined(TEST_IF_STRUCT) object q_obj_TestIfEvent-arg member foo: TestIfStruct optional=3DFalse + member bar: TestIfEnum optional=3DFalse if=3Ddefined(TEST_IF_EVT_BAR) if defined(TEST_IF_EVT) && defined(TEST_IF_STRUCT) object q_obj_TestStruct-wrapper member data: TestStruct optional=3DFalse diff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi.py index 70054848f0..5d2f67a1d3 100644 --- a/tests/qapi-schema/test-qapi.py +++ b/tests/qapi-schema/test-qapi.py @@ -31,7 +31,8 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): print ' base %s' % base.name for m in members: print ' member %s: %s optional=3D%s' % \ - (m.name, m.type.name, m.optional) + (m.name, m.type.name, m.optional) + \ + (' if=3D%s' % m.ifcond if m.ifcond else '') self._print_variants(variants) self._print_if(ifcond) =20 --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 1503410823167318.11156183738944; Tue, 22 Aug 2017 07:07:03 -0700 (PDT) Received: from localhost ([::1]:47325 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9pd-0002q5-SX for importer@patchew.org; Tue, 22 Aug 2017 10:07:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55180) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9JL-000820-B4 for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9JI-0006xc-59 for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58300) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9JH-0006wj-T3 for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:36 -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 8CAA3C04D2AB; Tue, 22 Aug 2017 13:25:52 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id B29D66CDD0; Tue, 22 Aug 2017 13:25:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8CAA3C04D2AB 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: Tue, 22 Aug 2017 15:22:34 +0200 Message-Id: <20170822132255.23945-34-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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.31]); Tue, 22 Aug 2017 13:25: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 33/54] qapi: add some struct member 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?= , Markus Armbruster , Michael Roth 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/Makefile.include | 2 ++ tests/qapi-schema/struct-if-invalid.err | 1 + tests/qapi-schema/struct-if-invalid.exit | 1 + tests/qapi-schema/struct-if-invalid.json | 3 +++ tests/qapi-schema/struct-if-invalid.out | 0 tests/qapi-schema/struct-member-type.err | 0 tests/qapi-schema/struct-member-type.exit | 1 + tests/qapi-schema/struct-member-type.json | 1 + tests/qapi-schema/struct-member-type.out | 5 +++++ 9 files changed, 14 insertions(+) create mode 100644 tests/qapi-schema/struct-if-invalid.err create mode 100644 tests/qapi-schema/struct-if-invalid.exit create mode 100644 tests/qapi-schema/struct-if-invalid.json create mode 100644 tests/qapi-schema/struct-if-invalid.out create mode 100644 tests/qapi-schema/struct-member-type.err create mode 100644 tests/qapi-schema/struct-member-type.exit create mode 100644 tests/qapi-schema/struct-member-type.json create mode 100644 tests/qapi-schema/struct-member-type.out diff --git a/tests/Makefile.include b/tests/Makefile.include index 1c5ce6519e..e00cb9833b 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -512,7 +512,9 @@ qapi-schema +=3D returns-whitelist.json qapi-schema +=3D struct-base-clash-deep.json qapi-schema +=3D struct-base-clash.json qapi-schema +=3D struct-data-invalid.json +qapi-schema +=3D struct-if-invalid.json qapi-schema +=3D struct-member-invalid.json +qapi-schema +=3D struct-member-type.json qapi-schema +=3D trailing-comma-list.json qapi-schema +=3D trailing-comma-object.json qapi-schema +=3D type-bypass-bad-gen.json diff --git a/tests/qapi-schema/struct-if-invalid.err b/tests/qapi-schema/st= ruct-if-invalid.err new file mode 100644 index 0000000000..42245262a9 --- /dev/null +++ b/tests/qapi-schema/struct-if-invalid.err @@ -0,0 +1 @@ +tests/qapi-schema/struct-if-invalid.json:2: Member 'bar' of 'data' for str= uct 'TestIfStruct' should be a type name diff --git a/tests/qapi-schema/struct-if-invalid.exit b/tests/qapi-schema/s= truct-if-invalid.exit new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/tests/qapi-schema/struct-if-invalid.exit @@ -0,0 +1 @@ +1 diff --git a/tests/qapi-schema/struct-if-invalid.json b/tests/qapi-schema/s= truct-if-invalid.json new file mode 100644 index 0000000000..466cdb61e1 --- /dev/null +++ b/tests/qapi-schema/struct-if-invalid.json @@ -0,0 +1,3 @@ +# check missing 'type' +{ 'struct': 'TestIfStruct', 'data': + { 'foo': 'int', 'bar': { 'if': 'defined(TEST_IF_STRUCT_BAR)' } } } diff --git a/tests/qapi-schema/struct-if-invalid.out b/tests/qapi-schema/st= ruct-if-invalid.out new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/qapi-schema/struct-member-type.err b/tests/qapi-schema/s= truct-member-type.err new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/qapi-schema/struct-member-type.exit b/tests/qapi-schema/= struct-member-type.exit new file mode 100644 index 0000000000..573541ac97 --- /dev/null +++ b/tests/qapi-schema/struct-member-type.exit @@ -0,0 +1 @@ +0 diff --git a/tests/qapi-schema/struct-member-type.json b/tests/qapi-schema/= struct-member-type.json new file mode 100644 index 0000000000..07de38fa4a --- /dev/null +++ b/tests/qapi-schema/struct-member-type.json @@ -0,0 +1 @@ +{ 'struct': 'foo', 'data': { 'a': { 'type': 'str' } } } diff --git a/tests/qapi-schema/struct-member-type.out b/tests/qapi-schema/s= truct-member-type.out new file mode 100644 index 0000000000..2ea68909a9 --- /dev/null +++ b/tests/qapi-schema/struct-member-type.out @@ -0,0 +1,5 @@ +enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool'] + prefix QTYPE +object foo + member a: str optional=3DFalse +object q_empty --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 1503410003907680.6419776856256; Tue, 22 Aug 2017 06:53:23 -0700 (PDT) Received: from localhost ([::1]:47170 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9cP-0008CJ-Nr for importer@patchew.org; Tue, 22 Aug 2017 09:53:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54570) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9HN-0006HY-SX for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:31:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9HK-0005d3-2g for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:31:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55044) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9HJ-0005cV-Rl for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:31:33 -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 6B13A5BECB; Tue, 22 Aug 2017 13:25:57 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 789537E57D; Tue, 22 Aug 2017 13:25:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6B13A5BECB 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: Tue, 22 Aug 2017 15:22:35 +0200 Message-Id: <20170822132255.23945-35-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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]); Tue, 22 Aug 2017 13:25: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 34/54] qapi: add #if conditions to generated struct members 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?= , Markus Armbruster , Michael Roth 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 --- scripts/qapi-introspect.py | 2 ++ scripts/qapi-types.py | 2 ++ scripts/qapi-visit.py | 2 ++ 3 files changed, 6 insertions(+) diff --git a/scripts/qapi-introspect.py b/scripts/qapi-introspect.py index 5e736a06df..b379c7c170 100644 --- a/scripts/qapi-introspect.py +++ b/scripts/qapi-introspect.py @@ -136,6 +136,8 @@ const QLitObject %(c_name)s =3D %(c_string)s; ret =3D {'name': member.name, 'type': self._use_type(member.type)} if member.optional: ret['default'] =3D None + if member.ifcond: + ret =3D (ret, member.ifcond) return ret =20 def _gen_variants(self, tag_name, variants): diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index c1316312ac..b7f4773fe1 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -41,6 +41,7 @@ struct %(c_name)s { def gen_struct_members(members): ret =3D '' for memb in members: + ret +=3D gen_if(memb.ifcond) if memb.optional: ret +=3D mcgen(''' bool has_%(c_name)s; @@ -50,6 +51,7 @@ def gen_struct_members(members): %(c_type)s %(c_name)s; ''', c_type=3Dmemb.type.c_type(), c_name=3Dc_name(memb.nam= e)) + ret +=3D gen_endif(memb.ifcond) return ret =20 =20 diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py index bb18c9edee..25914f71b0 100644 --- a/scripts/qapi-visit.py +++ b/scripts/qapi-visit.py @@ -53,6 +53,7 @@ void visit_type_%(c_name)s_members(Visitor *v, %(c_name)s= *obj, Error **errp) c_type=3Dbase.c_name()) =20 for memb in members: + ret +=3D gen_if(memb.ifcond) if memb.optional: ret +=3D mcgen(''' if (visit_optional(v, "%(name)s", &obj->has_%(c_name)s)) { @@ -72,6 +73,7 @@ void visit_type_%(c_name)s_members(Visitor *v, %(c_name)s= *obj, Error **errp) ret +=3D mcgen(''' } ''') + ret +=3D gen_endif(memb.ifcond) =20 if variants: ret +=3D mcgen(''' --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 1503411177254532.0559683500181; Tue, 22 Aug 2017 07:12:57 -0700 (PDT) Received: from localhost ([::1]:47365 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9vL-0007Rr-Vk for importer@patchew.org; Tue, 22 Aug 2017 10:12:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55181) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9JL-000821-B3 for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9JI-0006xX-53 for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58298) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9JH-0006wi-Sk for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:36 -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 701CFC0467C6; Tue, 22 Aug 2017 13:26:00 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 93B66617A0; Tue, 22 Aug 2017 13:25:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 701CFC0467C6 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: Tue, 22 Aug 2017 15:22:36 +0200 Message-Id: <20170822132255.23945-36-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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.31]); Tue, 22 Aug 2017 13:26:00 +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 35/54] qapi: add 'if' on union variants 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?= , Markus Armbruster , Michael Roth 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 --- scripts/qapi.py | 14 +++++++++----- tests/qapi-schema/qapi-schema-test.json | 6 +++++- tests/qapi-schema/qapi-schema-test.out | 9 ++++++++- tests/qapi-schema/test-qapi.py | 3 ++- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/scripts/qapi.py b/scripts/qapi.py index 946df83854..cd5d151809 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -1397,8 +1397,8 @@ class QAPISchemaObjectTypeVariants(object): class QAPISchemaObjectTypeVariant(QAPISchemaObjectTypeMember): role =3D 'branch' =20 - def __init__(self, name, typ): - QAPISchemaObjectTypeMember.__init__(self, name, typ, False) + def __init__(self, name, typ, ifcond=3DNone): + QAPISchemaObjectTypeMember.__init__(self, name, typ, False, ifcond) =20 =20 class QAPISchemaAlternateType(QAPISchemaType): @@ -1647,6 +1647,10 @@ class QAPISchema(object): return QAPISchemaObjectTypeVariant(case, typ) =20 def _make_simple_variant(self, case, typ, info): + ifcond =3D None + if isinstance(typ, dict): + ifcond =3D typ.get('if') + typ =3D typ['type'] if isinstance(typ, list): assert len(typ) =3D=3D 1 typ =3D self._make_array_type(typ[0], info) @@ -1654,7 +1658,7 @@ class QAPISchema(object): typ =3D self._make_implicit_object_type( typ, info, None, 'wrapper', [self._make_member('data', typ, info)], type_entity.ifcond) - return QAPISchemaObjectTypeVariant(case, typ) + return QAPISchemaObjectTypeVariant(case, typ, ifcond) =20 def _def_union_type(self, expr, info, doc): name =3D expr['union'] @@ -1674,8 +1678,8 @@ class QAPISchema(object): else: variants =3D [self._make_simple_variant(key, value, info) for (key, value) in data.iteritems()] - typ =3D self._make_implicit_enum_type(name, info, - [v.name for v in variants], + values =3D [{'name': v.name, 'if': v.ifcond} for v in variants] + typ =3D self._make_implicit_enum_type(name, info, values, ifcond) tag_member =3D QAPISchemaObjectTypeMember('type', typ, False) members =3D [tag_member] diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qa= pi-schema-test.json index b136e4855f..23dae79f92 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -199,9 +199,13 @@ [ 'foo', { 'name' : 'bar', 'if': 'defined(TEST_IF_ENUM_BAR)' } ], 'if': 'defined(TEST_IF_ENUM)' } =20 -{ 'union': 'TestIfUnion', 'data': { 'foo': 'TestStruct' }, +{ 'union': 'TestIfUnion', 'data': + { 'foo': 'TestStruct', 'union_bar': { 'type': 'str', 'if': 'defined(TEST= _IF_UNION_BAR)'} }, 'if': 'defined(TEST_IF_UNION) && defined(TEST_IF_STRUCT)' } =20 +{ 'command': 'TestIfUnionCmd', 'data': { 'union_cmd_arg': 'TestIfUnion' }, + 'if': 'defined(TEST_IF_UNION)' } + { 'alternate': 'TestIfAlternate', 'data': { 'foo': 'int', 'bar': 'TestStru= ct' }, 'if': 'defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT)' } =20 diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index 5d2f18e4aa..12fc5a4425 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -73,8 +73,12 @@ object TestIfUnion member type: TestIfUnionKind optional=3DFalse tag type case foo: q_obj_TestStruct-wrapper + case union_bar: q_obj_str-wrapper if=3Ddefined(TEST_IF_UNION_BAR) if defined(TEST_IF_UNION) && defined(TEST_IF_STRUCT) -enum TestIfUnionKind ['foo'] +command TestIfUnionCmd q_obj_TestIfUnionCmd-arg -> None + gen=3DTrue success_response=3DTrue boxed=3DFalse + if defined(TEST_IF_UNION) +enum TestIfUnionKind ['foo', ('union_bar', 'defined(TEST_IF_UNION_BAR)')] if defined(TEST_IF_UNION) && defined(TEST_IF_STRUCT) object TestStruct member integer: int optional=3DFalse @@ -204,6 +208,9 @@ object q_obj_TestIfEvent-arg member foo: TestIfStruct optional=3DFalse member bar: TestIfEnum optional=3DFalse if=3Ddefined(TEST_IF_EVT_BAR) if defined(TEST_IF_EVT) && defined(TEST_IF_STRUCT) +object q_obj_TestIfUnionCmd-arg + member union_cmd_arg: TestIfUnion optional=3DFalse + if defined(TEST_IF_UNION) object q_obj_TestStruct-wrapper member data: TestStruct optional=3DFalse object q_obj_UserDefFlatUnion2-base diff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi.py index 5d2f67a1d3..b360d44df1 100644 --- a/tests/qapi-schema/test-qapi.py +++ b/tests/qapi-schema/test-qapi.py @@ -59,7 +59,8 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): if variants: print ' tag %s' % variants.tag_member.name for v in variants.variants: - print ' case %s: %s' % (v.name, v.type.name) + print ' case %s: %s' % (v.name, v.type.name) + \ + (' if=3D%s' % v.ifcond if v.ifcond else '') =20 @staticmethod def _print_if(ifcond): --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 1503409379185928.1332051752706; Tue, 22 Aug 2017 06:42:59 -0700 (PDT) Received: from localhost ([::1]:47044 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9SM-0007Ig-24 for importer@patchew.org; Tue, 22 Aug 2017 09:42:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54479) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9H4-0005zY-QC for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:31:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9Gz-0005Kd-6p for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:31:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38000) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9Gy-0005K8-VO for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:31:13 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AE8B57E44D; Tue, 22 Aug 2017 13:26:04 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5944C17F55; Tue, 22 Aug 2017 13:26:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com AE8B57E44D 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: Tue, 22 Aug 2017 15:22:37 +0200 Message-Id: <20170822132255.23945-37-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 22 Aug 2017 13:26:04 +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 36/54] qapi: add #if conditions to generated variants 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?= , Markus Armbruster , Michael Roth 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 --- scripts/qapi-introspect.py | 3 ++- scripts/qapi-types.py | 2 ++ scripts/qapi-visit.py | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/qapi-introspect.py b/scripts/qapi-introspect.py index b379c7c170..5cd2a3fe3f 100644 --- a/scripts/qapi-introspect.py +++ b/scripts/qapi-introspect.py @@ -145,7 +145,8 @@ const QLitObject %(c_name)s =3D %(c_string)s; 'variants': [self._gen_variant(v) for v in variants]} =20 def _gen_variant(self, variant): - return {'case': variant.name, 'type': self._use_type(variant.type)} + return ({'case': variant.name, 'type': self._use_type(variant.type= )}, + variant.ifcond) =20 def visit_builtin_type(self, name, info, json_type): self._gen_qlit(name, 'builtin', {'json-type': json_type}, None) diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index b7f4773fe1..5924276990 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -129,11 +129,13 @@ def gen_variants(variants): c_name=3Dc_name(variants.tag_member.name)) =20 for var in variants.variants: + ret +=3D gen_if(var.ifcond) ret +=3D mcgen(''' %(c_type)s %(c_name)s; ''', c_type=3Dvar.type.c_unboxed_type(), c_name=3Dc_name(var.name)) + ret +=3D gen_endif(var.ifcond) =20 ret +=3D mcgen(''' } u; diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py index 25914f71b0..a1ff509e53 100644 --- a/scripts/qapi-visit.py +++ b/scripts/qapi-visit.py @@ -82,6 +82,7 @@ void visit_type_%(c_name)s_members(Visitor *v, %(c_name)s= *obj, Error **errp) c_name=3Dc_name(variants.tag_member.name)) =20 for var in variants.variants: + ret +=3D gen_if(var.ifcond) ret +=3D mcgen(''' case %(case)s: visit_type_%(c_type)s_members(v, &obj->u.%(c_name)s, &err); @@ -92,6 +93,7 @@ void visit_type_%(c_name)s_members(Visitor *v, %(c_name)s= *obj, Error **errp) variants.tag_member.type.prefix= ), c_type=3Dvar.type.c_name(), c_name=3Dc_name(var.n= ame)) =20 + ret +=3D gen_endif(var.ifcond) ret +=3D mcgen(''' default: abort(); @@ -182,6 +184,7 @@ void visit_type_%(c_name)s(Visitor *v, const char *name= , %(c_name)s **obj, Error c_name=3Dc_name(name)) =20 for var in variants.variants: + ret +=3D gen_if(var.ifcond) ret +=3D mcgen(''' case %(case)s: ''', @@ -209,6 +212,7 @@ void visit_type_%(c_name)s(Visitor *v, const char *name= , %(c_name)s **obj, Error ret +=3D mcgen(''' break; ''') + ret +=3D gen_endif(var.ifcond) =20 ret +=3D mcgen(''' case QTYPE_NONE: --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 1503409973455991.8356136911983; Tue, 22 Aug 2017 06:52:53 -0700 (PDT) Received: from localhost ([::1]:47169 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9bw-0007m3-7N for importer@patchew.org; Tue, 22 Aug 2017 09:52:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54803) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9Ho-0006fA-3h for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:32:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9Hk-00064F-67 for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:32:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33394) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9Hj-00063K-Ss for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:32:00 -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 3895761476; Tue, 22 Aug 2017 13:26:10 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id A75B2617A9; Tue, 22 Aug 2017 13:26:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3895761476 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: Tue, 22 Aug 2017 15:22:38 +0200 Message-Id: <20170822132255.23945-38-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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.39]); Tue, 22 Aug 2017 13:26:10 +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 37/54] qapi: 'if' to alternate variant 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?= , Markus Armbruster , Michael Roth 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 --- scripts/qapi.py | 8 +++++++- tests/qapi-schema/qapi-schema-test.json | 6 +++++- tests/qapi-schema/qapi-schema-test.out | 8 +++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/scripts/qapi.py b/scripts/qapi.py index cd5d151809..bcd8d37c12 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -829,6 +829,8 @@ def check_alternate(expr, info): check_type(info, "Member '%s' of alternate '%s'" % (key, name), value, allow_metas=3D['built-in', 'union', 'struct', 'enum']) + if isinstance(value, dict): + value =3D value['type'] qtype =3D find_alternate_member_qtype(value) if not qtype: raise QAPISemError(info, "Alternate '%s' member '%s' cannot us= e " @@ -1644,7 +1646,11 @@ class QAPISchema(object): None, ifcond)) =20 def _make_variant(self, case, typ): - return QAPISchemaObjectTypeVariant(case, typ) + ifcond =3D None + if isinstance(typ, dict): + ifcond =3D typ.get('if') + typ =3D typ['type'] + return QAPISchemaObjectTypeVariant(case, typ, ifcond) =20 def _make_simple_variant(self, case, typ, info): ifcond =3D None diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qa= pi-schema-test.json index 23dae79f92..0032e4f026 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -206,9 +206,13 @@ { 'command': 'TestIfUnionCmd', 'data': { 'union_cmd_arg': 'TestIfUnion' }, 'if': 'defined(TEST_IF_UNION)' } =20 -{ 'alternate': 'TestIfAlternate', 'data': { 'foo': 'int', 'bar': 'TestStru= ct' }, +{ 'alternate': 'TestIfAlternate', 'data': + { 'foo': 'int', 'alt_bar': { 'type': 'TestStruct', 'if': 'defined(TEST_I= F_ALT_BAR)'} }, 'if': 'defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT)' } =20 +{ 'command': 'TestIfAlternateCmd', 'data': { 'alt_cmd_arg': 'TestIfAlterna= te' }, + 'if': 'defined(TEST_IF_ALT)' } + { 'command': 'TestIfCmd', 'data': { 'foo': 'TestIfStruct', 'bar': { 'type': 'TestIfEnum', 'if': 'defined(T= EST_IF_CMD_BAR)' } }, 'if': 'defined(TEST_IF_CMD) && defined(TEST_IF_STRUCT)' } diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index 12fc5a4425..8b8144574b 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -55,8 +55,11 @@ enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict',= 'qlist', 'qbool'] alternate TestIfAlternate tag type case foo: int - case bar: TestStruct + case alt_bar: TestStruct if=3Ddefined(TEST_IF_ALT_BAR) if defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT) +command TestIfAlternateCmd q_obj_TestIfAlternateCmd-arg -> None + gen=3DTrue success_response=3DTrue boxed=3DFalse + if defined(TEST_IF_ALT) command TestIfCmd q_obj_TestIfCmd-arg -> None gen=3DTrue success_response=3DTrue boxed=3DFalse if defined(TEST_IF_CMD) && defined(TEST_IF_STRUCT) @@ -200,6 +203,9 @@ object q_obj_EVENT_D-arg member b: str optional=3DFalse member c: str optional=3DTrue member enum3: EnumOne optional=3DTrue +object q_obj_TestIfAlternateCmd-arg + member alt_cmd_arg: TestIfAlternate optional=3DFalse + if defined(TEST_IF_ALT) object q_obj_TestIfCmd-arg member foo: TestIfStruct optional=3DFalse member bar: TestIfEnum optional=3DFalse if=3Ddefined(TEST_IF_CMD_BAR) --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 1503410108306757.5809783153769; Tue, 22 Aug 2017 06:55:08 -0700 (PDT) Received: from localhost ([::1]:47186 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9e6-0001Br-Vs for importer@patchew.org; Tue, 22 Aug 2017 09:55:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54904) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9I6-0006yD-3w for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:32:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9Hy-0006G0-Dx for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:32:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51642) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9Hy-0006Ez-7D for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:32:14 -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 2B3D1267C5; Tue, 22 Aug 2017 13:26:13 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id F1F2E617B7; Tue, 22 Aug 2017 13:26:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2B3D1267C5 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: Tue, 22 Aug 2017 15:22:39 +0200 Message-Id: <20170822132255.23945-39-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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]); Tue, 22 Aug 2017 13:26:13 +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 38/54] qapi: add tests for invalid alternate 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?= , Markus Armbruster , Michael Roth 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/Makefile.include | 1 + tests/qapi-schema/alternate-dict-invalid.err | 1 + tests/qapi-schema/alternate-dict-invalid.exit | 1 + tests/qapi-schema/alternate-dict-invalid.json | 4 ++++ tests/qapi-schema/alternate-dict-invalid.out | 0 5 files changed, 7 insertions(+) create mode 100644 tests/qapi-schema/alternate-dict-invalid.err create mode 100644 tests/qapi-schema/alternate-dict-invalid.exit create mode 100644 tests/qapi-schema/alternate-dict-invalid.json create mode 100644 tests/qapi-schema/alternate-dict-invalid.out diff --git a/tests/Makefile.include b/tests/Makefile.include index e00cb9833b..316d81fa95 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -374,6 +374,7 @@ qapi-schema +=3D alternate-conflict-dict.json qapi-schema +=3D alternate-conflict-enum-bool.json qapi-schema +=3D alternate-conflict-enum-int.json qapi-schema +=3D alternate-conflict-string.json +qapi-schema +=3D alternate-dict-invalid.json qapi-schema +=3D alternate-empty.json qapi-schema +=3D alternate-nested.json qapi-schema +=3D alternate-unknown.json diff --git a/tests/qapi-schema/alternate-dict-invalid.err b/tests/qapi-sche= ma/alternate-dict-invalid.err new file mode 100644 index 0000000000..707c40f0f6 --- /dev/null +++ b/tests/qapi-schema/alternate-dict-invalid.err @@ -0,0 +1 @@ +tests/qapi-schema/alternate-dict-invalid.json:2: Member 'two' of alternate= 'Alt' should be a type name diff --git a/tests/qapi-schema/alternate-dict-invalid.exit b/tests/qapi-sch= ema/alternate-dict-invalid.exit new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/tests/qapi-schema/alternate-dict-invalid.exit @@ -0,0 +1 @@ +1 diff --git a/tests/qapi-schema/alternate-dict-invalid.json b/tests/qapi-sch= ema/alternate-dict-invalid.json new file mode 100644 index 0000000000..45f2c8ebef --- /dev/null +++ b/tests/qapi-schema/alternate-dict-invalid.json @@ -0,0 +1,4 @@ +# invalid field dictionnary, missing type +{ 'alternate': 'Alt', + 'data': { 'one': 'str', + 'two': { 'if': 'foo' } } } diff --git a/tests/qapi-schema/alternate-dict-invalid.out b/tests/qapi-sche= ma/alternate-dict-invalid.out new file mode 100644 index 0000000000..e69de29bb2 --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 1503409167199920.49771220376; Tue, 22 Aug 2017 06:39:27 -0700 (PDT) Received: from localhost ([::1]:46944 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9Ow-0003xo-0y for importer@patchew.org; Tue, 22 Aug 2017 09:39:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54589) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9HP-0006J0-IZ for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:31:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9HK-0005dK-3D for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:31:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55032) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9HJ-0005cR-S4 for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:31:33 -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 7479368C8; Tue, 22 Aug 2017 13:26:18 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id E62887DE57; Tue, 22 Aug 2017 13:26:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7479368C8 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: Tue, 22 Aug 2017 15:22:40 +0200 Message-Id: <20170822132255.23945-40-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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]); Tue, 22 Aug 2017 13:26:18 +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 39/54] qapi: add #if conditions to generated alternate variants 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?= , Markus Armbruster , Michael Roth 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" Mostly covered by previous patches already. Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi-introspect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/qapi-introspect.py b/scripts/qapi-introspect.py index 5cd2a3fe3f..ed00005894 100644 --- a/scripts/qapi-introspect.py +++ b/scripts/qapi-introspect.py @@ -168,7 +168,7 @@ const QLitObject %(c_name)s =3D %(c_string)s; =20 def visit_alternate_type(self, name, info, variants, ifcond): self._gen_qlit(name, 'alternate', - {'members': [{'type': self._use_type(m.type)} + {'members': [({'type': self._use_type(m.type)}, m.i= fcond) for m in variants.variants]}, ifcond) =20 def visit_command(self, name, info, arg_type, ret_type, --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 1503411387110502.3224824018363; Tue, 22 Aug 2017 07:16:27 -0700 (PDT) Received: from localhost ([::1]:47458 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9yj-0001u4-Tf for importer@patchew.org; Tue, 22 Aug 2017 10:16:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56232) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9M3-0001su-D8 for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:36:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9M0-0000Ct-4n for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:36:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:21760) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9Lp-00009J-2N for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:36:24 -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 8C87A7E44B for ; Tue, 22 Aug 2017 13:26:24 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0CC5B86E67; Tue, 22 Aug 2017 13:26:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8C87A7E44B 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: Tue, 22 Aug 2017 15:22:41 +0200 Message-Id: <20170822132255.23945-41-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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]); Tue, 22 Aug 2017 13:26:24 +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 40/54] docs: document schema configuration 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?= 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 --- docs/devel/qapi-code-gen.txt | 47 ++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 47 insertions(+) diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt index b653e86bff..94555c01eb 100644 --- a/docs/devel/qapi-code-gen.txt +++ b/docs/devel/qapi-code-gen.txt @@ -682,6 +682,53 @@ Example: Red Hat, Inc. controls redhat.com, and may th= erefore add a downstream command __com.redhat_drive-mirror. =20 =20 +=3D=3D=3D Configuring the schema =3D=3D=3D + +'struct', 'enum', 'union', 'alternate', 'command' and 'event' +top-level QAPI expressions can take a 'if' keyword like: + +{ 'struct': 'IfStruct', 'data': { 'foo': 'int' }, + 'if': 'defined(IF_STRUCT) && defined(FOO)' } + +Members can be exploded as dictionnary with 'type' & 'if' keys: + +{ 'struct': 'IfStruct', 'data': + { 'foo': 'int', + 'bar': { 'type': 'int', 'if': 'defined(IF_STRUCT_BAR)'} } } + +Enum values can be exploded as dictionnary with 'name' & 'if' keys: + +{ 'enum': 'IfEnum', 'data': + [ 'foo', + { 'name' : 'bar', 'if': 'defined(IF_ENUM_BAR)' } ] } + +The C code generators will wrap the corresponding lines with #if / #endif +pre-processor conditions for a given 'if' value. + +Example for enum values: + +enum IfEnum { + IF_ENUM_FOO, +#if defined(IF_ENUM_BAR) + IF_ENUM_BAR, +#endif /* defined(IF_ENUM_BAR) */ + IF_ENUM__MAX +} + +Please note that you are responsbile to ensure that the C code will +compile with an arbitrary combination of conditions, since the +generators are unable to check it at this point. + +Poisoined symbols like TARGET_I386 can be wrapped around a preliminary +NEED_CPU_H condition, using a list value, like so: + +{ ..., 'if': ['defined(NEED_CPU_H)', 'defined(TARGET_I386)'] } + +This will generate two consecutive #if lines to silence the C error +when compiling common code. FIXME: split the schema in various units +instead. + + =3D=3D Client JSON Protocol introspection =3D=3D =20 Clients of a Client JSON Protocol commonly need to figure out what --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 150341179647867.71246238079743; Tue, 22 Aug 2017 07:23:16 -0700 (PDT) Received: from localhost ([::1]:47674 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkA5L-00071S-AF for importer@patchew.org; Tue, 22 Aug 2017 10:23:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56328) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9MD-00021H-Eh for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:36:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9MA-0000Nb-6J for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:36:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43090) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9M9-0000MK-Sv for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:36:34 -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 E0B813A24C; Tue, 22 Aug 2017 13:26:31 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 24FAF7E660; Tue, 22 Aug 2017 13:26:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E0B813A24C 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: Tue, 22 Aug 2017 15:22:42 +0200 Message-Id: <20170822132255.23945-42-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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]); Tue, 22 Aug 2017 13:26:32 +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 41/54] qapi2texi: add 'If:' section to generated documentation 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?= , Markus Armbruster , Michael Roth 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" The documentation is generated only once, and doesn't know C pre-conditions. Add 'If:' sections for top-level entities. Signed-off-by: Marc-Andr=C3=A9 Lureau --- scripts/qapi2texi.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/scripts/qapi2texi.py b/scripts/qapi2texi.py index ae7920aa87..3a923ce438 100755 --- a/scripts/qapi2texi.py +++ b/scripts/qapi2texi.py @@ -132,7 +132,6 @@ def texi_enum_value(value): """Format a table of members item for an enumeration value""" return '@item @code{%s}\n' % value.name =20 - def texi_member(member, suffix=3D''): """Format a table of members item for an object type member""" typ =3D member.type.doc_type() @@ -175,7 +174,7 @@ def texi_members(doc, what, base, variants, member_func= ): return '\n@b{%s:}\n@table @asis\n%s@end table\n' % (what, items) =20 =20 -def texi_sections(doc): +def texi_sections(doc, ifcond): """Format additional sections following arguments""" body =3D '' for section in doc.sections: @@ -189,14 +188,16 @@ def texi_sections(doc): body +=3D '\n\n@b{%s:}\n' % name =20 body +=3D func(doc) + if ifcond: + body +=3D '\n\n@b{If:} @code{%s}' % ifcond return body =20 =20 -def texi_entity(doc, what, base=3DNone, variants=3DNone, +def texi_entity(doc, what, ifcond, base=3DNone, variants=3DNone, member_func=3Dtexi_member): return (texi_body(doc) + texi_members(doc, what, base, variants, member_func) - + texi_sections(doc)) + + texi_sections(doc, ifcond)) =20 =20 class QAPISchemaGenDocVisitor(qapi.QAPISchemaVisitor): @@ -213,7 +214,7 @@ class QAPISchemaGenDocVisitor(qapi.QAPISchemaVisitor): self.out +=3D '\n' self.out +=3D TYPE_FMT(type=3D'Enum', name=3Ddoc.symbol, - body=3Dtexi_entity(doc, 'Values', + body=3Dtexi_entity(doc, 'Values', ifcond, member_func=3Dtexi_enum_valu= e)) =20 def visit_object_type(self, name, info, base, members, variants, ifcon= d): @@ -224,7 +225,8 @@ class QAPISchemaGenDocVisitor(qapi.QAPISchemaVisitor): self.out +=3D '\n' self.out +=3D TYPE_FMT(type=3D'Object', name=3Ddoc.symbol, - body=3Dtexi_entity(doc, 'Members', base, vari= ants)) + body=3Dtexi_entity(doc, 'Members', ifcond, + base, variants)) =20 def visit_alternate_type(self, name, info, variants, ifcond): doc =3D self.cur_doc @@ -232,7 +234,7 @@ class QAPISchemaGenDocVisitor(qapi.QAPISchemaVisitor): self.out +=3D '\n' self.out +=3D TYPE_FMT(type=3D'Alternate', name=3Ddoc.symbol, - body=3Dtexi_entity(doc, 'Members')) + body=3Dtexi_entity(doc, 'Members', ifcond)) =20 def visit_command(self, name, info, arg_type, ret_type, gen, success_response, boxed, ifcond): @@ -242,9 +244,9 @@ class QAPISchemaGenDocVisitor(qapi.QAPISchemaVisitor): if boxed: body =3D texi_body(doc) body +=3D '\n@b{Arguments:} the members of @code{%s}' % arg_ty= pe.name - body +=3D texi_sections(doc) + body +=3D texi_sections(doc, ifcond) else: - body =3D texi_entity(doc, 'Arguments') + body =3D texi_entity(doc, 'Arguments', ifcond) self.out +=3D MSG_FMT(type=3D'Command', name=3Ddoc.symbol, body=3Dbody) @@ -255,7 +257,7 @@ class QAPISchemaGenDocVisitor(qapi.QAPISchemaVisitor): self.out +=3D '\n' self.out +=3D MSG_FMT(type=3D'Event', name=3Ddoc.symbol, - body=3Dtexi_entity(doc, 'Arguments')) + body=3Dtexi_entity(doc, 'Arguments', ifcond)) =20 def symbol(self, doc, entity): self.cur_doc =3D doc @@ -266,7 +268,7 @@ class QAPISchemaGenDocVisitor(qapi.QAPISchemaVisitor): assert not doc.args if self.out: self.out +=3D '\n' - self.out +=3D texi_body(doc) + texi_sections(doc) + self.out +=3D texi_body(doc) + texi_sections(doc, None) =20 =20 def texi_schema(schema): --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 1503409843906354.10292110643354; Tue, 22 Aug 2017 06:50:43 -0700 (PDT) Received: from localhost ([::1]:47137 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9Zq-0005hG-EQ for importer@patchew.org; Tue, 22 Aug 2017 09:50:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54890) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9I3-0006w0-T0 for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:32:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9Hy-0006Fc-2Y for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:32:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51648) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9Hx-0006F1-S5 for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:32:13 -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 739921E2ED; Tue, 22 Aug 2017 13:26:44 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 62F6D7DE34; Tue, 22 Aug 2017 13:26:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 739921E2ED 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: Tue, 22 Aug 2017 15:22:43 +0200 Message-Id: <20170822132255.23945-43-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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.30]); Tue, 22 Aug 2017 13:26: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 42/54] qapi2texi: add 'If:' condition to enum values 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?= , Markus Armbruster , Michael Roth 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 --- scripts/qapi2texi.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/qapi2texi.py b/scripts/qapi2texi.py index 3a923ce438..8959cb0cdf 100755 --- a/scripts/qapi2texi.py +++ b/scripts/qapi2texi.py @@ -130,7 +130,9 @@ def texi_body(doc): =20 def texi_enum_value(value): """Format a table of members item for an enumeration value""" - return '@item @code{%s}\n' % value.name + return '@item @code{%s}%s\n' % ( + value.name, + '\n@b{If:} @code{%s}\n' % value.ifcond if value.ifcond else '') =20 def texi_member(member, suffix=3D''): """Format a table of members item for an object type member""" --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 1503410716841973.6739573361066; Tue, 22 Aug 2017 07:05:16 -0700 (PDT) Received: from localhost ([::1]:47286 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9nv-0001HH-Nk for importer@patchew.org; Tue, 22 Aug 2017 10:05:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54816) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9Hp-0006gY-96 for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:32:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9Hm-00066c-20 for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:32:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44194) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9Hl-00065W-Rj for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:32:01 -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 76F298124F; Tue, 22 Aug 2017 13:26:52 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 011CC7E589; Tue, 22 Aug 2017 13:26:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 76F298124F 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: Tue, 22 Aug 2017 15:22:44 +0200 Message-Id: <20170822132255.23945-44-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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.25]); Tue, 22 Aug 2017 13:26: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 43/54] qapi2texi: add 'If:' condition to struct members 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?= , Markus Armbruster , Michael Roth 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 --- scripts/qapi2texi.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/qapi2texi.py b/scripts/qapi2texi.py index 8959cb0cdf..2c3e1d1a1c 100755 --- a/scripts/qapi2texi.py +++ b/scripts/qapi2texi.py @@ -138,9 +138,10 @@ def texi_member(member, suffix=3D''): """Format a table of members item for an object type member""" typ =3D member.type.doc_type() membertype =3D ': %s' % typ if typ else '' - return '@item @code{%s%s}%s%s\n' % ( + return '@item @code{%s%s}%s%s%s\n' % ( member.name, membertype, ' (optional)' if member.optional else '', + '\n@b{If:} @code{%s}\n' % member.ifcond if member.ifcond else '', suffix) =20 =20 --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 1503411588551278.33641656681175; Tue, 22 Aug 2017 07:19:48 -0700 (PDT) Received: from localhost ([::1]:47512 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkA1z-0004Jo-DH for importer@patchew.org; Tue, 22 Aug 2017 10:19:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56411) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9MU-0002GN-Cf for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:36:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9MP-0000Yk-2z for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:36:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41254) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9MO-0000YJ-Sa for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:36:49 -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 BA8B68046E; Tue, 22 Aug 2017 13:26:59 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0F42086E7F; Tue, 22 Aug 2017 13:26:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com BA8B68046E 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: Tue, 22 Aug 2017 15:22:45 +0200 Message-Id: <20170822132255.23945-45-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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.28]); Tue, 22 Aug 2017 13:26:59 +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 44/54] qapi2texi: add condition to variants 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?= , Markus Armbruster , Michael Roth 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 --- scripts/qapi2texi.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/qapi2texi.py b/scripts/qapi2texi.py index 2c3e1d1a1c..49a54d41db 100755 --- a/scripts/qapi2texi.py +++ b/scripts/qapi2texi.py @@ -163,8 +163,9 @@ def texi_members(doc, what, base, variants, member_func= ): items +=3D '@item The members of @code{%s}\n' % base.doc_type() if variants: for v in variants.variants: - when =3D ' when @code{%s} is @t{"%s"}' % ( - variants.tag_member.name, v.name) + when =3D ' when @code{%s} is @t{"%s"}%s' % ( + variants.tag_member.name, v.name, + ' (and @code{%s})' % v.ifcond if v.ifcond else '') if v.type.is_implicit(): assert not v.type.base and not v.type.variants for m in v.type.local_members: --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 1503410038166927.041592096198; Tue, 22 Aug 2017 06:53:58 -0700 (PDT) Received: from localhost ([::1]:47177 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9cy-0000Ei-Rd for importer@patchew.org; Tue, 22 Aug 2017 09:53:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55285) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9JR-000858-Hx for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9JP-00073Y-9Q for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38472) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9JP-00072O-03 for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:43 -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 55890859FA for ; Tue, 22 Aug 2017 13:27:09 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id B353761786; Tue, 22 Aug 2017 13:27:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 55890859FA 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: Tue, 22 Aug 2017 15:22:46 +0200 Message-Id: <20170822132255.23945-46-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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.26]); Tue, 22 Aug 2017 13:27: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 45/54] qapi: add conditions to VNC type/commands/events on the schema 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?= , "Dr. David Alan Gilbert" , Markus Armbruster 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" Add #if defined(CONFIG_VNC) in generated code, and adjust the qmp/hmp code accordingly. Commands made conditional: * query-vnc, query-vnc-servers, change-vnc-password Before the patch, the commands for !CONFIG_VNC are stubs that fail like this: {"error": {"class": "GenericError", "desc": "The feature 'vnc' is not enabled"}} Afterwards, they fail like this: {"error": {"class": "CommandNotFound", "desc": "The command FOO has not been found"}} I call that an improvement, because it lets clients distinguish between command unavailable (class CommandNotFound) and command failed (class GenericError). Events made conditional: * VNC_CONNECTED, VNC_INITIALIZED, VNC_DISCONNECTED Enum made conditional: * QCryptoCipherAlgorithm # @des-rfb: RFB specific variant of single DES. Do not use except in VN= C. Occurrences of VNC (case insensitive) in the schema that aren't covered by this change: * add_client Command has other uses, including "socket bases character devices". These are unconditional as far as I can tell. * set_password, expire_password In theory, these commands could be used for managing any service's password. In practice, they're used for VNC and SPICE services. They're documented for "remote display session" / "remote display server". The service is selected by argument @protocol. The code special-cases protocol-specific argument checking, then calls a protocol-specific function to do the work. If it fails, the command fails with "Could not set password". It does when the service isn't compiled in (it's a stub then). We could make these commands conditional on the conjunction of all services [currently: defined(CONFIG_VNC) || defined(CONFIG_SPICE)], but I doubt it's worthwhile. * change Command has other uses, namely changing media. This patch inlines a stub; no functional change. Signed-off-by: Marc-Andr=C3=A9 Lureau --- qapi-schema.json | 34 ++++++++++++++++++++++------------ qapi/crypto.json | 3 ++- qapi/event.json | 9 ++++++--- crypto/cipher-builtin.c | 9 +++++++++ crypto/cipher-gcrypt.c | 10 ++++++++-- crypto/cipher-nettle.c | 14 +++++++++++--- crypto/cipher.c | 13 +++++++++++-- hmp.c | 9 ++++++++- qmp.c | 30 ++++-------------------------- hmp-commands-info.hx | 2 ++ 10 files changed, 83 insertions(+), 50 deletions(-) diff --git a/qapi-schema.json b/qapi-schema.json index 802ea53d00..4ffbe1d9ff 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -1660,7 +1660,8 @@ 'data': { 'host': 'str', 'service': 'str', 'family': 'NetworkAddressFamily', - 'websocket': 'bool' } } + 'websocket': 'bool' }, + 'if': 'defined(CONFIG_VNC)' } =20 ## # @VncServerInfo: @@ -1674,7 +1675,8 @@ ## { 'struct': 'VncServerInfo', 'base': 'VncBasicInfo', - 'data': { '*auth': 'str' } } + 'data': { '*auth': 'str' }, + 'if': 'defined(CONFIG_VNC)' } =20 ## # @VncClientInfo: @@ -1691,7 +1693,8 @@ ## { 'struct': 'VncClientInfo', 'base': 'VncBasicInfo', - 'data': { '*x509_dname': 'str', '*sasl_username': 'str' } } + 'data': { '*x509_dname': 'str', '*sasl_username': 'str' }, + 'if': 'defined(CONFIG_VNC)' } =20 ## # @VncInfo: @@ -1732,7 +1735,8 @@ { 'struct': 'VncInfo', 'data': {'enabled': 'bool', '*host': 'str', '*family': 'NetworkAddressFamily', - '*service': 'str', '*auth': 'str', '*clients': ['VncClientInfo'= ]} } + '*service': 'str', '*auth': 'str', '*clients': ['VncClientInfo'= ]}, + 'if': 'defined(CONFIG_VNC)' } =20 ## # @VncPrimaryAuth: @@ -1743,7 +1747,8 @@ ## { 'enum': 'VncPrimaryAuth', 'data': [ 'none', 'vnc', 'ra2', 'ra2ne', 'tight', 'ultra', - 'tls', 'vencrypt', 'sasl' ] } + 'tls', 'vencrypt', 'sasl' ], + 'if': 'defined(CONFIG_VNC)' } =20 ## # @VncVencryptSubAuth: @@ -1757,7 +1762,8 @@ 'tls-none', 'x509-none', 'tls-vnc', 'x509-vnc', 'tls-plain', 'x509-plain', - 'tls-sasl', 'x509-sasl' ] } + 'tls-sasl', 'x509-sasl' ], + 'if': 'defined(CONFIG_VNC)' } =20 =20 ## @@ -1775,7 +1781,8 @@ { 'struct': 'VncServerInfo2', 'base': 'VncBasicInfo', 'data': { 'auth' : 'VncPrimaryAuth', - '*vencrypt' : 'VncVencryptSubAuth' } } + '*vencrypt' : 'VncVencryptSubAuth' }, + 'if': 'defined(CONFIG_VNC)' } =20 =20 ## @@ -1808,7 +1815,8 @@ 'clients' : ['VncClientInfo'], 'auth' : 'VncPrimaryAuth', '*vencrypt' : 'VncVencryptSubAuth', - '*display' : 'str' } } + '*display' : 'str' }, + 'if': 'defined(CONFIG_VNC)' } =20 ## # @query-vnc: @@ -1839,7 +1847,8 @@ # } # ## -{ 'command': 'query-vnc', 'returns': 'VncInfo' } +{ 'command': 'query-vnc', 'returns': 'VncInfo', + 'if': 'defined(CONFIG_VNC)' } =20 ## # @query-vnc-servers: @@ -1850,7 +1859,8 @@ # # Since: 2.3 ## -{ 'command': 'query-vnc-servers', 'returns': ['VncInfo2'] } +{ 'command': 'query-vnc-servers', 'returns': ['VncInfo2'], + 'if': 'defined(CONFIG_VNC)' } =20 ## # @SpiceBasicInfo: @@ -3077,8 +3087,8 @@ # Notes: An empty password in this command will set the password to the e= mpty # string. Existing clients are unaffected by executing this comma= nd. ## -{ 'command': 'change-vnc-password', 'data': {'password': 'str'} } - +{ 'command': 'change-vnc-password', 'data': {'password': 'str'}, + 'if': 'defined(CONFIG_VNC)' } ## # @change: # diff --git a/qapi/crypto.json b/qapi/crypto.json index 6b6fde367a..b9bfff202c 100644 --- a/qapi/crypto.json +++ b/qapi/crypto.json @@ -79,7 +79,8 @@ { 'enum': 'QCryptoCipherAlgorithm', 'prefix': 'QCRYPTO_CIPHER_ALG', 'data': ['aes-128', 'aes-192', 'aes-256', - 'des-rfb', '3des', + { 'name': 'des-rfb', 'if': 'defined(CONFIG_VNC)' }, + '3des', 'cast5-128', 'serpent-128', 'serpent-192', 'serpent-256', 'twofish-128', 'twofish-192', 'twofish-256']} diff --git a/qapi/event.json b/qapi/event.json index 6d22b025cc..c8b8e9f384 100644 --- a/qapi/event.json +++ b/qapi/event.json @@ -263,7 +263,8 @@ ## { 'event': 'VNC_CONNECTED', 'data': { 'server': 'VncServerInfo', - 'client': 'VncBasicInfo' } } + 'client': 'VncBasicInfo' }, + 'if': 'defined(CONFIG_VNC)' } =20 ## # @VNC_INITIALIZED: @@ -290,7 +291,8 @@ ## { 'event': 'VNC_INITIALIZED', 'data': { 'server': 'VncServerInfo', - 'client': 'VncClientInfo' } } + 'client': 'VncClientInfo' }, + 'if': 'defined(CONFIG_VNC)' } =20 ## # @VNC_DISCONNECTED: @@ -316,7 +318,8 @@ ## { 'event': 'VNC_DISCONNECTED', 'data': { 'server': 'VncServerInfo', - 'client': 'VncClientInfo' } } + 'client': 'VncClientInfo' }, + 'if': 'defined(CONFIG_VNC)' } =20 ## # @SPICE_CONNECTED: diff --git a/crypto/cipher-builtin.c b/crypto/cipher-builtin.c index e956cc5a53..647bcf3247 100644 --- a/crypto/cipher-builtin.c +++ b/crypto/cipher-builtin.c @@ -35,17 +35,22 @@ struct QCryptoCipherBuiltinAES { QCryptoCipherBuiltinAESContext key_tweak; uint8_t iv[AES_BLOCK_SIZE]; }; + +#ifdef CONFIG_VNC typedef struct QCryptoCipherBuiltinDESRFB QCryptoCipherBuiltinDESRFB; struct QCryptoCipherBuiltinDESRFB { uint8_t *key; size_t nkey; }; +#endif =20 typedef struct QCryptoCipherBuiltin QCryptoCipherBuiltin; struct QCryptoCipherBuiltin { union { QCryptoCipherBuiltinAES aes; +#ifdef CONFIG_VNC QCryptoCipherBuiltinDESRFB desrfb; +#endif } state; size_t blocksize; void (*free)(QCryptoCipher *cipher); @@ -403,7 +408,9 @@ bool qcrypto_cipher_supports(QCryptoCipherAlgorithm alg, QCryptoCipherMode mode) { switch (alg) { +#ifdef CONFIG_VNC case QCRYPTO_CIPHER_ALG_DES_RFB: +#endif case QCRYPTO_CIPHER_ALG_AES_128: case QCRYPTO_CIPHER_ALG_AES_192: case QCRYPTO_CIPHER_ALG_AES_256: @@ -449,9 +456,11 @@ static QCryptoCipherBuiltin *qcrypto_cipher_ctx_new(QC= ryptoCipherAlgorithm alg, } =20 switch (alg) { +#ifdef CONFIG_VNC case QCRYPTO_CIPHER_ALG_DES_RFB: ctxt =3D qcrypto_cipher_init_des_rfb(mode, key, nkey, errp); break; +#endif case QCRYPTO_CIPHER_ALG_AES_128: case QCRYPTO_CIPHER_ALG_AES_192: case QCRYPTO_CIPHER_ALG_AES_256: diff --git a/crypto/cipher-gcrypt.c b/crypto/cipher-gcrypt.c index 3e46ee7502..18c01ca424 100644 --- a/crypto/cipher-gcrypt.c +++ b/crypto/cipher-gcrypt.c @@ -29,7 +29,9 @@ bool qcrypto_cipher_supports(QCryptoCipherAlgorithm alg, QCryptoCipherMode mode) { switch (alg) { +#ifdef CONFIG_VNC case QCRYPTO_CIPHER_ALG_DES_RFB: +#endif case QCRYPTO_CIPHER_ALG_3DES: case QCRYPTO_CIPHER_ALG_AES_128: case QCRYPTO_CIPHER_ALG_AES_192: @@ -114,10 +116,11 @@ static QCryptoCipherGcrypt *qcrypto_cipher_ctx_new(QC= ryptoCipherAlgorithm alg, } =20 switch (alg) { +#ifdef CONFIG_VNC case QCRYPTO_CIPHER_ALG_DES_RFB: gcryalg =3D GCRY_CIPHER_DES; break; - +#endif case QCRYPTO_CIPHER_ALG_3DES: gcryalg =3D GCRY_CIPHER_3DES; break; @@ -181,6 +184,7 @@ static QCryptoCipherGcrypt *qcrypto_cipher_ctx_new(QCry= ptoCipherAlgorithm alg, } } =20 +#ifdef CONFIG_VNC if (alg =3D=3D QCRYPTO_CIPHER_ALG_DES_RFB) { /* We're using standard DES cipher from gcrypt, so we need * to munge the key so that the results are the same as the @@ -190,7 +194,9 @@ static QCryptoCipherGcrypt *qcrypto_cipher_ctx_new(QCry= ptoCipherAlgorithm alg, err =3D gcry_cipher_setkey(ctx->handle, rfbkey, nkey); g_free(rfbkey); ctx->blocksize =3D 8; - } else { + } else +#endif /* CONFIG_VNC */ + { if (mode =3D=3D QCRYPTO_CIPHER_MODE_XTS) { nkey /=3D 2; err =3D gcry_cipher_setkey(ctx->handle, key, nkey); diff --git a/crypto/cipher-nettle.c b/crypto/cipher-nettle.c index 5e70c7984a..7b14f23f7e 100644 --- a/crypto/cipher-nettle.c +++ b/crypto/cipher-nettle.c @@ -67,6 +67,7 @@ static void aes_decrypt_native(cipher_ctx_t ctx, cipher_l= ength_t length, aes_decrypt(&aesctx->dec, length, dst, src); } =20 +#ifdef CONFIG_VNC static void des_encrypt_native(cipher_ctx_t ctx, cipher_length_t length, uint8_t *dst, const uint8_t *src) { @@ -78,6 +79,7 @@ static void des_decrypt_native(cipher_ctx_t ctx, cipher_l= ength_t length, { des_decrypt(ctx, length, dst, src); } +#endif =20 static void des3_encrypt_native(cipher_ctx_t ctx, cipher_length_t length, uint8_t *dst, const uint8_t *src) @@ -141,6 +143,7 @@ static void aes_decrypt_wrapper(const void *ctx, size_t= length, aes_decrypt(&aesctx->dec, length, dst, src); } =20 +#ifdef CONFIG_VNC static void des_encrypt_wrapper(const void *ctx, size_t length, uint8_t *dst, const uint8_t *src) { @@ -152,6 +155,7 @@ static void des_decrypt_wrapper(const void *ctx, size_t= length, { des_decrypt(ctx, length, dst, src); } +#endif =20 static void des3_encrypt_wrapper(const void *ctx, size_t length, uint8_t *dst, const uint8_t *src) @@ -221,7 +225,9 @@ bool qcrypto_cipher_supports(QCryptoCipherAlgorithm alg, QCryptoCipherMode mode) { switch (alg) { +#ifdef CONFIG_VNC case QCRYPTO_CIPHER_ALG_DES_RFB: +#endif case QCRYPTO_CIPHER_ALG_3DES: case QCRYPTO_CIPHER_ALG_AES_128: case QCRYPTO_CIPHER_ALG_AES_192: @@ -271,7 +277,6 @@ static QCryptoCipherNettle *qcrypto_cipher_ctx_new(QCry= ptoCipherAlgorithm alg, Error **errp) { QCryptoCipherNettle *ctx; - uint8_t *rfbkey; =20 switch (mode) { case QCRYPTO_CIPHER_MODE_ECB: @@ -292,7 +297,9 @@ static QCryptoCipherNettle *qcrypto_cipher_ctx_new(QCry= ptoCipherAlgorithm alg, ctx =3D g_new0(QCryptoCipherNettle, 1); =20 switch (alg) { - case QCRYPTO_CIPHER_ALG_DES_RFB: +#ifdef CONFIG_VNC + case QCRYPTO_CIPHER_ALG_DES_RFB: { + uint8_t *rfbkey; ctx->ctx =3D g_new0(struct des_ctx, 1); rfbkey =3D qcrypto_cipher_munge_des_rfb_key(key, nkey); des_set_key(ctx->ctx, rfbkey); @@ -305,7 +312,8 @@ static QCryptoCipherNettle *qcrypto_cipher_ctx_new(QCry= ptoCipherAlgorithm alg, =20 ctx->blocksize =3D DES_BLOCK_SIZE; break; - + } +#endif case QCRYPTO_CIPHER_ALG_3DES: ctx->ctx =3D g_new0(struct des3_ctx, 1); des3_set_key(ctx->ctx, key); diff --git a/crypto/cipher.c b/crypto/cipher.c index 43291cba7e..3e39882b7c 100644 --- a/crypto/cipher.c +++ b/crypto/cipher.c @@ -29,7 +29,9 @@ static size_t alg_key_len[QCRYPTO_CIPHER_ALG__MAX] =3D { [QCRYPTO_CIPHER_ALG_AES_128] =3D 16, [QCRYPTO_CIPHER_ALG_AES_192] =3D 24, [QCRYPTO_CIPHER_ALG_AES_256] =3D 32, +#ifdef CONFIG_VNC [QCRYPTO_CIPHER_ALG_DES_RFB] =3D 8, +#endif [QCRYPTO_CIPHER_ALG_3DES] =3D 24, [QCRYPTO_CIPHER_ALG_CAST5_128] =3D 16, [QCRYPTO_CIPHER_ALG_SERPENT_128] =3D 16, @@ -44,7 +46,9 @@ static size_t alg_block_len[QCRYPTO_CIPHER_ALG__MAX] =3D { [QCRYPTO_CIPHER_ALG_AES_128] =3D 16, [QCRYPTO_CIPHER_ALG_AES_192] =3D 16, [QCRYPTO_CIPHER_ALG_AES_256] =3D 16, +#ifdef CONFIG_VNC [QCRYPTO_CIPHER_ALG_DES_RFB] =3D 8, +#endif [QCRYPTO_CIPHER_ALG_3DES] =3D 8, [QCRYPTO_CIPHER_ALG_CAST5_128] =3D 8, [QCRYPTO_CIPHER_ALG_SERPENT_128] =3D 16, @@ -107,8 +111,11 @@ qcrypto_cipher_validate_key_length(QCryptoCipherAlgori= thm alg, } =20 if (mode =3D=3D QCRYPTO_CIPHER_MODE_XTS) { - if (alg =3D=3D QCRYPTO_CIPHER_ALG_DES_RFB - || alg =3D=3D QCRYPTO_CIPHER_ALG_3DES) { + if ( +#ifdef CONFIG_VNC + alg =3D=3D QCRYPTO_CIPHER_ALG_DES_RFB || +#endif + alg =3D=3D QCRYPTO_CIPHER_ALG_3DES) { error_setg(errp, "XTS mode not compatible with DES-RFB/3DES"); return false; } @@ -132,6 +139,7 @@ qcrypto_cipher_validate_key_length(QCryptoCipherAlgorit= hm alg, return true; } =20 +#if defined(CONFIG_VNC) #if defined(CONFIG_GCRYPT) || defined(CONFIG_NETTLE) static uint8_t * qcrypto_cipher_munge_des_rfb_key(const uint8_t *key, @@ -149,6 +157,7 @@ qcrypto_cipher_munge_des_rfb_key(const uint8_t *key, return ret; } #endif /* CONFIG_GCRYPT || CONFIG_NETTLE */ +#endif /* CONFIG_VNC */ =20 #ifdef CONFIG_GCRYPT #include "crypto/cipher-gcrypt.c" diff --git a/hmp.c b/hmp.c index 0eb318f938..bb0a695f2d 100644 --- a/hmp.c +++ b/hmp.c @@ -620,6 +620,7 @@ void hmp_info_blockstats(Monitor *mon, const QDict *qdi= ct) qapi_free_BlockStatsList(stats_list); } =20 +#ifdef CONFIG_VNC /* Helper for hmp_info_vnc_clients, _servers */ static void hmp_info_VncBasicInfo(Monitor *mon, VncBasicInfo *info, const char *name) @@ -708,6 +709,7 @@ void hmp_info_vnc(Monitor *mon, const QDict *qdict) qapi_free_VncInfo2List(info2l); =20 } +#endif =20 #ifdef CONFIG_SPICE void hmp_info_spice(Monitor *mon, const QDict *qdict) @@ -1718,12 +1720,14 @@ void hmp_eject(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, &err); } =20 +#ifdef CONFIG_VNC static void hmp_change_read_arg(void *opaque, const char *password, void *readline_opaque) { qmp_change_vnc_password(password, NULL); monitor_read_command(opaque, 1); } +#endif =20 void hmp_change(Monitor *mon, const QDict *qdict) { @@ -1734,6 +1738,7 @@ void hmp_change(Monitor *mon, const QDict *qdict) BlockdevChangeReadOnlyMode read_only_mode =3D 0; Error *err =3D NULL; =20 +#ifdef CONFIG_VNC if (strcmp(device, "vnc") =3D=3D 0) { if (read_only) { monitor_printf(mon, @@ -1748,7 +1753,9 @@ void hmp_change(Monitor *mon, const QDict *qdict) } } qmp_change("vnc", target, !!arg, arg, &err); - } else { + } else +#endif + { if (read_only) { read_only_mode =3D qapi_enum_parse(&BlockdevChangeReadOnlyMode= _lookup, read_only, BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err); diff --git a/qmp.c b/qmp.c index b86201e349..2c90dacb56 100644 --- a/qmp.c +++ b/qmp.c @@ -130,22 +130,6 @@ void qmp_cpu_add(int64_t id, Error **errp) } } =20 -#ifndef CONFIG_VNC -/* If VNC support is enabled, the "true" query-vnc command is - defined in the VNC subsystem */ -VncInfo *qmp_query_vnc(Error **errp) -{ - error_setg(errp, QERR_FEATURE_DISABLED, "vnc"); - return NULL; -}; - -VncInfo2List *qmp_query_vnc_servers(Error **errp) -{ - error_setg(errp, QERR_FEATURE_DISABLED, "vnc"); - return NULL; -}; -#endif - #ifndef CONFIG_SPICE /* * qmp-commands.hx ensures that QMP command query-spice exists only @@ -403,23 +387,17 @@ static void qmp_change_vnc(const char *target, bool h= as_arg, const char *arg, qmp_change_vnc_listen(target, errp); } } -#else -void qmp_change_vnc_password(const char *password, Error **errp) -{ - error_setg(errp, QERR_FEATURE_DISABLED, "vnc"); -} -static void qmp_change_vnc(const char *target, bool has_arg, const char *a= rg, - Error **errp) -{ - error_setg(errp, QERR_FEATURE_DISABLED, "vnc"); -} #endif /* !CONFIG_VNC */ =20 void qmp_change(const char *device, const char *target, bool has_arg, const char *arg, Error **errp) { if (strcmp(device, "vnc") =3D=3D 0) { +#ifdef CONFIG_VNC qmp_change_vnc(target, has_arg, arg, errp); +#else + error_setg(errp, QERR_FEATURE_DISABLED, "vnc"); +#endif } else { qmp_blockdev_change_medium(true, device, false, NULL, target, has_arg, arg, false, 0, errp); diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index d9df238a5f..2fb7a556a3 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -419,6 +419,7 @@ STEXI Show which guest mouse is receiving events. ETEXI =20 +#if defined(CONFIG_VNC) { .name =3D "vnc", .args_type =3D "", @@ -426,6 +427,7 @@ ETEXI .help =3D "show the vnc server status", .cmd =3D hmp_info_vnc, }, +#endif =20 STEXI @item info vnc --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 1503411544874496.18586725283797; Tue, 22 Aug 2017 07:19:04 -0700 (PDT) Received: from localhost ([::1]:47510 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkA1H-0003iG-DA for importer@patchew.org; Tue, 22 Aug 2017 10:19:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56231) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9M3-0001st-Cz for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:36:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9M0-0000Cs-4P for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:36:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52588) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9Lp-00009I-2O for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:36:24 -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 39B5A7E446 for ; Tue, 22 Aug 2017 13:27:13 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id F0C2F86E68; Tue, 22 Aug 2017 13:27:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 39B5A7E446 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: Tue, 22 Aug 2017 15:22:47 +0200 Message-Id: <20170822132255.23945-47-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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]); Tue, 22 Aug 2017 13:27:13 +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 46/54] qapi: add conditions to SPICE type/commands/events on the schema 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?= , Markus Armbruster , "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" Add #if defined(CONFIG_SPICE) in generated code, and adjust the qmp/hmp code accordingly. Signed-off-by: Marc-Andr=C3=A9 Lureau --- qapi-schema.json | 28 ++++++++++++++++++---------- qapi/event.json | 12 ++++++++---- monitor.c | 3 --- qmp.c | 16 ---------------- 4 files changed, 26 insertions(+), 33 deletions(-) diff --git a/qapi-schema.json b/qapi-schema.json index 4ffbe1d9ff..08e96bd93f 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -1878,7 +1878,8 @@ { 'struct': 'SpiceBasicInfo', 'data': { 'host': 'str', 'port': 'str', - 'family': 'NetworkAddressFamily' } } + 'family': 'NetworkAddressFamily' }, + 'if': 'defined(CONFIG_SPICE)' } =20 ## # @SpiceServerInfo: @@ -1891,7 +1892,8 @@ ## { 'struct': 'SpiceServerInfo', 'base': 'SpiceBasicInfo', - 'data': { '*auth': 'str' } } + 'data': { '*auth': 'str' }, + 'if': 'defined(CONFIG_SPICE)' } =20 ## # @SpiceChannel: @@ -1916,7 +1918,8 @@ { 'struct': 'SpiceChannel', 'base': 'SpiceBasicInfo', 'data': {'connection-id': 'int', 'channel-type': 'int', 'channel-id': 'i= nt', - 'tls': 'bool'} } + 'tls': 'bool'}, + 'if': 'defined(CONFIG_SPICE)' } =20 ## # @SpiceQueryMouseMode: @@ -1935,7 +1938,8 @@ # Since: 1.1 ## { 'enum': 'SpiceQueryMouseMode', - 'data': [ 'client', 'server', 'unknown' ] } + 'data': [ 'client', 'server', 'unknown' ], + 'if': 'defined(CONFIG_SPICE)' } =20 ## # @SpiceInfo: @@ -1972,7 +1976,8 @@ { 'struct': 'SpiceInfo', 'data': {'enabled': 'bool', 'migrated': 'bool', '*host': 'str', '*port':= 'int', '*tls-port': 'int', '*auth': 'str', '*compiled-version': 'str', - 'mouse-mode': 'SpiceQueryMouseMode', '*channels': ['SpiceChanne= l']} } + 'mouse-mode': 'SpiceQueryMouseMode', '*channels': ['SpiceChanne= l']}, + 'if': 'defined(CONFIG_SPICE)' } =20 ## # @query-spice: @@ -2017,7 +2022,8 @@ # } # ## -{ 'command': 'query-spice', 'returns': 'SpiceInfo' } +{ 'command': 'query-spice', 'returns': 'SpiceInfo', + 'if': 'defined(CONFIG_SPICE)' } =20 ## # @BalloonInfo: @@ -5091,7 +5097,8 @@ # Since: 1.5 ## { 'struct': 'ChardevSpiceChannel', 'data': { 'type' : 'str' }, - 'base': 'ChardevCommon' } + 'base': 'ChardevCommon', + 'if': 'defined(CONFIG_SPICE)' } =20 ## # @ChardevSpicePort: @@ -5103,7 +5110,8 @@ # Since: 1.5 ## { 'struct': 'ChardevSpicePort', 'data': { 'fqdn' : 'str' }, - 'base': 'ChardevCommon' } + 'base': 'ChardevCommon', + 'if': 'defined(CONFIG_SPICE)' } =20 ## # @ChardevVC: @@ -5157,8 +5165,8 @@ 'testdev': 'ChardevCommon', 'stdio' : 'ChardevStdio', 'console': 'ChardevCommon', - 'spicevmc' : 'ChardevSpiceChannel', - 'spiceport' : 'ChardevSpicePort', + 'spicevmc' : { 'type': 'ChardevSpic= eChannel', 'if': 'defined(CONFIG_SPICE)' }, + 'spiceport' : { 'type': 'ChardevSpi= cePort', 'if': 'defined(CONFIG_SPICE)' }, 'vc' : 'ChardevVC', 'ringbuf': 'ChardevRingbuf', # next one is just for compatibility diff --git a/qapi/event.json b/qapi/event.json index c8b8e9f384..ff59551914 100644 --- a/qapi/event.json +++ b/qapi/event.json @@ -344,7 +344,8 @@ ## { 'event': 'SPICE_CONNECTED', 'data': { 'server': 'SpiceBasicInfo', - 'client': 'SpiceBasicInfo' } } + 'client': 'SpiceBasicInfo' }, + 'if': 'defined(CONFIG_SPICE)' } =20 ## # @SPICE_INITIALIZED: @@ -372,7 +373,8 @@ ## { 'event': 'SPICE_INITIALIZED', 'data': { 'server': 'SpiceServerInfo', - 'client': 'SpiceChannel' } } + 'client': 'SpiceChannel' }, + 'if': 'defined(CONFIG_SPICE)' } =20 ## # @SPICE_DISCONNECTED: @@ -397,7 +399,8 @@ ## { 'event': 'SPICE_DISCONNECTED', 'data': { 'server': 'SpiceBasicInfo', - 'client': 'SpiceBasicInfo' } } + 'client': 'SpiceBasicInfo' }, + 'if': 'defined(CONFIG_SPICE)' } =20 ## # @SPICE_MIGRATE_COMPLETED: @@ -412,7 +415,8 @@ # "event": "SPICE_MIGRATE_COMPLETED" } # ## -{ 'event': 'SPICE_MIGRATE_COMPLETED' } +{ 'event': 'SPICE_MIGRATE_COMPLETED', + 'if': 'defined(CONFIG_SPICE)' } =20 ## # @MIGRATION: diff --git a/monitor.c b/monitor.c index 228f246fcc..e5a179d32e 100644 --- a/monitor.c +++ b/monitor.c @@ -971,9 +971,6 @@ static void qmp_query_qmp_schema(QDict *qdict, QObject = **ret_data, */ static void qmp_unregister_commands_hack(void) { -#ifndef CONFIG_SPICE - qmp_unregister_command(&qmp_commands, "query-spice"); -#endif #ifndef CONFIG_REPLICATION qmp_unregister_command(&qmp_commands, "xen-set-replication"); qmp_unregister_command(&qmp_commands, "query-xen-replication-status"); diff --git a/qmp.c b/qmp.c index 2c90dacb56..90816ba283 100644 --- a/qmp.c +++ b/qmp.c @@ -130,22 +130,6 @@ void qmp_cpu_add(int64_t id, Error **errp) } } =20 -#ifndef CONFIG_SPICE -/* - * qmp-commands.hx ensures that QMP command query-spice exists only - * #ifdef CONFIG_SPICE. Necessary for an accurate query-commands - * result. However, the QAPI schema is blissfully unaware of that, - * and the QAPI code generator happily generates a dead - * qmp_marshal_query_spice() that calls qmp_query_spice(). Provide it - * one, or else linking fails. FIXME Educate the QAPI schema on - * CONFIG_SPICE. - */ -SpiceInfo *qmp_query_spice(Error **errp) -{ - abort(); -}; -#endif - void qmp_cont(Error **errp) { BlockBackend *blk; --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 1503412202533856.1453431399927; Tue, 22 Aug 2017 07:30:02 -0700 (PDT) Received: from localhost ([::1]:47930 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkABt-0004Rz-3F for importer@patchew.org; Tue, 22 Aug 2017 10:30:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56413) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9MU-0002Ge-Kw for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:36:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9MP-0000Yr-5Q for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:36:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41256) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9MO-0000YI-SC for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:36:49 -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 E85AD7EAA2; Tue, 22 Aug 2017 13:27:16 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4C28C617A9; Tue, 22 Aug 2017 13:27:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E85AD7EAA2 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: Tue, 22 Aug 2017 15:22:48 +0200 Message-Id: <20170822132255.23945-48-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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]); Tue, 22 Aug 2017 13:27:17 +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 47/54] qapi: add conditions to REPLICATION type/commands on the schema 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: zhanghailiang , Juan Quintela , Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= 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" Add #if defined(CONFIG_REPLICATION) in generated code, and adjust the code accordingly. Made conditional: * xen-set-replication, query-xen-replication-status, xen-colo-do-checkpoint Before the patch, we first register the commands unconditionally in generated code (requires a stub), then conditionally unregister in qmp_unregister_commands_hack(). Afterwards, we register only when CONFIG_REPLICATION. The command fails exactly the same, with CommandNotFound. Improvement, because now query-qmp-schema is accurate, and we're one step close to killing qmp_unregister_commands_hack(). * enum BlockdevDriver value "replication" in command blockdev-add As well as enum BlockdevDriver value @replication BlockdevOptions variant @replication, BlockdevOptionsReplication, BlockdevOptionsReplicationMode. Signed-off-by: Marc-Andr=C3=A9 Lureau --- qapi-schema.json | 12 ++++++++---- qapi/block-core.json | 13 +++++++++---- migration/colo.c | 14 ++------------ monitor.c | 5 ----- 4 files changed, 19 insertions(+), 25 deletions(-) diff --git a/qapi-schema.json b/qapi-schema.json index 08e96bd93f..1091a80fd3 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -6361,7 +6361,8 @@ # Since: 2.9 ## { 'command': 'xen-set-replication', - 'data': { 'enable': 'bool', 'primary': 'bool', '*failover' : 'bool' } } + 'data': { 'enable': 'bool', 'primary': 'bool', '*failover' : 'bool' }, + 'if': 'defined(CONFIG_REPLICATION)' } =20 ## # @ReplicationStatus: @@ -6376,7 +6377,8 @@ # Since: 2.9 ## { 'struct': 'ReplicationStatus', - 'data': { 'error': 'bool', '*desc': 'str' } } + 'data': { 'error': 'bool', '*desc': 'str' }, + 'if': 'defined(CONFIG_REPLICATION)' } =20 ## # @query-xen-replication-status: @@ -6393,7 +6395,8 @@ # Since: 2.9 ## { 'command': 'query-xen-replication-status', - 'returns': 'ReplicationStatus' } + 'returns': 'ReplicationStatus', + 'if': 'defined(CONFIG_REPLICATION)' } =20 ## # @xen-colo-do-checkpoint: @@ -6409,7 +6412,8 @@ # # Since: 2.9 ## -{ 'command': 'xen-colo-do-checkpoint' } +{ 'command': 'xen-colo-do-checkpoint', + 'if': 'defined(CONFIG_REPLICATION)' } =20 ## # @GICCapability: diff --git a/qapi/block-core.json b/qapi/block-core.json index 833c602150..f9a0834190 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2182,7 +2182,9 @@ 'dmg', 'file', 'ftp', 'ftps', 'gluster', 'host_cdrom', 'host_device', 'http', 'https', 'iscsi', 'luks', 'nbd', 'nfs', 'null-aio', 'null-co', 'parallels', 'qcow', 'qcow2', 'qed', - 'quorum', 'raw', 'rbd', 'replication', 'sheepdog', 'ssh', + 'quorum', 'raw', 'rbd', + { 'name': 'replication', 'if': 'defined(CONFIG_REPLICATION)' }, + 'sheepdog', 'ssh', 'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat', 'vxhs' ] } =20 ## @@ -2805,7 +2807,8 @@ # # Since: 2.9 ## -{ 'enum' : 'ReplicationMode', 'data' : [ 'primary', 'secondary' ] } +{ 'enum' : 'ReplicationMode', 'data' : [ 'primary', 'secondary' ], + 'if': 'defined(CONFIG_REPLICATION)' } =20 ## # @BlockdevOptionsReplication: @@ -2823,7 +2826,8 @@ { 'struct': 'BlockdevOptionsReplication', 'base': 'BlockdevOptionsGenericFormat', 'data': { 'mode': 'ReplicationMode', - '*top-id': 'str' } } + '*top-id': 'str' }, + 'if': 'defined(CONFIG_REPLICATION)' } =20 ## # @NFSTransport: @@ -3104,7 +3108,8 @@ 'quorum': 'BlockdevOptionsQuorum', 'raw': 'BlockdevOptionsRaw', 'rbd': 'BlockdevOptionsRbd', - 'replication':'BlockdevOptionsReplication', + 'replication': { 'type': 'BlockdevOptionsReplication', + 'if': 'defined(CONFIG_REPLICATION)' }, 'sheepdog': 'BlockdevOptionsSheepdog', 'ssh': 'BlockdevOptionsSsh', 'vdi': 'BlockdevOptionsGenericFormat', diff --git a/migration/colo.c b/migration/colo.c index 8bd7ef0531..1f352a6d86 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -150,11 +150,11 @@ void colo_do_failover(MigrationState *s) } } =20 +#ifdef CONFIG_REPLICATION void qmp_xen_set_replication(bool enable, bool primary, bool has_failover, bool failover, Error **errp) { -#ifdef CONFIG_REPLICATION ReplicationMode mode =3D primary ? REPLICATION_MODE_PRIMARY : REPLICATION_MODE_SECONDARY; @@ -173,14 +173,10 @@ void qmp_xen_set_replication(bool enable, bool primar= y, } replication_stop_all(failover, failover ? NULL : errp); } -#else - abort(); -#endif } =20 ReplicationStatus *qmp_query_xen_replication_status(Error **errp) { -#ifdef CONFIG_REPLICATION Error *err =3D NULL; ReplicationStatus *s =3D g_new0(ReplicationStatus, 1); =20 @@ -195,19 +191,13 @@ ReplicationStatus *qmp_query_xen_replication_status(E= rror **errp) =20 error_free(err); return s; -#else - abort(); -#endif } =20 void qmp_xen_colo_do_checkpoint(Error **errp) { -#ifdef CONFIG_REPLICATION replication_do_checkpoint_all(errp); -#else - abort(); -#endif } +#endif =20 static void colo_send_message(QEMUFile *f, COLOMessage msg, Error **errp) diff --git a/monitor.c b/monitor.c index e5a179d32e..008d7c2b06 100644 --- a/monitor.c +++ b/monitor.c @@ -971,11 +971,6 @@ static void qmp_query_qmp_schema(QDict *qdict, QObject= **ret_data, */ static void qmp_unregister_commands_hack(void) { -#ifndef CONFIG_REPLICATION - qmp_unregister_command(&qmp_commands, "xen-set-replication"); - qmp_unregister_command(&qmp_commands, "query-xen-replication-status"); - qmp_unregister_command(&qmp_commands, "xen-colo-do-checkpoint"); -#endif #ifndef TARGET_I386 qmp_unregister_command(&qmp_commands, "rtc-reset-reinjection"); #endif --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 1503410218678543.0222311370959; Tue, 22 Aug 2017 06:56:58 -0700 (PDT) Received: from localhost ([::1]:47213 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9ft-0002mu-Gz for importer@patchew.org; Tue, 22 Aug 2017 09:56:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55308) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9JU-000887-6k for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9JQ-00074H-1I for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38644) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9JP-00073O-Rb for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:43 -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 BACB9883DA for ; Tue, 22 Aug 2017 13:27:22 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0964A60466; Tue, 22 Aug 2017 13:27:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com BACB9883DA 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: Tue, 22 Aug 2017 15:22:49 +0200 Message-Id: <20170822132255.23945-49-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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.26]); Tue, 22 Aug 2017 13:27: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 48/54] tests/qmp-test: add query-qmp-schema test 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?= , Markus Armbruster 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" The following patch is going to make qmp introspection per-target, and test-qobject-input-visitor.c can no longer link with qmp_schema_qlit. Use a run-time QMP test instead to validate the query-qmp-schema schema. Signed-off-by: Marc-Andr=C3=A9 Lureau --- tests/qmp-test.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/qmp-test.c b/tests/qmp-test.c index 5d0260b2be..1fd37092b5 100644 --- a/tests/qmp-test.c +++ b/tests/qmp-test.c @@ -129,11 +129,32 @@ static void test_qmp_protocol(void) qtest_end(); } =20 +static void test_qmp_query_schema(void) +{ + SchemaInfoList *schema; + QDict *resp; + Visitor *v; + + qtest_start(common_args); + + resp =3D qmp("{'execute': 'query-qmp-schema'}"); + v =3D qobject_input_visitor_new(qdict_get(resp, "return")); + visit_type_SchemaInfoList(v, NULL, &schema, &error_abort); + g_assert(schema); + + qapi_free_SchemaInfoList(schema); + visit_free(v); + QDECREF(resp); + + qtest_end(); +} + int main(int argc, char *argv[]) { g_test_init(&argc, &argv, NULL); =20 qtest_add_func("qmp/protocol", test_qmp_protocol); + qtest_add_func("qmp/query-schema", test_qmp_query_schema); =20 return g_test_run(); } --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 150341181663730.45964864206894; Tue, 22 Aug 2017 07:23:36 -0700 (PDT) Received: from localhost ([::1]:47676 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkA5f-0007Ld-EM for importer@patchew.org; Tue, 22 Aug 2017 10:23:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55469) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9Jq-0008UK-EE for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:34:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9Jp-0007Mq-5H for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:34:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60050) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9Jo-0007MA-SB for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:34:09 -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 67B1BC04D952; Tue, 22 Aug 2017 13:27:36 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id B391A81B5A; Tue, 22 Aug 2017 13:27:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 67B1BC04D952 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: Tue, 22 Aug 2017 15:22:50 +0200 Message-Id: <20170822132255.23945-50-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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.32]); Tue, 22 Aug 2017 13:27:36 +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 49/54] build-sys: make qemu qapi objects per-target 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?= , Markus Armbruster , Stefan Hajnoczi , 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" QAPI can't do target-specific conditionals (the symbols are poisoned), and the work-around is to pretend the target-specific stuff is target-independent, with stubs for the other targets. Makes the target-specifity invisible in introspection. To unpoison the symbols, we need to move the generated QAPI code to the per-target build. Keep qapi-types.o qapi-visit.o in util-obj as they are necessary for common code, but they will be overwritten during the target link. Add some stubs for block events, in code shared by tools & qemu. The following patches will configure the schema to conditionally remove per-target disabled features. Drop "do_test_visitor_in_qmp_introspect(&&qmp_schema_qlit)" since it is no longer in a common object, and covered by "query-qmp-schema test" instead. Signed-off-by: Marc-Andr=C3=A9 Lureau --- stubs/qapi-event.c | 74 ++++++++++++++++++++++++++++++++++= ++++ tests/test-qobject-input-visitor.c | 1 - Makefile.objs | 9 +---- Makefile.target | 4 +++ stubs/Makefile.objs | 1 + trace/Makefile.objs | 2 +- 6 files changed, 81 insertions(+), 10 deletions(-) create mode 100644 stubs/qapi-event.c diff --git a/stubs/qapi-event.c b/stubs/qapi-event.c new file mode 100644 index 0000000000..9415299f3a --- /dev/null +++ b/stubs/qapi-event.c @@ -0,0 +1,74 @@ +#include "qemu/osdep.h" +#include "qapi-event.h" + +void qapi_event_send_device_tray_moved(const char *device, const char *id, + bool tray_open, Error **errp) +{ +} + +void qapi_event_send_quorum_report_bad(QuorumOpType type, bool has_error, + const char *error, const char *node= _name, + int64_t sector_num, + int64_t sectors_count, Error **errp) +{ +} + +void qapi_event_send_quorum_failure(const char *reference, int64_t sector_= num, + int64_t sectors_count, Error **errp) +{ +} + +void qapi_event_send_block_job_cancelled(BlockJobType type, const char *de= vice, + int64_t len, int64_t offset, + int64_t speed, Error **errp) +{ +} + +void qapi_event_send_block_job_completed(BlockJobType type, const char *de= vice, + int64_t len, int64_t offset, + int64_t speed, bool has_error, + const char *error, Error **errp) +{ +} + +void qapi_event_send_block_job_error(const char *device, + IoOperationType operation, + BlockErrorAction action, Error **errp) +{ +} + +void qapi_event_send_block_job_ready(BlockJobType type, const char *device, + int64_t len, int64_t offset, int64_t = speed, + Error **errp) +{ +} + +void qapi_event_send_block_io_error(const char *device, const char *node_n= ame, + IoOperationType operation, + BlockErrorAction action, bool has_nosp= ace, + bool nospace, const char *reason, + Error **errp) +{ +} + +void qapi_event_send_block_image_corrupted(const char *device, + bool has_node_name, + const char *node_name, + const char *msg, bool has_offse= t, + int64_t offset, bool has_size, + int64_t size, bool fatal, + Error **errp) +{ +} + +void qapi_event_send_block_write_threshold(const char *node_name, + uint64_t amount_exceeded, + uint64_t write_threshold, + Error **errp) +{ +} + +void qapi_event_send_device_deleted(bool has_device, const char *device, + const char *path, Error **errp) +{ +} diff --git a/tests/test-qobject-input-visitor.c b/tests/test-qobject-input-= visitor.c index be7d7ea654..bb35a4d15f 100644 --- a/tests/test-qobject-input-visitor.c +++ b/tests/test-qobject-input-visitor.c @@ -1267,7 +1267,6 @@ static void test_visitor_in_qmp_introspect(TestInputV= isitorData *data, const void *unused) { 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/Makefile.objs b/Makefile.objs index 24a4ea08b8..2664720f9b 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -2,7 +2,7 @@ # Common libraries for tools and emulators stub-obj-y =3D stubs/ crypto/ util-obj-y =3D util/ qobject/ qapi/ -util-obj-y +=3D qmp-introspect.o qapi-types.o qapi-visit.o qapi-event.o +util-obj-y +=3D qapi-types.o qapi-visit.o =20 chardev-obj-y =3D chardev/ =20 @@ -72,13 +72,6 @@ common-obj-y +=3D chardev/ common-obj-$(CONFIG_SECCOMP) +=3D qemu-seccomp.o =20 common-obj-$(CONFIG_FDT) +=3D device_tree.o - -###################################################################### -# qapi - -common-obj-y +=3D qmp-marshal.o -common-obj-y +=3D qmp-introspect.o -common-obj-y +=3D qmp.o hmp.o endif =20 ####################################################################### diff --git a/Makefile.target b/Makefile.target index 7f42c45db8..c5f8ded4fa 100644 --- a/Makefile.target +++ b/Makefile.target @@ -157,6 +157,10 @@ endif =20 GENERATED_FILES +=3D hmp-commands.h hmp-commands-info.h =20 +obj-y +=3D qmp-introspect.o qapi-types.o qapi-visit.o qapi-event.o +obj-y +=3D qmp-marshal.o qmp-introspect.o +obj-y +=3D qmp.o hmp.o + endif # CONFIG_SOFTMMU =20 # Workaround for http://gcc.gnu.org/PR55489, see configure. diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs index e69c217aff..717b342c80 100644 --- a/stubs/Makefile.objs +++ b/stubs/Makefile.objs @@ -22,6 +22,7 @@ stub-obj-y +=3D migr-blocker.o stub-obj-y +=3D change-state-handler.o stub-obj-y +=3D monitor.o stub-obj-y +=3D notify-event.o +stub-obj-y +=3D qapi-event.o stub-obj-y +=3D qtest.o stub-obj-y +=3D replay.o stub-obj-y +=3D runstate-check.o diff --git a/trace/Makefile.objs b/trace/Makefile.objs index afd571c3ec..6447729d60 100644 --- a/trace/Makefile.objs +++ b/trace/Makefile.objs @@ -56,4 +56,4 @@ util-obj-$(CONFIG_TRACE_SIMPLE) +=3D simple.o util-obj-$(CONFIG_TRACE_FTRACE) +=3D ftrace.o util-obj-y +=3D control.o target-obj-y +=3D control-target.o -util-obj-y +=3D qmp.o +target-obj-y +=3D qmp.o --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 1503411009770931.0188885551174; Tue, 22 Aug 2017 07:10:09 -0700 (PDT) Received: from localhost ([::1]:47341 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9se-00059p-Ge for importer@patchew.org; Tue, 22 Aug 2017 10:10:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55184) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9JL-000823-Bc for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9JJ-0006ye-16 for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58422) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9JI-0006xt-S3 for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:36 -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 0F34CC04D2A8 for ; Tue, 22 Aug 2017 13:27:41 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 492168311D; Tue, 22 Aug 2017 13:27:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0F34CC04D2A8 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: Tue, 22 Aug 2017 15:22:51 +0200 Message-Id: <20170822132255.23945-51-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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.31]); Tue, 22 Aug 2017 13:27:41 +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 50/54] qapi: make rtc-reset-reinjection depend on TARGET_I386 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?= , "Dr. David Alan Gilbert" , Markus Armbruster 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 --- qapi-schema.json | 3 ++- monitor.c | 10 ---------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/qapi-schema.json b/qapi-schema.json index 1091a80fd3..58574b3044 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -6294,7 +6294,8 @@ # <- { "return": {} } # ## -{ 'command': 'rtc-reset-reinjection' } +{ 'command': 'rtc-reset-reinjection', + 'if': ['defined(NEED_CPU_H)', 'defined(TARGET_I386)'] } =20 # Rocker ethernet network switch { 'include': 'qapi/rocker.json' } diff --git a/monitor.c b/monitor.c index 008d7c2b06..fcacf10f59 100644 --- a/monitor.c +++ b/monitor.c @@ -971,9 +971,6 @@ static void qmp_query_qmp_schema(QDict *qdict, QObject = **ret_data, */ static void qmp_unregister_commands_hack(void) { -#ifndef TARGET_I386 - qmp_unregister_command(&qmp_commands, "rtc-reset-reinjection"); -#endif #ifndef TARGET_S390X qmp_unregister_command(&qmp_commands, "dump-skeys"); #endif @@ -4156,13 +4153,6 @@ QemuOptsList qemu_mon_opts =3D { }, }; =20 -#ifndef TARGET_I386 -void qmp_rtc_reset_reinjection(Error **errp) -{ - error_setg(errp, QERR_FEATURE_DISABLED, "rtc-reset-reinjection"); -} -#endif - #ifndef TARGET_S390X void qmp_dump_skeys(const char *filename, Error **errp) { --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 1503410845983922.741339333794; Tue, 22 Aug 2017 07:07:25 -0700 (PDT) Received: from localhost ([::1]:47326 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9q0-00037H-Cv for importer@patchew.org; Tue, 22 Aug 2017 10:07:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55304) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9JT-00087P-Fo for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9JP-00073J-6A for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38448) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9JO-00072D-TJ for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:33:43 -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 9AC5D806CC; Tue, 22 Aug 2017 13:27:46 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0479081E33; Tue, 22 Aug 2017 13:27:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9AC5D806CC 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: Tue, 22 Aug 2017 15:22:52 +0200 Message-Id: <20170822132255.23945-52-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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]); Tue, 22 Aug 2017 13:27:46 +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 51/54] qapi: make s390 commands depend on TARGET_S390X 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: Alexander Graf , Markus Armbruster , "Dr. David Alan Gilbert" , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Richard Henderson 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 --- qapi-schema.json | 10 +++++++--- include/sysemu/arch_init.h | 6 ------ monitor.c | 14 -------------- qmp.c | 14 -------------- stubs/arch-query-cpu-model-baseline.c | 12 ------------ stubs/arch-query-cpu-model-comparison.c | 12 ------------ target/s390x/cpu_models.c | 4 ++-- stubs/Makefile.objs | 2 -- 8 files changed, 9 insertions(+), 65 deletions(-) delete mode 100644 stubs/arch-query-cpu-model-baseline.c delete mode 100644 stubs/arch-query-cpu-model-comparison.c diff --git a/qapi-schema.json b/qapi-schema.json index 58574b3044..d4e1552ddc 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -3577,7 +3577,8 @@ # ## { 'command': 'dump-skeys', - 'data': { 'filename': 'str' } } + 'data': { 'filename': 'str' }, + 'if': ['defined(NEED_CPU_H)', 'defined(TARGET_S390X)']} =20 ## # @netdev_add: @@ -4621,7 +4622,9 @@ ## { 'command': 'query-cpu-model-comparison', 'data': { 'modela': 'CpuModelInfo', 'modelb': 'CpuModelInfo' }, - 'returns': 'CpuModelCompareInfo' } + 'returns': 'CpuModelCompareInfo', + 'if': ['defined(NEED_CPU_H)', 'defined(TARGET_S390X)']} + =20 ## # @CpuModelBaselineInfo: @@ -4673,7 +4676,8 @@ { 'command': 'query-cpu-model-baseline', 'data': { 'modela': 'CpuModelInfo', 'modelb': 'CpuModelInfo' }, - 'returns': 'CpuModelBaselineInfo' } + 'returns': 'CpuModelBaselineInfo', + 'if': ['defined(NEED_CPU_H)', 'defined(TARGET_S390X)']} =20 ## # @AddfdInfo: diff --git a/include/sysemu/arch_init.h b/include/sysemu/arch_init.h index 8751c468ed..e9f1ea0cca 100644 --- a/include/sysemu/arch_init.h +++ b/include/sysemu/arch_init.h @@ -35,11 +35,5 @@ CpuDefinitionInfoList *arch_query_cpu_definitions(Error = **errp); CpuModelExpansionInfo *arch_query_cpu_model_expansion(CpuModelExpansionTyp= e type, CpuModelInfo *mode, Error **errp); -CpuModelCompareInfo *arch_query_cpu_model_comparison(CpuModelInfo *modela, - CpuModelInfo *modelb, - Error **errp); -CpuModelBaselineInfo *arch_query_cpu_model_baseline(CpuModelInfo *modela, - CpuModelInfo *modelb, - Error **errp); =20 #endif diff --git a/monitor.c b/monitor.c index fcacf10f59..c9f04652b4 100644 --- a/monitor.c +++ b/monitor.c @@ -971,19 +971,12 @@ static void qmp_query_qmp_schema(QDict *qdict, QObjec= t **ret_data, */ static void qmp_unregister_commands_hack(void) { -#ifndef TARGET_S390X - qmp_unregister_command(&qmp_commands, "dump-skeys"); -#endif #ifndef TARGET_ARM qmp_unregister_command(&qmp_commands, "query-gic-capabilities"); #endif #if !defined(TARGET_S390X) && !defined(TARGET_I386) qmp_unregister_command(&qmp_commands, "query-cpu-model-expansion"); #endif -#if !defined(TARGET_S390X) - qmp_unregister_command(&qmp_commands, "query-cpu-model-baseline"); - qmp_unregister_command(&qmp_commands, "query-cpu-model-comparison"); -#endif #if !defined(TARGET_PPC) && !defined(TARGET_ARM) && !defined(TARGET_I386) \ && !defined(TARGET_S390X) qmp_unregister_command(&qmp_commands, "query-cpu-definitions"); @@ -4153,13 +4146,6 @@ QemuOptsList qemu_mon_opts =3D { }, }; =20 -#ifndef TARGET_S390X -void qmp_dump_skeys(const char *filename, Error **errp) -{ - error_setg(errp, QERR_FEATURE_DISABLED, "dump-skeys"); -} -#endif - #ifndef TARGET_ARM GICCapabilityList *qmp_query_gic_capabilities(Error **errp) { diff --git a/qmp.c b/qmp.c index 90816ba283..7b6861846f 100644 --- a/qmp.c +++ b/qmp.c @@ -553,20 +553,6 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(C= puModelExpansionType type, return arch_query_cpu_model_expansion(type, model, errp); } =20 -CpuModelCompareInfo *qmp_query_cpu_model_comparison(CpuModelInfo *modela, - CpuModelInfo *modelb, - Error **errp) -{ - return arch_query_cpu_model_comparison(modela, modelb, errp); -} - -CpuModelBaselineInfo *qmp_query_cpu_model_baseline(CpuModelInfo *modela, - CpuModelInfo *modelb, - Error **errp) -{ - return arch_query_cpu_model_baseline(modela, modelb, errp); -} - void qmp_add_client(const char *protocol, const char *fdname, bool has_skipauth, bool skipauth, bool has_tls, bool t= ls, Error **errp) diff --git a/stubs/arch-query-cpu-model-baseline.c b/stubs/arch-query-cpu-m= odel-baseline.c deleted file mode 100644 index 094ec13c2c..0000000000 --- a/stubs/arch-query-cpu-model-baseline.c +++ /dev/null @@ -1,12 +0,0 @@ -#include "qemu/osdep.h" -#include "qemu-common.h" -#include "sysemu/arch_init.h" -#include "qapi/qmp/qerror.h" - -CpuModelBaselineInfo *arch_query_cpu_model_baseline(CpuModelInfo *modela, - CpuModelInfo *modelb, - Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - return NULL; -} diff --git a/stubs/arch-query-cpu-model-comparison.c b/stubs/arch-query-cpu= -model-comparison.c deleted file mode 100644 index d5486ae980..0000000000 --- a/stubs/arch-query-cpu-model-comparison.c +++ /dev/null @@ -1,12 +0,0 @@ -#include "qemu/osdep.h" -#include "qemu-common.h" -#include "sysemu/arch_init.h" -#include "qapi/qmp/qerror.h" - -CpuModelCompareInfo *arch_query_cpu_model_comparison(CpuModelInfo *modela, - CpuModelInfo *modelb, - Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - return NULL; -} diff --git a/target/s390x/cpu_models.c b/target/s390x/cpu_models.c index fa1338fc72..cdff9cdd3b 100644 --- a/target/s390x/cpu_models.c +++ b/target/s390x/cpu_models.c @@ -559,7 +559,7 @@ static void list_add_feat(const char *name, void *opaqu= e) *last =3D entry; } =20 -CpuModelCompareInfo *arch_query_cpu_model_comparison(CpuModelInfo *infoa, +CpuModelCompareInfo *qmp_query_cpu_model_comparison(CpuModelInfo *infoa, CpuModelInfo *infob, Error **errp) { @@ -632,7 +632,7 @@ CpuModelCompareInfo *arch_query_cpu_model_comparison(Cp= uModelInfo *infoa, return compare_info; } =20 -CpuModelBaselineInfo *arch_query_cpu_model_baseline(CpuModelInfo *infoa, +CpuModelBaselineInfo *qmp_query_cpu_model_baseline(CpuModelInfo *infoa, CpuModelInfo *infob, Error **errp) { diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs index 717b342c80..1421824eb3 100644 --- a/stubs/Makefile.objs +++ b/stubs/Makefile.objs @@ -1,7 +1,5 @@ stub-obj-y +=3D arch-query-cpu-def.o stub-obj-y +=3D arch-query-cpu-model-expansion.o -stub-obj-y +=3D arch-query-cpu-model-comparison.o -stub-obj-y +=3D arch-query-cpu-model-baseline.o stub-obj-y +=3D bdrv-next-monitor-owned.o stub-obj-y +=3D blk-commit-all.o stub-obj-y +=3D blockdev-close-all-bdrv-states.o --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 1503411998505292.5670151629787; Tue, 22 Aug 2017 07:26:38 -0700 (PDT) Received: from localhost ([::1]:47797 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkA8b-0001tT-CT for importer@patchew.org; Tue, 22 Aug 2017 10:26:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56558) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9Mt-0002dr-G2 for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:37:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9Mo-00013T-1r for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:37:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47391) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9Mn-00013B-S2 for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:37:13 -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 9A3FD267C4 for ; Tue, 22 Aug 2017 13:27:51 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 719AB81E27; Tue, 22 Aug 2017 13:27:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9A3FD267C4 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: Tue, 22 Aug 2017 15:22:53 +0200 Message-Id: <20170822132255.23945-53-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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.30]); Tue, 22 Aug 2017 13:27:51 +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 52/54] qapi: make query-gic-capabilities depend on TARGET_ARM 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?= , Markus Armbruster , "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" Signed-off-by: Marc-Andr=C3=A9 Lureau --- qapi-schema.json | 3 ++- monitor.c | 11 ----------- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/qapi-schema.json b/qapi-schema.json index d4e1552ddc..6c1adb35b5 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -6461,7 +6461,8 @@ # { "version": 3, "emulated": false, "kernel": true } ] } # ## -{ 'command': 'query-gic-capabilities', 'returns': ['GICCapability'] } +{ 'command': 'query-gic-capabilities', 'returns': ['GICCapability'], + 'if': ['defined(NEED_CPU_H)', 'defined(TARGET_ARM)']} =20 ## # @CpuInstanceProperties: diff --git a/monitor.c b/monitor.c index c9f04652b4..6ddc3c7ff7 100644 --- a/monitor.c +++ b/monitor.c @@ -971,9 +971,6 @@ static void qmp_query_qmp_schema(QDict *qdict, QObject = **ret_data, */ static void qmp_unregister_commands_hack(void) { -#ifndef TARGET_ARM - qmp_unregister_command(&qmp_commands, "query-gic-capabilities"); -#endif #if !defined(TARGET_S390X) && !defined(TARGET_I386) qmp_unregister_command(&qmp_commands, "query-cpu-model-expansion"); #endif @@ -4146,14 +4143,6 @@ QemuOptsList qemu_mon_opts =3D { }, }; =20 -#ifndef TARGET_ARM -GICCapabilityList *qmp_query_gic_capabilities(Error **errp) -{ - error_setg(errp, QERR_FEATURE_DISABLED, "query-gic-capabilities"); - return NULL; -} -#endif - HotpluggableCPUList *qmp_query_hotpluggable_cpus(Error **errp) { MachineState *ms =3D MACHINE(qdev_get_machine()); --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 1503411621765292.186815257841; Tue, 22 Aug 2017 07:20:21 -0700 (PDT) Received: from localhost ([::1]:47513 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkA2W-0004cK-HI for importer@patchew.org; Tue, 22 Aug 2017 10:20:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55466) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9Jq-0008U6-7m for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:34:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9Jp-0007Mv-50 for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:34:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:17571) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9Jo-0007MC-Ro for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:34:09 -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 73AB0C0546C3; Tue, 22 Aug 2017 13:27:56 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2F22D7E575; Tue, 22 Aug 2017 13:27:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 73AB0C0546C3 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: Tue, 22 Aug 2017 15:22:54 +0200 Message-Id: <20170822132255.23945-54-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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]); Tue, 22 Aug 2017 13:27:56 +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 53/54] qapi: make query-cpu-model-expansion depend on s390 or x86 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: Alexander Graf , Eduardo Habkost , "Dr. David Alan Gilbert" , Markus Armbruster , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Richard Henderson 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 --- qapi-schema.json | 4 +++- include/sysemu/arch_init.h | 3 --- monitor.c | 3 --- qmp.c | 7 ------- stubs/arch-query-cpu-model-expansion.c | 12 ------------ target/i386/cpu.c | 2 +- target/s390x/cpu_models.c | 3 ++- stubs/Makefile.objs | 1 - 8 files changed, 6 insertions(+), 29 deletions(-) delete mode 100644 stubs/arch-query-cpu-model-expansion.c diff --git a/qapi-schema.json b/qapi-schema.json index 6c1adb35b5..127a2c71c6 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -4535,7 +4535,9 @@ { 'command': 'query-cpu-model-expansion', 'data': { 'type': 'CpuModelExpansionType', 'model': 'CpuModelInfo' }, - 'returns': 'CpuModelExpansionInfo' } + 'returns': 'CpuModelExpansionInfo', + 'if': ['defined(NEED_CPU_H)', + 'defined(TARGET_S390X) || defined(TARGET_I386)']} =20 ## # @CpuModelCompareResult: diff --git a/include/sysemu/arch_init.h b/include/sysemu/arch_init.h index e9f1ea0cca..fb3d20a1b8 100644 --- a/include/sysemu/arch_init.h +++ b/include/sysemu/arch_init.h @@ -32,8 +32,5 @@ int kvm_available(void); int xen_available(void); =20 CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp); -CpuModelExpansionInfo *arch_query_cpu_model_expansion(CpuModelExpansionTyp= e type, - CpuModelInfo *mode, - Error **errp); =20 #endif diff --git a/monitor.c b/monitor.c index 6ddc3c7ff7..ca67a584d2 100644 --- a/monitor.c +++ b/monitor.c @@ -971,9 +971,6 @@ static void qmp_query_qmp_schema(QDict *qdict, QObject = **ret_data, */ static void qmp_unregister_commands_hack(void) { -#if !defined(TARGET_S390X) && !defined(TARGET_I386) - qmp_unregister_command(&qmp_commands, "query-cpu-model-expansion"); -#endif #if !defined(TARGET_PPC) && !defined(TARGET_ARM) && !defined(TARGET_I386) \ && !defined(TARGET_S390X) qmp_unregister_command(&qmp_commands, "query-cpu-definitions"); diff --git a/qmp.c b/qmp.c index 7b6861846f..afa266ec1e 100644 --- a/qmp.c +++ b/qmp.c @@ -546,13 +546,6 @@ CpuDefinitionInfoList *qmp_query_cpu_definitions(Error= **errp) return arch_query_cpu_definitions(errp); } =20 -CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType= type, - CpuModelInfo *model, - Error **errp) -{ - return arch_query_cpu_model_expansion(type, model, errp); -} - void qmp_add_client(const char *protocol, const char *fdname, bool has_skipauth, bool skipauth, bool has_tls, bool t= ls, Error **errp) diff --git a/stubs/arch-query-cpu-model-expansion.c b/stubs/arch-query-cpu-= model-expansion.c deleted file mode 100644 index ae7cf554d1..0000000000 --- a/stubs/arch-query-cpu-model-expansion.c +++ /dev/null @@ -1,12 +0,0 @@ -#include "qemu/osdep.h" -#include "qemu-common.h" -#include "sysemu/arch_init.h" -#include "qapi/qmp/qerror.h" - -CpuModelExpansionInfo *arch_query_cpu_model_expansion(CpuModelExpansionTyp= e type, - CpuModelInfo *mode, - Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - return NULL; -} diff --git a/target/i386/cpu.c b/target/i386/cpu.c index ddc45abd70..d683e70a13 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -2574,7 +2574,7 @@ out: } =20 CpuModelExpansionInfo * -arch_query_cpu_model_expansion(CpuModelExpansionType type, +qmp_query_cpu_model_expansion(CpuModelExpansionType type, CpuModelInfo *model, Error **errp) { diff --git a/target/s390x/cpu_models.c b/target/s390x/cpu_models.c index cdff9cdd3b..863dce064f 100644 --- a/target/s390x/cpu_models.c +++ b/target/s390x/cpu_models.c @@ -22,6 +22,7 @@ #ifndef CONFIG_USER_ONLY #include "sysemu/arch_init.h" #endif +#include "qmp-commands.h" =20 #define CPUDEF_INIT(_type, _gen, _ec_ga, _mha_pow, _hmfai, _name, _desc) \ { \ @@ -520,7 +521,7 @@ static void cpu_info_from_model(CpuModelInfo *info, con= st S390CPUModel *model, } } =20 -CpuModelExpansionInfo *arch_query_cpu_model_expansion(CpuModelExpansionTyp= e type, +CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType= type, CpuModelInfo *model, Error **errp) { diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs index 1421824eb3..eb17628ede 100644 --- a/stubs/Makefile.objs +++ b/stubs/Makefile.objs @@ -1,5 +1,4 @@ stub-obj-y +=3D arch-query-cpu-def.o -stub-obj-y +=3D arch-query-cpu-model-expansion.o stub-obj-y +=3D bdrv-next-monitor-owned.o stub-obj-y +=3D blk-commit-all.o stub-obj-y +=3D blockdev-close-all-bdrv-states.o --=20 2.14.1.146.gd35faa819 From nobody Tue May 7 01:19:00 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 1503408870292645.3994703201232; Tue, 22 Aug 2017 06:34:30 -0700 (PDT) Received: from localhost ([::1]:46712 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9K8-0008H9-N5 for importer@patchew.org; Tue, 22 Aug 2017 09:34:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53329) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9E3-0003BN-QE for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:28:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9E2-0003PB-F1 for qemu-devel@nongnu.org; Tue, 22 Aug 2017 09:28:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42582) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dk9Dx-0003LD-7m; Tue, 22 Aug 2017 09:28:05 -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 C17556147C; Tue, 22 Aug 2017 13:28:02 +0000 (UTC) Received: from localhost (ovpn-112-43.ams2.redhat.com [10.36.112.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 883E5617A3; Tue, 22 Aug 2017 13:27:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C17556147C 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: Tue, 22 Aug 2017 15:22:55 +0200 Message-Id: <20170822132255.23945-55-marcandre.lureau@redhat.com> In-Reply-To: <20170822132255.23945-1-marcandre.lureau@redhat.com> References: <20170822132255.23945-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.39]); Tue, 22 Aug 2017 13:28:02 +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 54/54] qapi: make query-cpu-definitions depend on specific targets 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: Peter Maydell , Eduardo Habkost , "Dr. David Alan Gilbert" , Markus Armbruster , Alexander Graf , "open list:ARM" , "open list:PowerPC" , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , David Gibson , Richard Henderson 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" It depends on TARGET_PPC || TARGET_ARM || TARGET_I386 || TARGET_S390X. Signed-off-by: Marc-Andr=C3=A9 Lureau --- qapi-schema.json | 4 +++- include/sysemu/arch_init.h | 2 -- monitor.c | 22 ---------------------- qmp.c | 5 ----- stubs/arch-query-cpu-def.c | 10 ---------- target/arm/helper.c | 3 ++- target/i386/cpu.c | 3 ++- target/ppc/translate_init.c | 3 ++- target/s390x/cpu_models.c | 2 +- stubs/Makefile.objs | 1 - 10 files changed, 10 insertions(+), 45 deletions(-) delete mode 100644 stubs/arch-query-cpu-def.c diff --git a/qapi-schema.json b/qapi-schema.json index 127a2c71c6..194859f683 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -4433,7 +4433,9 @@ # # Since: 1.2.0 ## -{ 'command': 'query-cpu-definitions', 'returns': ['CpuDefinitionInfo'] } +{ 'command': 'query-cpu-definitions', 'returns': ['CpuDefinitionInfo'], + 'if': ['defined(NEED_CPU_H)', + 'defined(TARGET_PPC) || defined(TARGET_ARM) || defined(TARGET_I38= 6) || defined(TARGET_S390X)'] } =20 ## # @CpuModelInfo: diff --git a/include/sysemu/arch_init.h b/include/sysemu/arch_init.h index fb3d20a1b8..e9721b9ce8 100644 --- a/include/sysemu/arch_init.h +++ b/include/sysemu/arch_init.h @@ -31,6 +31,4 @@ extern const uint32_t arch_type; int kvm_available(void); int xen_available(void); =20 -CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp); - #endif diff --git a/monitor.c b/monitor.c index ca67a584d2..ac400e65ee 100644 --- a/monitor.c +++ b/monitor.c @@ -957,26 +957,6 @@ static void qmp_query_qmp_schema(QDict *qdict, QObject= **ret_data, *ret_data =3D qobject_from_qlit(&qmp_schema_qlit); } =20 -/* - * We used to define commands in qmp-commands.hx in addition to the - * QAPI schema. This permitted defining some of them only in certain - * configurations. query-commands has always reflected that (good, - * because it lets QMP clients figure out what's actually available), - * while query-qmp-schema never did (not so good). This function is a - * hack to keep the configuration-specific commands defined exactly as - * before, even though qmp-commands.hx is gone. - * - * FIXME Educate the QAPI schema on configuration-specific commands, - * and drop this hack. - */ -static void qmp_unregister_commands_hack(void) -{ -#if !defined(TARGET_PPC) && !defined(TARGET_ARM) && !defined(TARGET_I386) \ - && !defined(TARGET_S390X) - qmp_unregister_command(&qmp_commands, "query-cpu-definitions"); -#endif -} - void monitor_init_qmp_commands(void) { /* @@ -996,8 +976,6 @@ void monitor_init_qmp_commands(void) qmp_register_command(&qmp_commands, "netdev_add", qmp_netdev_add, QCO_NO_OPTIONS); =20 - qmp_unregister_commands_hack(); - QTAILQ_INIT(&qmp_cap_negotiation_commands); qmp_register_command(&qmp_cap_negotiation_commands, "qmp_capabilities", qmp_marshal_qmp_capabilities, QCO_NO_OPTIONS); diff --git a/qmp.c b/qmp.c index afa266ec1e..d57ccf1251 100644 --- a/qmp.c +++ b/qmp.c @@ -541,11 +541,6 @@ DevicePropertyInfoList *qmp_device_list_properties(con= st char *typename, return prop_list; } =20 -CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) -{ - return arch_query_cpu_definitions(errp); -} - void qmp_add_client(const char *protocol, const char *fdname, bool has_skipauth, bool skipauth, bool has_tls, bool t= ls, Error **errp) diff --git a/stubs/arch-query-cpu-def.c b/stubs/arch-query-cpu-def.c deleted file mode 100644 index cefe4beb82..0000000000 --- a/stubs/arch-query-cpu-def.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "qemu/osdep.h" -#include "qemu-common.h" -#include "sysemu/arch_init.h" -#include "qapi/qmp/qerror.h" - -CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); - return NULL; -} diff --git a/target/arm/helper.c b/target/arm/helper.c index fa60040361..54543a0b01 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -15,6 +15,7 @@ #include /* For crc32 */ #include "exec/semihost.h" #include "sysemu/kvm.h" +#include "qmp-commands.h" =20 #define ARM_CPU_FREQ 1000000000 /* FIXME: 1 GHz, should be configurable */ =20 @@ -5332,7 +5333,7 @@ static void arm_cpu_add_definition(gpointer data, gpo= inter user_data) *cpu_list =3D entry; } =20 -CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp) +CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) { CpuDefinitionInfoList *cpu_list =3D NULL; GSList *list; diff --git a/target/i386/cpu.c b/target/i386/cpu.c index d683e70a13..e5f61f6bff 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -36,6 +36,7 @@ #include "qapi/visitor.h" #include "qom/qom-qobject.h" #include "sysemu/arch_init.h" +#include "qmp-commands.h" =20 #if defined(CONFIG_KVM) #include @@ -2318,7 +2319,7 @@ static void x86_cpu_definition_entry(gpointer data, g= pointer user_data) *cpu_list =3D entry; } =20 -CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp) +CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) { CpuDefinitionInfoList *cpu_list =3D NULL; GSList *list =3D get_sorted_cpu_model_list(); diff --git a/target/ppc/translate_init.c b/target/ppc/translate_init.c index 8fb407ed73..5845a15296 100644 --- a/target/ppc/translate_init.c +++ b/target/ppc/translate_init.c @@ -34,6 +34,7 @@ #include "hw/ppc/ppc.h" #include "mmu-book3s-v3.h" #include "sysemu/qtest.h" +#include "qmp-commands.h" =20 //#define PPC_DUMP_CPU //#define PPC_DEBUG_SPR @@ -10401,7 +10402,7 @@ static void ppc_cpu_defs_entry(gpointer data, gpoin= ter user_data) *first =3D entry; } =20 -CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp) +CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) { CpuDefinitionInfoList *cpu_list =3D NULL; GSList *list; diff --git a/target/s390x/cpu_models.c b/target/s390x/cpu_models.c index 863dce064f..8021dda341 100644 --- a/target/s390x/cpu_models.c +++ b/target/s390x/cpu_models.c @@ -387,7 +387,7 @@ static void create_cpu_model_list(ObjectClass *klass, v= oid *opaque) *cpu_list =3D entry; } =20 -CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp) +CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) { struct CpuDefinitionInfoListData list_data =3D { .list =3D NULL, diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs index eb17628ede..67bf15261d 100644 --- a/stubs/Makefile.objs +++ b/stubs/Makefile.objs @@ -1,4 +1,3 @@ -stub-obj-y +=3D arch-query-cpu-def.o stub-obj-y +=3D bdrv-next-monitor-owned.o stub-obj-y +=3D blk-commit-all.o stub-obj-y +=3D blockdev-close-all-bdrv-states.o --=20 2.14.1.146.gd35faa819