From patchwork Mon Oct 26 22:34:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 536334 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 BD6481412FD for ; Tue, 27 Oct 2015 09:36:00 +1100 (AEDT) Received: from localhost ([::1]:55555 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZqqMw-0004MX-D3 for incoming@patchwork.ozlabs.org; Mon, 26 Oct 2015 18:35:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54860) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZqqMB-0003Gi-Mu for qemu-devel@nongnu.org; Mon, 26 Oct 2015 18:35:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZqqM7-0006xC-Tm for qemu-devel@nongnu.org; Mon, 26 Oct 2015 18:35:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35481) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZqqM7-0006wv-NE for qemu-devel@nongnu.org; Mon, 26 Oct 2015 18:35:07 -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 68A70811D9; Mon, 26 Oct 2015 22:35:07 +0000 (UTC) Received: from red.redhat.com (ovpn-113-189.phx2.redhat.com [10.3.113.189]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t9QMZ4Dc006171; Mon, 26 Oct 2015 18:35:07 -0400 From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 26 Oct 2015 16:34:43 -0600 Message-Id: <1445898903-12082-5-git-send-email-eblake@redhat.com> In-Reply-To: <1445898903-12082-1-git-send-email-eblake@redhat.com> References: <1445898903-12082-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 v11 04/24] qapi: Reserve '*List' type names for list types 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 Type names ending in 'List' can clash with qapi list types in generated C. We don't currently use such names. It is easier to outlaw them now than to worry about how to resolve such a clash in the future. For precedence, see commit 4dc2e69, which did the same for names ending in 'Kind' versus implicit enum types for qapi unions. Update the testsuite to match. Signed-off-by: Eric Blake --- v11: shorter commit message, rebase to earlier changes v10: improve commit message, including a retitle (qapi list types may be JSON arrays, but they are C linked lists, not C arrays) v9: new patch --- docs/qapi-code-gen.txt | 3 ++- scripts/qapi.py | 10 ++++------ tests/qapi-schema/reserved-type-list.err | 1 + tests/qapi-schema/reserved-type-list.exit | 2 +- tests/qapi-schema/reserved-type-list.json | 6 +++--- tests/qapi-schema/reserved-type-list.out | 3 --- 6 files changed, 11 insertions(+), 14 deletions(-) diff --git a/docs/qapi-code-gen.txt b/docs/qapi-code-gen.txt index 2afab20..c4264a8 100644 --- a/docs/qapi-code-gen.txt +++ b/docs/qapi-code-gen.txt @@ -106,7 +106,8 @@ Types, commands, and events share a common namespace. Therefore, generally speaking, type definitions should always use CamelCase for user-defined type names, while built-in types are lowercase. Type definitions should not end in 'Kind', as this namespace is used for -creating implicit C enums for visiting union types. Command names, +creating implicit C enums for visiting union types, or in 'List', as +this namespace is used for creating array types. Command names, and field names within a type, should be all lower case with words separated by a hyphen. However, some existing older commands and complex types use underscore; when extending such expressions, diff --git a/scripts/qapi.py b/scripts/qapi.py index 3af4c2c..d53b5c4 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -390,10 +390,10 @@ def add_name(name, info, meta, implicit=False): raise QAPIExprError(info, "%s '%s' is already defined" % (all_names[name], name)) - if not implicit and name.endswith('Kind'): + if not implicit and (name.endswith('Kind') or name.endswith('List')): raise QAPIExprError(info, - "%s '%s' should not end in 'Kind'" - % (meta, name)) + "%s '%s' should not end in '%s'" + % (meta, name, name[-4:])) all_names[name] = meta @@ -1196,9 +1196,7 @@ class QAPISchema(object): return name def _make_array_type(self, element_type, info): - # TODO fooList namespace is not reserved; user can create collisions, - # or abuse our type system with ['fooList'] for 2D array - name = element_type + 'List' + name = element_type + 'List' # Use namespace reserved by add_name() if not self.lookup_type(name): self._def_entity(QAPISchemaArrayType(name, info, element_type)) return name diff --git a/tests/qapi-schema/reserved-type-list.err b/tests/qapi-schema/reserved-type-list.err index e69de29..4510fa6 100644 --- a/tests/qapi-schema/reserved-type-list.err +++ b/tests/qapi-schema/reserved-type-list.err @@ -0,0 +1 @@ +tests/qapi-schema/reserved-type-list.json:5: struct 'FooList' should not end in 'List' diff --git a/tests/qapi-schema/reserved-type-list.exit b/tests/qapi-schema/reserved-type-list.exit index 573541a..d00491f 100644 --- a/tests/qapi-schema/reserved-type-list.exit +++ b/tests/qapi-schema/reserved-type-list.exit @@ -1 +1 @@ -0 +1 diff --git a/tests/qapi-schema/reserved-type-list.json b/tests/qapi-schema/reserved-type-list.json index 5b7d0f9..98d53bf 100644 --- a/tests/qapi-schema/reserved-type-list.json +++ b/tests/qapi-schema/reserved-type-list.json @@ -1,5 +1,5 @@ # Potential C name collision -# FIXME - This parses and compiles on its own, but prevents the user from -# creating a type named 'Foo' and using ['Foo'] for an array. We should -# reject the use of any type names ending in 'List'. +# We reserve names ending in 'List' for use by array types. +# TODO - we could choose array names to avoid collision with user types, +# in order to let this compile { 'struct': 'FooList', 'data': { 's': 'str' } } diff --git a/tests/qapi-schema/reserved-type-list.out b/tests/qapi-schema/reserved-type-list.out index 0406bfe..e69de29 100644 --- a/tests/qapi-schema/reserved-type-list.out +++ b/tests/qapi-schema/reserved-type-list.out @@ -1,3 +0,0 @@ -object :empty -object FooList - member s: str optional=False