a4c2edd290b84afb36b56b8bf28e1c26b0b8b0e2
[cython.git] / tests / wrappers / cpp_references.pyx
1 cimport cython
2
3
4 cdef extern from "cpp_references_helper.h":
5     cdef int& ref_func(int&)
6     
7     cdef int ref_var_value
8     cdef int& ref_var
9
10
11 def test_ref_func(int x):
12     """
13     >>> test_ref_func(2)
14     2
15     >>> test_ref_func(3)
16     3
17     """
18     return ref_func(x)
19
20 def test_ref_func_address(int x):
21     """
22     >>> test_ref_func_address(5)
23     5
24     >>> test_ref_func_address(7)
25     7
26     """
27     cdef int* i_ptr = &ref_func(x)
28     return i_ptr[0]
29
30 def test_ref_var(int x):
31     """
32     >>> test_ref_func(11)
33     11
34     >>> test_ref_func(13)
35     13
36     """
37     ref_var = x
38     return ref_var_value
39
40 def test_ref_assign(int x):
41     """
42     >>> test_ref_assign(17)
43     17.0
44     >>> test_ref_assign(19)
45     19.0
46     """
47     cdef double d = ref_func(x)
48     return d
49
50 @cython.infer_types(True)
51 def test_ref_inference(int x):
52     """
53     >>> test_ref_inference(23)
54     23
55     >>> test_ref_inference(29)
56     29
57     """
58     z = ref_func(x)
59     assert cython.typeof(z) == "int", cython.typeof(z)
60     return z