From 1d5644c786c99e8ec29465afcff35b660a0b0bfc Mon Sep 17 00:00:00 2001 From: Dag Sverre Seljebotn Date: Mon, 4 Aug 2008 20:41:41 +0200 Subject: [PATCH] Fixed bug: Empty "[]" is now always treated as array declarator --- Cython/Compiler/Parsing.py | 10 +++++++--- Cython/Compiler/Tests/TestBuffer.py | 4 +--- tests/compile/arrayargs.pyx | 13 +++++++++++++ 3 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 tests/compile/arrayargs.pyx diff --git a/Cython/Compiler/Parsing.py b/Cython/Compiler/Parsing.py index da3c44c0..949438bd 100644 --- a/Cython/Compiler/Parsing.py +++ b/Cython/Compiler/Parsing.py @@ -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 diff --git a/Cython/Compiler/Tests/TestBuffer.py b/Cython/Compiler/Tests/TestBuffer.py index 236140f4..5b924163 100644 --- a/Cython/Compiler/Tests/TestBuffer.py +++ b/Cython/Compiler/Tests/TestBuffer.py @@ -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 index 00000000..7a6429ec --- /dev/null +++ b/tests/compile/arrayargs.pyx @@ -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[]) -- 2.26.2