Commit fbed3e79 authored by Ian Henriksen's avatar Ian Henriksen

Added test for calling stack allocated c++ object.

parent d0e3a743
# 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; }
};
######## call.pxd ########
cdef extern from "call.cpp" nogil:
cppclass wint:
long long val
wint()
wint(long long val)
long long& operator()()
######## 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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment