From nobody Thu Nov 6 16:08:00 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489386591484825.5271001349485; Sun, 12 Mar 2017 23:29:51 -0700 (PDT) Received: from localhost ([::1]:50401 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnJUM-0007Qv-7d for importer@patchew.org; Mon, 13 Mar 2017 02:29:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52443) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnJJr-0007bq-N9 for qemu-devel@nongnu.org; Mon, 13 Mar 2017 02:19:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cnJJn-0003fR-Ad for qemu-devel@nongnu.org; Mon, 13 Mar 2017 02:18:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34170) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cnJJm-0003dc-SG for qemu-devel@nongnu.org; Mon, 13 Mar 2017 02:18:55 -0400 Received: from smtp.corp.redhat.com (int-mx16.intmail.prod.int.phx2.redhat.com [10.5.11.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EF6E83DBD4; Mon, 13 Mar 2017 06:18:54 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-55.ams2.redhat.com [10.36.116.55]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B93972D5C4; Mon, 13 Mar 2017 06:18:54 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 9CD4D11384C1; Mon, 13 Mar 2017 07:18:47 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 13 Mar 2017 07:18:42 +0100 Message-Id: <1489385927-6735-43-git-send-email-armbru@redhat.com> In-Reply-To: <1489385927-6735-1-git-send-email-armbru@redhat.com> References: <1489385927-6735-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.74 on 10.5.11.28 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 13 Mar 2017 06:18:55 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.9 42/47] qapi: enum_types is a list used like a dict, make it one 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: marcandre.lureau@redhat.com, mdroth@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Markus Armbruster --- scripts/qapi.py | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/scripts/qapi.py b/scripts/qapi.py index f06e3c4..5a3a606 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -46,7 +46,7 @@ returns_whitelist =3D [] # Whitelist of entities allowed to violate case conventions name_case_whitelist =3D [] =20 -enum_types =3D [] +enum_types =3D {} struct_types =3D [] union_types =3D [] all_names =3D {} @@ -562,7 +562,7 @@ def find_alternate_member_qtype(qapi_type): return builtin_types[qapi_type] elif find_struct(qapi_type): return 'QTYPE_QDICT' - elif find_enum(qapi_type): + elif qapi_type in enum_types: return 'QTYPE_QSTRING' elif find_union(qapi_type): return 'QTYPE_QDICT' @@ -586,7 +586,7 @@ def discriminator_find_enum_define(expr): if not discriminator_type: return None =20 - return find_enum(discriminator_type) + return enum_types.get(discriminator_type) =20 =20 # Names must be letters, numbers, -, and _. They must start with letter, @@ -659,23 +659,6 @@ def find_union(name): return None =20 =20 -def add_enum(definition, info): - global enum_types - enum_types.append(definition) - - -def find_enum(name): - global enum_types - for enum in enum_types: - if enum['enum'] =3D=3D name: - return enum - return None - - -def is_enum(name): - return find_enum(name) is not None - - def check_type(info, source, value, allow_array=3DFalse, allow_dict=3DFalse, allow_optional=3DFalse, allow_metas=3D[]): @@ -794,7 +777,7 @@ def check_union(expr, info): "Discriminator '%s' is not a member of base= " "struct '%s'" % (discriminator, base)) - enum_define =3D find_enum(discriminator_type) + enum_define =3D enum_types.get(discriminator_type) allow_metas =3D ['struct'] # Do not allow string discriminator if not enum_define: @@ -928,7 +911,7 @@ def check_exprs(exprs): if 'enum' in expr: meta =3D 'enum' check_keys(expr_elem, 'enum', ['data'], ['prefix']) - add_enum(expr, info) + enum_types[expr[meta]] =3D expr elif 'union' in expr: meta =3D 'union' check_keys(expr_elem, 'union', ['data'], @@ -966,7 +949,7 @@ def check_exprs(exprs): name =3D '%sKind' % expr['alternate'] else: continue - add_enum({ 'enum': name }, expr_elem['info']) + enum_types[name] =3D { 'enum': name } add_name(name, info, 'enum', implicit=3DTrue) =20 # Validate that exprs make sense --=20 2.7.4