From nobody Wed Nov 12 10:08:42 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569696905; cv=none; d=zoho.com; s=zohoarc; b=jX+nPbfr39Zrg6mKaoSLbi2AdmB3pH+Jf7w/7QD8tIMr36ykVriB2+gPkdSuv5U+RTPGO4b9XWa6VOl7TG5Q6jBwaB6Ihg52aPo4BmKNVfXQb3MZbj1SC6DEfH3lYsD+CrlVqCo3hl+4vxge4kkoooAnw7nfCWBXQY1DTJv3Cgk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569696905; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=9J1uLGfcpGXqFjdW12khVPXzB45UbHxKfLiqeRGg5IE=; b=hDM3Q3LY4rF711H+UZfXoSR43CYkaXqaPju6sfAvDr+1ACKjJ35nZNQVrzTkIDNgbItNq1f2BvWrfdwkErfcwduKm4TBNBL+U1D74lZmivL0sHjGZhroi2QMjZfpXuzIqOuAIjS8iL2W6pGuDv6jzh4uhgVMlHDtZUCZIgUcltE= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1569696905897661.5600103652351; Sat, 28 Sep 2019 11:55:05 -0700 (PDT) Received: from localhost ([::1]:34448 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iEHrz-0005iC-Sz for importer@patchew.org; Sat, 28 Sep 2019 14:55:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43896) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iEHd7-0008Pj-Qb for qemu-devel@nongnu.org; Sat, 28 Sep 2019 14:39:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iEHd4-0003su-S2 for qemu-devel@nongnu.org; Sat, 28 Sep 2019 14:39:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54104) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iEHd4-0003qp-JQ for qemu-devel@nongnu.org; Sat, 28 Sep 2019 14:39:38 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CA598A44AC8 for ; Sat, 28 Sep 2019 18:39:37 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-117-142.ams2.redhat.com [10.36.117.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 75E035D6B0; Sat, 28 Sep 2019 18:39:37 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 3CDB511386A8; Sat, 28 Sep 2019 20:39:34 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 06/27] qapi: Clean up member name case checking Date: Sat, 28 Sep 2019 20:39:13 +0200 Message-Id: <20190928183934.12459-7-armbru@redhat.com> In-Reply-To: <20190928183934.12459-1-armbru@redhat.com> References: <20190928183934.12459-1-armbru@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.6.2 (mx1.redhat.com [10.5.110.68]); Sat, 28 Sep 2019 18:39:37 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" QAPISchemaMember.check_clash() checks for member names that map to the same c_name(). Takes care of rejecting duplicate names. It also checks a naming rule: no uppercase in member names. That's a rather odd place to do it. Enforcing naming rules is check_name_str()'s job. qapi-code-gen.txt specifies the name case rule applies to the name as it appears in the schema. check_clash() checks c_name(name) instead. No difference, as c_name() leaves alone case, but unclean. Move the name case check into check_name_str(), less the c_name(). New argument @permit_upper suppresses it. Pass permit_upper=3DTrue for definitions (which are not members), and when the member's owner is whitelisted with pragma name-case-whitelist. Bonus: name-case-whitelist now applies to a union's inline base, too. Update qapi/qapi-schema.json pragma to whitelist union CpuInfo instead of CpuInfo's implicit base type's name q_obj_CpuInfo-base. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <20190927134639.4284-6-armbru@redhat.com> --- qapi/qapi-schema.json | 2 +- scripts/qapi/common.py | 25 +++++++++++++----------- tests/qapi-schema/args-member-case.err | 2 +- tests/qapi-schema/args-member-case.json | 2 +- tests/qapi-schema/enum-member-case.err | 2 +- tests/qapi-schema/union-branch-case.err | 4 ++-- tests/qapi-schema/union-branch-case.json | 4 ++-- 7 files changed, 22 insertions(+), 19 deletions(-) diff --git a/qapi/qapi-schema.json b/qapi/qapi-schema.json index 920b03b0aa..9751b11f8f 100644 --- a/qapi/qapi-schema.json +++ b/qapi/qapi-schema.json @@ -71,7 +71,7 @@ 'QapiErrorClass', # all members, visible through errors 'UuidInfo', # UUID, visible through query-uuid 'X86CPURegister32', # all members, visible indirectly thro= ugh qom-get - 'q_obj_CpuInfo-base' # CPU, visible through query-cpu + 'CpuInfo' # CPU, visible through query-cpu ] } } =20 # Documentation generated with qapi-gen.py is in source order, with diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index f0e7d5ad34..ed4bff4479 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -704,8 +704,8 @@ valid_name =3D re.compile(r'^(__[a-zA-Z0-9.-]+_)?' '[a-zA-Z][a-zA-Z0-9_-]*$') =20 =20 -def check_name(info, source, name, allow_optional=3DFalse, - enum_member=3DFalse): +def check_name(info, source, name, + allow_optional=3DFalse, enum_member=3DFalse, permit_upper= =3DFalse): global valid_name membername =3D name =20 @@ -725,11 +725,14 @@ def check_name(info, source, name, allow_optional=3DF= alse, if not valid_name.match(membername) or \ c_name(membername, False).startswith('q_'): raise QAPISemError(info, "%s uses invalid name '%s'" % (source, na= me)) + if not permit_upper and name.lower() !=3D name: + raise QAPISemError( + info, "%s uses uppercase in name '%s'" % (source, name)) =20 =20 def add_name(name, info, meta): global all_names - check_name(info, "'%s'" % meta, name) + check_name(info, "'%s'" % meta, name, permit_upper=3DTrue) # FIXME should reject names that differ only in '_' vs. '.' # vs. '-', because they're liable to clash in generated C. if name in all_names: @@ -797,10 +800,12 @@ def check_type(info, source, value, raise QAPISemError(info, "%s should be an object or type name" % source) =20 + permit_upper =3D allow_dict in name_case_whitelist + # value is a dictionary, check that each member is okay for (key, arg) in value.items(): check_name(info, "Member of %s" % source, key, - allow_optional=3DTrue) + allow_optional=3DTrue, permit_upper=3Dpermit_upper) if c_name(key, False) =3D=3D 'u' or c_name(key, False).startswith(= 'has_'): raise QAPISemError(info, "Member of %s uses reserved name '%s'" % (source, key)) @@ -870,7 +875,7 @@ def check_union(expr, info): else: # The object must have a string or dictionary 'base'. check_type(info, "'base' for union '%s'" % name, - base, allow_dict=3DTrue, + base, allow_dict=3Dname, allow_metas=3D['struct']) if not base: raise QAPISemError(info, "Flat union '%s' must have a base" @@ -982,13 +987,15 @@ def check_enum(expr, info): raise QAPISemError(info, "Enum '%s' requires a string for 'prefix'" % na= me) =20 + permit_upper =3D name in name_case_whitelist + for member in members: check_known_keys(info, "member of enum '%s'" % name, member, ['name'], ['if']) check_if(member, info) normalize_if(member) check_name(info, "Member of enum '%s'" % name, member['name'], - enum_member=3DTrue) + enum_member=3DTrue, permit_upper=3Dpermit_upper) =20 =20 def check_struct(expr, info): @@ -997,7 +1004,7 @@ def check_struct(expr, info): features =3D expr.get('features') =20 check_type(info, "'data' for struct '%s'" % name, members, - allow_dict=3DTrue) + allow_dict=3Dname) check_type(info, "'base' for struct '%s'" % name, expr.get('base'), allow_metas=3D['struct']) =20 @@ -1555,10 +1562,6 @@ class QAPISchemaMember(object): =20 def check_clash(self, info, seen): cname =3D c_name(self.name) - if (cname.lower() !=3D cname - and self.defined_in not in name_case_whitelist): - raise QAPISemError(info, - "%s should not use uppercase" % self.descri= be()) if cname in seen: raise QAPISemError(info, "%s collides with %s" % (self.describe(), seen[cname].describe())) diff --git a/tests/qapi-schema/args-member-case.err b/tests/qapi-schema/arg= s-member-case.err index 725ba16192..da183957b2 100644 --- a/tests/qapi-schema/args-member-case.err +++ b/tests/qapi-schema/args-member-case.err @@ -1,2 +1,2 @@ tests/qapi-schema/args-member-case.json: In command 'no-way-this-will-get-= whitelisted': -tests/qapi-schema/args-member-case.json:2: 'Arg' (parameter of no-way-this= -will-get-whitelisted) should not use uppercase +tests/qapi-schema/args-member-case.json:2: Member of 'data' for command 'n= o-way-this-will-get-whitelisted' uses uppercase in name 'Arg' diff --git a/tests/qapi-schema/args-member-case.json b/tests/qapi-schema/ar= gs-member-case.json index 93439bee8b..e27c603548 100644 --- a/tests/qapi-schema/args-member-case.json +++ b/tests/qapi-schema/args-member-case.json @@ -1,2 +1,2 @@ -# Member names should be 'lower-case' unless the struct/command is whiteli= sted +# Member names should be 'lower-case' unless the struct is whitelisted { 'command': 'no-way-this-will-get-whitelisted', 'data': { 'Arg': 'int' } } diff --git a/tests/qapi-schema/enum-member-case.err b/tests/qapi-schema/enu= m-member-case.err index f6c872d3bf..8f2007c86f 100644 --- a/tests/qapi-schema/enum-member-case.err +++ b/tests/qapi-schema/enum-member-case.err @@ -1,2 +1,2 @@ tests/qapi-schema/enum-member-case.json: In enum 'NoWayThisWillGetWhitelis= ted': -tests/qapi-schema/enum-member-case.json:4: 'Value' (value of NoWayThisWill= GetWhitelisted) should not use uppercase +tests/qapi-schema/enum-member-case.json:4: Member of enum 'NoWayThisWillGe= tWhitelisted' uses uppercase in name 'Value' diff --git a/tests/qapi-schema/union-branch-case.err b/tests/qapi-schema/un= ion-branch-case.err index 8e81a2d0b6..09313d7f83 100644 --- a/tests/qapi-schema/union-branch-case.err +++ b/tests/qapi-schema/union-branch-case.err @@ -1,2 +1,2 @@ -tests/qapi-schema/union-branch-case.json: In union 'NoWayThisWillGetWhitel= isted': -tests/qapi-schema/union-branch-case.json:2: 'Branch' (branch of NoWayThisW= illGetWhitelisted) should not use uppercase +tests/qapi-schema/union-branch-case.json: In union 'Uni': +tests/qapi-schema/union-branch-case.json:2: Member of union 'Uni' uses upp= ercase in name 'Branch' diff --git a/tests/qapi-schema/union-branch-case.json b/tests/qapi-schema/u= nion-branch-case.json index e6565dc3b3..b7894b75d6 100644 --- a/tests/qapi-schema/union-branch-case.json +++ b/tests/qapi-schema/union-branch-case.json @@ -1,2 +1,2 @@ -# Branch names should be 'lower-case' unless the union is whitelisted -{ 'union': 'NoWayThisWillGetWhitelisted', 'data': { 'Branch': 'int' } } +# Branch names should be 'lower-case' +{ 'union': 'Uni', 'data': { 'Branch': 'int' } } --=20 2.21.0