qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH v9 02/17] qapi: Reserve '*List' type names for array


From: Eric Blake
Subject: [Qemu-devel] [PATCH v9 02/17] qapi: Reserve '*List' type names for arrays
Date: Thu, 15 Oct 2015 22:15:27 -0600

We already reserved '*Kind' for implicit enums (since commit
4dc2e69), but failed to reserve '*List' for array types.  Since
no QMP was yet using it, we might as well make the reservation
official.

Note that this forbids creation of new types or commands ending
in 'List', but does NOT forbid abuse of attempts like ['intList']
for creating a 2-dimensional array of 'int'.  The whole idea of
multi-dimensional arrays needs more design thought, best left for
another day.

Signed-off-by: Eric Blake <address@hidden>

---
v9: new patch
---
 docs/qapi-code-gen.txt                  |  3 ++-
 scripts/qapi.py                         | 11 +++++------
 tests/qapi-schema/qapi-schema-test.json |  8 ++++----
 tests/qapi-schema/struct-name-list.err  |  1 +
 tests/qapi-schema/struct-name-list.exit |  2 +-
 tests/qapi-schema/struct-name-list.json |  6 +++---
 tests/qapi-schema/struct-name-list.out  |  3 ---
 7 files changed, 16 insertions(+), 18 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 9d53255..09ba44b 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[-4:] == 'Kind':
+    if not implicit and (name[-4:] == 'Kind' or name[-4:] == '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,8 @@ 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'
+        # TODO Should we worry about users abusing ['intList'] for 2-D array?
+        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/qapi-schema-test.json 
b/tests/qapi-schema/qapi-schema-test.json
index c842e22..81d19d0 100644
--- a/tests/qapi-schema/qapi-schema-test.json
+++ b/tests/qapi-schema/qapi-schema-test.json
@@ -106,10 +106,10 @@
             'any': ['any'] } }

 # Even if 'u' is forbidden as a struct member name, it should still be
-# valid as a type or union branch name. And although '*Kind' is forbidden
-# as a type name, it should not be forbidden as a member or branch name.
-# TODO - '*List' should also be forbidden as a type name, and 'has_*' as
-# a member name.
+# valid as a type or union branch name. And although '*Kind' and '*List'
+# are forbidden as type names, they should not be forbidden as a member
+# or branch name.
+# TODO - 'has_*' should also be forbidden as a member name.
 { 'struct': 'has_a', 'data': { 'MyKind': 'int', 'MyList': ['int'] } }
 { 'union': 'u', 'data': { 'u': 'uint8', 'myKind': 'has_a',
                           'myList': 'has_a' } }
diff --git a/tests/qapi-schema/struct-name-list.err 
b/tests/qapi-schema/struct-name-list.err
index e69de29..ee5b09b 100644
--- a/tests/qapi-schema/struct-name-list.err
+++ b/tests/qapi-schema/struct-name-list.err
@@ -0,0 +1 @@
+tests/qapi-schema/struct-name-list.json:5: struct 'FooList' should not end in 
'List'
diff --git a/tests/qapi-schema/struct-name-list.exit 
b/tests/qapi-schema/struct-name-list.exit
index 573541a..d00491f 100644
--- a/tests/qapi-schema/struct-name-list.exit
+++ b/tests/qapi-schema/struct-name-list.exit
@@ -1 +1 @@
-0
+1
diff --git a/tests/qapi-schema/struct-name-list.json 
b/tests/qapi-schema/struct-name-list.json
index 8ad38e6..98d53bf 100644
--- a/tests/qapi-schema/struct-name-list.json
+++ b/tests/qapi-schema/struct-name-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 non-array 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/struct-name-list.out 
b/tests/qapi-schema/struct-name-list.out
index 0406bfe..e69de29 100644
--- a/tests/qapi-schema/struct-name-list.out
+++ b/tests/qapi-schema/struct-name-list.out
@@ -1,3 +0,0 @@
-object :empty
-object FooList
-    member s: str optional=False
-- 
2.4.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]