summaryrefslogtreecommitdiff
path: root/tests/build/build_ext_cython_cplus.srctree
blob: 73a61df04cd9780ec02b55c1e95d04e9106e1721 (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
# tag: cpp

PYTHON setup.py build_ext --inplace --cython-cplus
PYTHON -c "import a; a.use_vector([1,2,3])"

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

from Cython.Distutils.extension import Extension
from Cython.Build import build_ext
from distutils.core import setup

setup(
    name='Hello world app',
    ext_modules = [
        Extension(
            name = 'a',
            sources=['a.pyx'],
        )
    ],
    cmdclass={'build_ext': build_ext},
)

######## a.pyx ########

from libcpp.vector cimport vector

def use_vector(L):
    try:
        v = new vector[int]()
        for a in L:
            v.push_back(a)
        return v.size()
    finally:
        del v