qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 04/25] qapi: Reserve '*List' type names for list types
Date: Fri, 30 Oct 2015 16:42:33 +0100	[thread overview]
Message-ID: <1446219774-1802-5-git-send-email-armbru@redhat.com> (raw)
In-Reply-To: <1446219774-1802-1-git-send-email-armbru@redhat.com>

From: Eric Blake <eblake@redhat.com>

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 <eblake@redhat.com>
Message-Id: <1445898903-12082-5-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 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
-- 
2.4.3

  parent reply	other threads:[~2015-10-30 15:43 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-30 15:42 [Qemu-devel] [PULL 00/25] QAPI patches Markus Armbruster
2015-10-30 15:42 ` [Qemu-devel] [PULL 01/25] tests/qapi-schema: Test for reserved names, empty struct Markus Armbruster
2015-10-30 15:42 ` [Qemu-devel] [PULL 02/25] qapi: More idiomatic string operations Markus Armbruster
2015-10-30 15:42 ` [Qemu-devel] [PULL 03/25] qapi: More robust conditions for when labels are needed Markus Armbruster
2015-10-30 15:42 ` Markus Armbruster [this message]
2015-10-30 15:42 ` [Qemu-devel] [PULL 05/25] qapi: Reserve 'q_*' and 'has_*' member names Markus Armbruster
2015-10-30 15:42 ` [Qemu-devel] [PULL 06/25] vnc: Hoist allocation of VncBasicInfo to callers Markus Armbruster
2015-10-30 15:42 ` [Qemu-devel] [PULL 07/25] qapi-visit: Split off visit_type_FOO_fields forward decl Markus Armbruster
2015-10-30 15:42 ` [Qemu-devel] [PULL 08/25] qapi-types: Refactor base fields output Markus Armbruster
2015-10-30 15:42 ` [Qemu-devel] [PULL 09/25] qapi: Prefer typesafe upcasts to qapi base classes Markus Armbruster
2015-10-30 15:42 ` [Qemu-devel] [PULL 10/25] qapi: Unbox base members Markus Armbruster
2015-10-30 15:42 ` [Qemu-devel] [PULL 11/25] qapi-visit: Remove redundant functions for flat union base Markus Armbruster
2015-10-30 15:42 ` [Qemu-devel] [PULL 12/25] qapi: Start converting to new qapi union layout Markus Armbruster
2015-10-30 15:42 ` [Qemu-devel] [PULL 13/25] qapi-visit: Convert " Markus Armbruster
2015-10-30 15:42 ` [Qemu-devel] [PULL 14/25] tests: " Markus Armbruster
2015-10-30 15:42 ` [Qemu-devel] [PULL 15/25] block: " Markus Armbruster
2015-10-30 15:42 ` [Qemu-devel] [PULL 16/25] sockets: " Markus Armbruster
2015-10-30 15:42 ` [Qemu-devel] [PULL 17/25] net: " Markus Armbruster
2015-10-30 15:42 ` [Qemu-devel] [PULL 18/25] char: " Markus Armbruster
2015-10-30 20:01   ` [Qemu-devel] [PATCH] fixup! " Eric Blake
2015-11-02  9:10     ` Markus Armbruster
2015-10-30 15:42 ` [Qemu-devel] [PULL 19/25] input: " Markus Armbruster
2015-10-30 15:42 ` [Qemu-devel] [PULL 20/25] memory: " Markus Armbruster
2015-10-30 15:42 ` [Qemu-devel] [PULL 21/25] tpm: " Markus Armbruster
2015-10-30 15:42 ` [Qemu-devel] [PULL 22/25] qapi: Finish converting " Markus Armbruster
2015-10-30 15:42 ` [Qemu-devel] [PULL 23/25] qapi: Reserve 'u' member name Markus Armbruster
2015-10-30 15:42 ` [Qemu-devel] [PULL 24/25] qapi: Simplify gen_struct_field() Markus Armbruster
2015-10-30 15:42 ` [Qemu-devel] [PULL 25/25] qapi-schema: mark InetSocketAddress as mandatory again Markus Armbruster
2015-10-30 19:47 ` [Qemu-devel] [PULL 00/25] QAPI patches Peter Maydell
2015-10-30 20:03   ` Eric Blake
2015-10-30 20:10     ` Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1446219774-1802-5-git-send-email-armbru@redhat.com \
    --to=armbru@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).