Fixed bug: Empty "[]" is now always treated as array declarator
authorDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Mon, 4 Aug 2008 18:41:41 +0000 (20:41 +0200)
committerDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Mon, 4 Aug 2008 18:41:41 +0000 (20:41 +0200)
Cython/Compiler/Parsing.py
Cython/Compiler/Tests/TestBuffer.py
tests/compile/arrayargs.pyx [new file with mode: 0644]

index da3c44c0aa1060d9e8298552075a7f78c3caff24..949438bd1d63c5d78c2a1724300f25450ca4be9c 100644 (file)
@@ -1620,15 +1620,19 @@ def p_c_simple_base_type(s, self_flag, nonempty):
 
 
     # Treat trailing [] on type as buffer access
-    if not is_basic and s.sy == '[':
+    if s.sy == '[':
         return p_buffer_access(s, type_node)
     else:
         return type_node
 
-def p_buffer_access(s, type_node):
+def p_buffer_access(s, base_type_node):
     # s.sy == '['
     pos = s.position()
     s.next()
+    if s.sy == ']':
+        # not buffer, could be [] on C type nameless array arguments
+        s.put_back('[', '[')
+        return base_type_node
     positional_args, keyword_args = (
         p_positional_and_keyword_args(s, (']',), (0,), ('dtype',))
     )
@@ -1643,7 +1647,7 @@ def p_buffer_access(s, type_node):
     result = Nodes.CBufferAccessTypeNode(pos,
         positional_args = positional_args,
         keyword_args = keyword_dict,
-        base_type_node = type_node)
+        base_type_node = base_type_node)
     return result
     
 
index 236140f47fa7815ba667b0cb88484fa8b8e140a4..5b9241636af48237ddc908537e725c50a37299bc 100644 (file)
@@ -58,6 +58,7 @@ class TestBufferOptions(CythonTest):
         self.assert_(self.expect_error)
 
     def parse_opts(self, opts, expect_error=False):
+        assert opts != ""
         s = u"def f():\n  cdef object[%s] x" % opts
         self.expect_error = expect_error
         root = self.fragment(s, pipeline=[NormalizeTree(self), PostParse(self)]).root
@@ -89,9 +90,6 @@ class TestBufferOptions(CythonTest):
         self.assert_(buf.dtype_node.signed == 0 and buf.dtype_node.longness == -1)
         self.assertEqual(3, buf.ndim)
         
-    def test_dtype(self):
-        self.non_parse(ERR_BUF_MISSING % 'dtype', u"")
-    
     def test_ndim(self):
         self.parse_opts(u"int, 2")
         self.non_parse(ERR_BUF_INT % 'ndim', u"int, 'a'")
diff --git a/tests/compile/arrayargs.pyx b/tests/compile/arrayargs.pyx
new file mode 100644 (file)
index 0000000..7a6429e
--- /dev/null
@@ -0,0 +1,13 @@
+cdef extern from *:
+
+    cdef void foo(int[])
+
+    ctypedef int MyInt
+    cdef void foo(MyInt[])
+
+    struct MyStruct:
+        pass
+    cdef void bar(MyStruct[])
+
+    ctypedef MyStruct* MyStructP
+    cdef void baz(MyStructP[])