3
from libc.string cimport strstr
11
cdef optargs(a, b=2, c=3):
14
ctypedef int (*cfuncptr_type)(int a, int b)
15
cdef int cfuncptr(int a, int b):
18
cdef cfuncptr_type get_cfuncptr():
28
@cython.test_fail_if_path_exists('//GeneralCallNode')
29
@cython.test_assert_path_exists('//SimpleCallNode')
30
def cfunc_all_keywords():
32
>>> cfunc_all_keywords()
35
return cfunc(a=1, b=2, c=3, d=4)
38
@cython.test_fail_if_path_exists('//GeneralCallNode')
39
@cython.test_assert_path_exists('//SimpleCallNode')
40
def cfunc_some_keywords():
42
>>> cfunc_some_keywords()
45
return cfunc(1, 2, c=3, d=4)
48
@cython.test_fail_if_path_exists('//GeneralCallNode')
49
@cython.test_assert_path_exists('//SimpleCallNode')
50
def cfunc_some_keywords_unordered():
52
>>> cfunc_some_keywords_unordered()
55
return cfunc(1, 2, d=4, c=3)
58
@cython.test_fail_if_path_exists('//GeneralCallNode')
59
@cython.test_assert_path_exists('//SimpleCallNode')
60
def cfunc_some_keywords_unordered_sideeffect():
63
>>> cfunc_some_keywords_unordered_sideeffect()
68
return cfunc(1, 2, d=side_effect(4), c=side_effect(3))
71
@cython.test_fail_if_path_exists('//GeneralCallNode')
72
@cython.test_assert_path_exists('//SimpleCallNode')
73
def cpfunc_all_keywords():
75
>>> cpfunc_all_keywords()
78
return cpfunc(a=1, b=2, c=3, d=4)
81
@cython.test_fail_if_path_exists('//GeneralCallNode')
82
@cython.test_assert_path_exists('//SimpleCallNode')
83
def cpfunc_some_keywords():
85
>>> cpfunc_some_keywords()
88
return cpfunc(1, 2, c=3, d=4)
91
@cython.test_fail_if_path_exists('//GeneralCallNode')
92
@cython.test_assert_path_exists('//SimpleCallNode')
93
def cpfunc_some_keywords_unordered():
95
>>> cpfunc_some_keywords_unordered()
98
return cpfunc(1, 2, d=4, c=3)
101
@cython.test_fail_if_path_exists('//GeneralCallNode')
102
@cython.test_assert_path_exists('//SimpleCallNode')
103
def cpfunc_some_keywords_unordered_sideeffect():
105
>>> del sideeffect[:]
106
>>> cpfunc_some_keywords_unordered_sideeffect()
111
return cpfunc(1, 2, d=side_effect(4), c=side_effect(3))
114
@cython.test_fail_if_path_exists('//GeneralCallNode')
115
@cython.test_assert_path_exists('//SimpleCallNode')
119
(True, True, True, True, True)
122
strstr("xabcy", "abc") is not NULL,
123
strstr("abc", "xabcy") is NULL,
124
strstr(needle="abc", haystack="xabcz") is not NULL,
125
strstr(needle="xabcz", haystack="abc") is NULL,
126
strstr(haystack="abc", needle="xabcz") is NULL,
130
@cython.test_fail_if_path_exists('//GeneralCallNode')
131
@cython.test_assert_path_exists('//SimpleCallNode')
153
print(optargs(11, 12))
154
print(optargs(11, b=12))
155
print(optargs(a=11, b=12))
156
print(optargs(b=12, a=11))
157
print(optargs(a=11, b=12))
159
print(optargs(11, 12, 13))
160
print(optargs(11, 12, c=13))
161
print(optargs(11, c=13, b=12))
162
print(optargs(a=11, b=12, c=13))
163
print(optargs(b=12, a=11, c=13))
164
print(optargs(b=12, c=13, a=11))
165
print(optargs(c=13, a=11, b=12))
168
@cython.test_fail_if_path_exists('//GeneralCallNode')
169
@cython.test_assert_path_exists('//SimpleCallNode')
178
cdef cfuncptr_type cfunc_ptr = get_cfuncptr()
186
# This works but currently brings up C compiler warnings
187
# because the format string is not a literal C string.
189
from libc.stdio cimport snprintf
191
@cython.test_fail_if_path_exists('//GeneralCallNode')
192
@cython.test_assert_path_exists('//SimpleCallNode')
199
retval = snprintf(buffer, template="abc", size=10)
202
return buffer[:retval].decode('ascii')
207
cdef cmeth(self, a, b, c, d):
210
@cython.test_fail_if_path_exists('//GeneralCallNode')
211
@cython.test_assert_path_exists('//SimpleCallNode')
212
def call_cmeth(self, ExtType ext):
224
print self.cmeth(1,2,3,4)
225
print self.cmeth(1,2,c=3,d=4)
226
print self.cmeth(a=1,b=2,c=3,d=4)
228
print ext.cmeth(1,2,3,4)
229
print ext.cmeth(1,2,c=3,d=4)
230
print ext.cmeth(a=1,b=2,c=3,d=4)
232
cpdef cpmeth(self, a, b, c, d):
235
@cython.test_fail_if_path_exists('//GeneralCallNode')
236
@cython.test_assert_path_exists('//SimpleCallNode')
237
def call_cpmeth(self, ExtType ext):
249
print self.cpmeth(1,2,3,4)
250
print self.cpmeth(1,2,c=3,d=4)
251
print self.cpmeth(a=1,b=2,c=3,d=4)
253
print ext.cpmeth(1,2,3,4)
254
print ext.cpmeth(1,2,c=3,d=4)
255
print ext.cpmeth(a=1,b=2,c=3,d=4)
257
cdef optargs(self, a=1, b=2):
260
@cython.test_fail_if_path_exists('//GeneralCallNode')
261
@cython.test_assert_path_exists('//SimpleCallNode')
262
def call_optargs(self, ExtType ext):
265
>>> x.call_optargs(x)
280
print self.optargs(3,4)
281
print self.optargs(3,b=4)
282
print self.optargs(a=3,b=4)
284
print self.optargs(3)
285
print self.optargs(a=3)
286
#print self.optargs(b=4)
288
print ext.optargs(3,4)
289
print ext.optargs(3,b=4)
290
print ext.optargs(a=3,b=4)
293
print ext.optargs(a=3)
294
#print ext.optargs(b=4)
296
cpdef cpmeth_optargs(self, a=1, b=2):
299
@cython.test_fail_if_path_exists('//GeneralCallNode')
300
@cython.test_assert_path_exists('//SimpleCallNode')
301
def call_cpmeth_optargs(self, ExtType ext):
304
>>> x.call_cpmeth_optargs(x)
319
print self.cpmeth_optargs(3,4)
320
print self.cpmeth_optargs(3,b=4)
321
print self.cpmeth_optargs(a=3,b=4)
322
print self.cpmeth_optargs()
323
print self.cpmeth_optargs(3)
324
print self.cpmeth_optargs(a=3)
325
#print self.cpmeth_optargs(b=4)
327
print ext.cpmeth_optargs(3,4)
328
print ext.cpmeth_optargs(3,b=4)
329
print ext.cpmeth_optargs(a=3,b=4)
330
print ext.cpmeth_optargs()
331
print ext.cpmeth_optargs(3)
332
print ext.cpmeth_optargs(a=3)
333
#print ext.cpmeth_optargs(b=4)
335
cpdef cpmeth_optargs1(self, a=1):
338
@cython.test_fail_if_path_exists('//GeneralCallNode')
339
@cython.test_assert_path_exists('//SimpleCallNode')
340
def call_cpmeth_optargs1(self, ExtType ext):
343
>>> x.call_cpmeth_optargs1(x)
352
print self.cpmeth_optargs1()
353
print self.cpmeth_optargs1(3)
354
print self.cpmeth_optargs1(a=3)
356
print ext.cpmeth_optargs1()
357
print ext.cpmeth_optargs1(3)
358
print ext.cpmeth_optargs1(a=3)