From patchwork Fri Oct 23 05:09:56 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 534781 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 80B11141332 for ; Fri, 23 Oct 2015 16:14:42 +1100 (AEDT) Received: from localhost ([::1]:36056 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZpUga-0006ki-G8 for incoming@patchwork.ozlabs.org; Fri, 23 Oct 2015 01:14:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55672) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZpUcI-0007BR-E4 for qemu-devel@nongnu.org; Fri, 23 Oct 2015 01:10:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZpUcH-0003LM-5V for qemu-devel@nongnu.org; Fri, 23 Oct 2015 01:10:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42937) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZpUcG-0003L5-Vb for qemu-devel@nongnu.org; Fri, 23 Oct 2015 01:10:13 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 93C8A3CA98E; Fri, 23 Oct 2015 05:10:12 +0000 (UTC) Received: from red.redhat.com (ovpn-113-176.phx2.redhat.com [10.3.113.176]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t9N59xEO026589; Fri, 23 Oct 2015 01:10:12 -0400 From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 22 Oct 2015 23:09:56 -0600 Message-Id: <1445576998-2921-24-git-send-email-eblake@redhat.com> In-Reply-To: <1445576998-2921-1-git-send-email-eblake@redhat.com> References: <1445576998-2921-1-git-send-email-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: armbru@redhat.com, Michael Roth Subject: [Qemu-devel] [PATCH v10 23/25] qapi: Reserve 'u' member name X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Now that we have separated union tag values from colliding with non-variant C names, by naming the union 'u', we should reserve this name for our use. Note that we want to forbid 'u' even in a struct with no variants, because it is possible for a future qemu release to extend QMP in a backwards-compatible manner while converting from a struct to a flat union. Fortunately, no existing clients were using this member name. If we ever find the need for QMP to have a member 'u', we could at that time relax things, perhaps by having c_name() munge the QMP member to 'q_u'. Note that we cannot forbid 'u' everywhere (by adding the rejection code to check_name()), because the existing QKeyCode enum already uses it. And it is still okay to use it as a branch name within a union, although not worth adding a positive test to qapi-schema-test for this corner case. Signed-off-by: Eric Blake --- v10: new patch, split from 1/17 and 3/17; by deferring this until after the rename was complete, it reduces churn due to the new feature --- scripts/qapi.py | 2 +- tests/Makefile | 1 + tests/qapi-schema/struct-member-u.err | 1 + tests/qapi-schema/struct-member-u.exit | 1 + tests/qapi-schema/struct-member-u.json | 7 +++++++ tests/qapi-schema/struct-member-u.out | 0 6 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 tests/qapi-schema/struct-member-u.err create mode 100644 tests/qapi-schema/struct-member-u.exit create mode 100644 tests/qapi-schema/struct-member-u.json create mode 100644 tests/qapi-schema/struct-member-u.out diff --git a/tests/qapi-schema/struct-member-u.out b/tests/qapi-schema/struct-member-u.out new file mode 100644 index 0000000..e69de29 diff --git a/scripts/qapi.py b/scripts/qapi.py index 8b9f5f7..b941ccf 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -490,7 +490,7 @@ def check_type(expr_info, source, value, allow_array=False, for (key, arg) in value.items(): check_name(expr_info, "Member of %s" % source, key, allow_optional=allow_optional) - if c_name(key).startswith('has_'): + if key == 'u' or c_name(key).startswith('has_'): raise QAPIExprError(expr_info, "Member of %s uses reserved name '%s'" % (source, key)) diff --git a/tests/Makefile b/tests/Makefile index 9194264..8c239f8 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -326,6 +326,7 @@ qapi-schema += struct-base-clash-deep.json qapi-schema += struct-base-clash.json qapi-schema += struct-data-invalid.json qapi-schema += struct-member-invalid.json +qapi-schema += struct-member-u.json qapi-schema += struct-name-list.json qapi-schema += trailing-comma-list.json qapi-schema += trailing-comma-object.json diff --git a/tests/qapi-schema/struct-member-u.err b/tests/qapi-schema/struct-member-u.err new file mode 100644 index 0000000..0dc354c --- /dev/null +++ b/tests/qapi-schema/struct-member-u.err @@ -0,0 +1 @@ +tests/qapi-schema/struct-member-u.json:7: Member of 'data' for struct 'Oops' uses reserved name 'u' diff --git a/tests/qapi-schema/struct-member-u.exit b/tests/qapi-schema/struct-member-u.exit new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/tests/qapi-schema/struct-member-u.exit @@ -0,0 +1 @@ +1 diff --git a/tests/qapi-schema/struct-member-u.json b/tests/qapi-schema/struct-member-u.json new file mode 100644 index 0000000..1eaf0f3 --- /dev/null +++ b/tests/qapi-schema/struct-member-u.json @@ -0,0 +1,7 @@ +# Potential C member name collision +# We reject use of 'u' as a member name, to allow it for internal use in +# putting union branch members in a separate namespace from QMP members. +# This is true even for non-unions, because it is possible to convert a +# struct to flat union while remaining backwards compatible in QMP. +# TODO - we could munge the member name to 'q_u' to avoid the collision +{ 'struct': 'Oops', 'data': { 'u': 'str' } }