Commit 1d5644c7 authored by Dag Sverre Seljebotn's avatar Dag Sverre Seljebotn

Fixed bug: Empty "[]" is now always treated as array declarator

parent 9262420f
...@@ -1620,15 +1620,19 @@ def p_c_simple_base_type(s, self_flag, nonempty): ...@@ -1620,15 +1620,19 @@ def p_c_simple_base_type(s, self_flag, nonempty):
# Treat trailing [] on type as buffer access # Treat trailing [] on type as buffer access
if not is_basic and s.sy == '[': if s.sy == '[':
return p_buffer_access(s, type_node) return p_buffer_access(s, type_node)
else: else:
return type_node return type_node
def p_buffer_access(s, type_node): def p_buffer_access(s, base_type_node):
# s.sy == '[' # s.sy == '['
pos = s.position() pos = s.position()
s.next() 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 = ( positional_args, keyword_args = (
p_positional_and_keyword_args(s, (']',), (0,), ('dtype',)) p_positional_and_keyword_args(s, (']',), (0,), ('dtype',))
) )
...@@ -1643,7 +1647,7 @@ def p_buffer_access(s, type_node): ...@@ -1643,7 +1647,7 @@ def p_buffer_access(s, type_node):
result = Nodes.CBufferAccessTypeNode(pos, result = Nodes.CBufferAccessTypeNode(pos,
positional_args = positional_args, positional_args = positional_args,
keyword_args = keyword_dict, keyword_args = keyword_dict,
base_type_node = type_node) base_type_node = base_type_node)
return result return result
......
...@@ -58,6 +58,7 @@ class TestBufferOptions(CythonTest): ...@@ -58,6 +58,7 @@ class TestBufferOptions(CythonTest):
self.assert_(self.expect_error) self.assert_(self.expect_error)
def parse_opts(self, opts, expect_error=False): def parse_opts(self, opts, expect_error=False):
assert opts != ""
s = u"def f():\n cdef object[%s] x" % opts s = u"def f():\n cdef object[%s] x" % opts
self.expect_error = expect_error self.expect_error = expect_error
root = self.fragment(s, pipeline=[NormalizeTree(self), PostParse(self)]).root root = self.fragment(s, pipeline=[NormalizeTree(self), PostParse(self)]).root
...@@ -89,9 +90,6 @@ class TestBufferOptions(CythonTest): ...@@ -89,9 +90,6 @@ class TestBufferOptions(CythonTest):
self.assert_(buf.dtype_node.signed == 0 and buf.dtype_node.longness == -1) self.assert_(buf.dtype_node.signed == 0 and buf.dtype_node.longness == -1)
self.assertEqual(3, buf.ndim) self.assertEqual(3, buf.ndim)
def test_dtype(self):
self.non_parse(ERR_BUF_MISSING % 'dtype', u"")
def test_ndim(self): def test_ndim(self):
self.parse_opts(u"int, 2") self.parse_opts(u"int, 2")
self.non_parse(ERR_BUF_INT % 'ndim', u"int, 'a'") self.non_parse(ERR_BUF_INT % 'ndim', u"int, 'a'")
......
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[])
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment