Cython has moved to github.
cython-devel
view tests/run/pure.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 | ed6c1b3311af |
| children | c75f78dfbf7d |
line source
1 __doc__ = """
2 >>> test_sizeof()
3 True
4 True
5 True
6 True
7 True
9 >>> test_declare(100)
10 (100, 100)
11 >>> test_declare(100.5)
12 (100, 100)
13 >>> test_declare(None)
14 Traceback (most recent call last):
15 ...
16 TypeError: an integer is required
18 >>> test_cast(1.5)
19 1
20 >>> test_cast(None)
21 Traceback (most recent call last):
22 ...
23 TypeError: a float is required
25 >>> test_address(39)
26 39
28 >>> test_locals(5)
29 True
31 >>> test_struct(389, 1.64493)
32 (389, 1.64493)
34 >>> test_imports()
35 True
36 """
38 import cython
40 def test_sizeof():
41 x = cython.declare(cython.bint)
42 print sizeof(x) == sizeof(cython.bint)
43 print sizeof(cython.char) <= sizeof(cython.short) <= sizeof(cython.int) <= sizeof(cython.long) <= sizeof(cython.longlong)
44 print sizeof(cython.uint) == sizeof(cython.int)
45 print sizeof(cython.p_int) == sizeof(cython.p_double)
46 if cython.compiled:
47 print sizeof(cython.char) < sizeof(cython.longlong)
48 else:
49 print sizeof(cython.char) == 1
51 def test_declare(n):
52 x = cython.declare(cython.int)
53 y = cython.declare(cython.int, n)
54 if cython.compiled:
55 cython.declare(xx=cython.int, yy=cython.long)
56 sizeof(xx)
57 ptr = cython.declare(cython.p_int, cython.address(y))
58 return y, ptr[0]
60 @cython.locals(x=cython.double, n=cython.int)
61 def test_cast(x):
62 n = cython.cast(cython.int, x)
63 return n
65 @cython.locals(x=cython.int, y=cython.p_int)
66 def test_address(x):
67 y = cython.address(x)
68 return y[0]
70 @cython.locals(x=cython.int, y=cython.bint)
71 def test_locals(x):
72 y = x
73 return y
76 MyUnion = cython.union(n=cython.int, x=cython.double)
77 MyStruct = cython.struct(is_integral=cython.bint, data=MyUnion)
78 MyStruct2 = cython.typedef(MyStruct[2])
80 def test_struct(n, x):
81 a = cython.declare(MyStruct2)
82 a[0] = MyStruct(True, data=MyUnion(n=n))
83 a[1] = MyStruct(is_integral=False, data={'x': x})
84 return a[0].data.n, a[1].data.x
86 import cython as cy
87 from cython import declare, cast, locals, address, typedef, p_void, compiled
88 from cython import declare as my_declare, locals as my_locals, p_void as my_void_star, typedef as my_typedef, compiled as my_compiled
90 @my_locals(a=cython.p_void)
91 def test_imports():
92 a = cython.NULL
93 b = declare(p_void, cython.NULL)
94 c = my_declare(my_void_star, cython.NULL)
95 d = cy.declare(cy.p_void, cython.NULL)
96 return a == d and compiled and my_compiled
98 MyStruct3 = typedef(MyStruct[3])
99 MyStruct4 = my_typedef(MyStruct[4])
100 MyStruct5 = cy.typedef(MyStruct[5])
