From 64ad2013e4f71675083ed5d3896c63b256f7b18b Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Sun, 21 Feb 2010 01:41:28 -0800 Subject: [PATCH] Parsing fix, vector test. --- Cython/Compiler/Parsing.py | 4 ++-- tests/run/cpp_stl_vector.pyx | 25 +++++++++++++++++++++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/Cython/Compiler/Parsing.py b/Cython/Compiler/Parsing.py index f35498f1..b234963a 100644 --- a/Cython/Compiler/Parsing.py +++ b/Cython/Compiler/Parsing.py @@ -1853,13 +1853,13 @@ def p_c_simple_base_type(s, self_flag, nonempty, templates = None): # Make sure this is not a declaration of a variable or function. if s.sy == '(': s.next() - if s.sy == '*' or s.sy == '**': + if s.sy == '*' or s.sy == '**' or s.sy == '&': s.put_back('(', '(') else: s.put_back('(', '(') s.put_back('IDENT', name) name = None - elif s.sy not in ('*', '**', '['): + elif s.sy not in ('*', '**', '[', '&'): s.put_back('IDENT', name) name = None diff --git a/tests/run/cpp_stl_vector.pyx b/tests/run/cpp_stl_vector.pyx index 159d2bd0..eee6ef89 100644 --- a/tests/run/cpp_stl_vector.pyx +++ b/tests/run/cpp_stl_vector.pyx @@ -1,16 +1,17 @@ +from cython.operator cimport dereference as d + cdef extern from "" namespace "std": cdef cppclass vector[T]: void push_back(T) size_t size() - T operator[](size_t) + T& operator[](size_t) def simple_test(double x): """ >>> simple_test(55) 3 """ - cdef vector[double] *v try: v = new vector[double]() v.push_back(1.0) @@ -30,7 +31,6 @@ def list_test(L): >>> list_test([-1] * 1000) (1000, 1000) """ - cdef vector[int] *v try: v = new vector[int]() for a in L: @@ -46,7 +46,6 @@ def index_test(L): >>> index_test([1.25]) (1.25, 1.25) """ - cdef vector[double] *v try: v = new vector[double]() for a in L: @@ -54,3 +53,21 @@ def index_test(L): return v[0][0], v[0][len(L)-1] finally: del v + + +def index_set_test(L): + """ + >>> index_set_test([1,2,4,8]) + (-1.0, -8.0) + >>> index_set_test([1.25]) + (-1.25, -1.25) + """ + try: + v = new vector[double]() + for a in L: + v.push_back(a) + for i in range(v.size()): + d(v)[i] = -d(v)[i] + return d(v)[0], d(v)[v.size()-1] + finally: + del v -- 2.26.2