summaryrefslogtreecommitdiff
path: root/tests/run/cpp_call_stack_allocated.srctree
blob: 59228d2aee31b943e3f02dd3dc4dc507bd977d60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# tag: cpp

"""
PYTHON setup.py build_ext --inplace
PYTHON -c "from call_stack_allocated import test; test()"
"""

######## setup.py ########

from distutils.core import setup
from Cython.Build import cythonize
setup(ext_modules=cythonize('*.pyx', language='c++'))

######## call.cpp ########

class wint {
public:
  long long val;
  wint() { val = 0; }
  wint(long long val) { this->val = val; }
  long long &operator()() { return this->val; }
  long long operator()(long long i) { return this->val + i; }
  long long operator()(long long i, long long j) { return this->val + i + j; }
};

######## call.pxd ########

cdef extern from "call.cpp" nogil:
    cppclass wint:
        long long val
        wint()
        wint(long long val)
        long long& operator()()
        long long operator()(long long i)
        long long operator()(long long i, long long j)


######## call_stack_allocated.pyx ########

from call cimport wint
def test():
    cdef wint a = wint(4)
    cdef long long b = 3
    b = a()
    assert b == 4
    b = a(1ll)
    assert b == 5
    b = a(1ll, 1ll)
    assert b == 6