From 3aad1ec52c84c23680ca56942de227f1e7604e3d Mon Sep 17 00:00:00 2001 From: Dag Sverre Seljebotn Date: Wed, 13 Aug 2008 21:18:12 +0200 Subject: [PATCH] Fixed buffer [] syntax yet another time --- Cython/Compiler/Parsing.py | 13 +++++++------ tests/compile/arrayargs.pyx | 6 ++++++ 2 files changed, 13 insertions(+), 6 deletions(-) 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]) + -- 2.26.2