Cython has moved to github.

cython-devel

view tests/run/r_forloop.pyx @ 1622:4f0327bdebc9

test for temp allocation bug in call
author Robert Bradshaw <robertwb@math.washington.edu>
date Sat Jan 17 01:25:34 2009 -0800 (3 years ago)
parents cb1a842e882d
children 82d312a9f1fc
line source
1 __doc__ = u"""
2 >>> go_py()
3 Spam!
4 Spam!
5 Spam!
6 Spam!
7 >>> go_py_ret()
8 2
10 >>> go_c()
11 Spam!
12 Spam!
13 Spam!
14 Spam!
15 >>> go_c_int(1,5)
16 Spam!
17 Spam!
18 >>> go_c_enumerate()
19 True
20 True
21 True
22 True
23 >>> go_c_all()
24 Spam!
25 Spam!
26 Spam!
27 >>> go_c_all_exprs(1)
28 Spam!
29 >>> go_c_all_exprs(3)
30 Spam!
31 Spam!
32 >>> go_c_const_exprs()
33 Spam!
34 Spam!
35 >>> go_c_calc(2)
36 Spam!
37 Spam!
38 >>> go_c_ret()
39 2
40 >>> go_c_calc_ret(2)
41 6
43 >>> go_list()
44 Spam!
45 Spam!
46 Spam!
47 Spam!
48 >>> go_list_ret()
49 2
51 >>> go_tuple()
52 Spam!
53 Spam!
54 Spam!
55 Spam!
56 >>> go_tuple_ret()
57 2
59 >>> go_dict()
60 Spam!
61 Spam!
62 Spam!
63 Spam!
64 >>> go_dict_ret()
65 2
67 >>> global_result
68 6
69 """
71 def go_py():
72 for i in range(4):
73 print u"Spam!"
75 def go_py_ret():
76 for i in range(4):
77 if i > 1:
78 return i
80 def go_c():
81 cdef int i
82 for i in range(4):
83 print u"Spam!"
85 def go_c_enumerate():
86 cdef int i,k
87 for i,k in enumerate(range(4)):
88 print i == k
90 def go_c_int(int a, int b):
91 cdef int i
92 for i in range(a,b,2):
93 print u"Spam!"
95 def go_c_all():
96 cdef int i
97 for i in range(8,2,-2):
98 print u"Spam!"
100 def go_c_all_exprs(x):
101 cdef int i
102 for i in range(4*x,2*x,-3):
103 print u"Spam!"
105 def go_c_const_exprs():
106 cdef int i
107 for i in range(4*2+1,2*2,-2-1):
108 print u"Spam!"
110 def f(x):
111 return 2*x
113 def go_c_calc(x):
114 cdef int i
115 for i in range(2*f(x),f(x), -2):
116 print u"Spam!"
118 def go_c_calc_ret(x):
119 cdef int i
120 for i in range(2*f(x),f(x), -2):
121 if i < 2*f(x):
122 return i
124 def go_c_ret():
125 cdef int i
126 for i in range(4):
127 if i > 1:
128 return i
130 def go_list():
131 cdef list l = list(range(4))
132 for i in l:
133 print u"Spam!"
135 def go_list_ret():
136 cdef list l = list(range(4))
137 for i in l:
138 if i > 1:
139 return i
141 def go_tuple():
142 cdef tuple t = tuple(range(4))
143 for i in t:
144 print u"Spam!"
146 def go_tuple_ret():
147 cdef tuple t = tuple(range(4))
148 for i in t:
149 if i > 1:
150 return i
152 def go_dict():
153 cdef dict d = dict(zip(range(4), range(4)))
154 for i in d:
155 print u"Spam!"
157 def go_dict_ret():
158 cdef dict d = dict(zip(range(4), range(4)))
159 for i in d:
160 if i > 1 and i < 3:
161 return i
163 # test global scope also
164 global_result = None
165 cdef int i
166 for i in range(4*2+1,2*2,-2-1):
167 if i < 7:
168 global_result = i
169 break