Cython has moved to github.

cython-devel

view tests/run/struct_conversion.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 33ed4ad07703
children 0310198e281e
line source
1 __doc__ = """
2 >>> test_constructor(1,2,255)
3 {'y': 2.0, 'x': 1.0, 'color': 255}
4 >>> test_constructor(1,None,255)
5 Traceback (most recent call last):
6 ...
7 TypeError: a float is required
9 >>> test_constructor_kwds(1.25, 2.5, 128)
10 {'y': 2.5, 'x': 1.25, 'color': 128}
11 >>> test_constructor_kwds(1.25, 2.5, None)
12 Traceback (most recent call last):
13 ...
14 TypeError: an integer is required
16 >>> test_dict_construction(4, 5, 64)
17 {'y': 5.0, 'x': 4.0, 'color': 64}
18 >>> test_dict_construction("foo", 5, 64)
19 Traceback (most recent call last):
20 ...
21 TypeError: a float is required
23 >>> test_pointers(100, 2.71828)
24 100
25 2.71828
26 True
27 """
29 cdef struct Point:
30 double x
31 double y
32 int color
34 def test_constructor(x, y, color):
35 cdef Point p = Point(x, y, color)
36 return p
38 def test_constructor_kwds(x, y, color):
39 cdef Point p = Point(x=x, y=y, color=color)
40 return p
42 def test_dict_construction(x, y, color):
43 cdef Point p = {'color': color, 'x': x, 'y': y}
44 return p
46 cdef union int_or_float:
47 int n
48 double x
50 cdef struct with_pointers:
51 bint is_integral
52 int_or_float data
53 void* ptr
55 def test_pointers(int n, double x):
56 cdef with_pointers a = [True, {'n': n}, NULL]
57 cdef with_pointers b = with_pointers(False, {'x': x}, NULL)
58 print a.data.n
59 print b.data.x
60 print a.ptr == b.ptr == NULL