From: Dag Sverre Seljebotn Date: Wed, 13 Aug 2008 19:18:12 +0000 (+0200) Subject: Fixed buffer [] syntax yet another time X-Git-Tag: 0.9.8.1~49^2~3 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=3aad1ec52c84c23680ca56942de227f1e7604e3d;p=cython.git Fixed buffer [] syntax yet another time --- diff --git a/Cython/Compiler/Parsing.py b/Cython/Compiler/Parsing.py index 2607060e..d2863db3 100644 --- a/Cython/Compiler/Parsing.py +++ b/Cython/Compiler/Parsing.py @@ -1627,8 +1627,13 @@ def p_c_simple_base_type(s, self_flag, nonempty): longness = longness, is_self_arg = self_flag) - # Treat trailing [] on type as buffer access - if s.sy == '[': + # Treat trailing [] on type as buffer access if it appears in a context + # where declarator names are required (so that it cannot mean int[] or + # sizeof(int[SIZE]))... + # + # (This means that buffers cannot occur where there can be empty declarators, + # which is an ok restriction to make.) + if nonempty and s.sy == '[': return p_buffer_access(s, type_node) else: return type_node @@ -1637,10 +1642,6 @@ def p_buffer_access(s, base_type_node): # s.sy == '[' pos = s.position() s.next() - if s.sy == ']' or s.sy == 'INT': - # 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',)) ) diff --git a/tests/compile/arrayargs.pyx b/tests/compile/arrayargs.pyx index 2a18093e..535e4319 100644 --- a/tests/compile/arrayargs.pyx +++ b/tests/compile/arrayargs.pyx @@ -1,3 +1,4 @@ + cdef extern from *: cdef void foo(int[]) @@ -17,3 +18,8 @@ cdef struct OtherStruct: a = sizeof(int[23][34]) b = sizeof(OtherStruct[43]) + +DEF COUNT = 4 +c = sizeof(int[COUNT]) +d = sizeof(OtherStruct[COUNT]) +