summaryrefslogtreecommitdiff
path: root/tests/run/cimport_from_pyx.srctree
blob: 602188748fde0d9bd8eecd75c111a52d938f2a38 (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
51
52
53
54
55
PYTHON setup.py build_ext --inplace
PYTHON -c "import a"

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

from Cython.Build.Dependencies import cythonize
import Cython.Compiler.Options
Cython.Compiler.Options.cimport_from_pyx = True

from distutils.core import setup

setup(
  ext_modules = cythonize("*.pyx"),
)

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

from b cimport Bclass, Bfunc, Bstruct, Benum, Benum_value, Btypedef, Py_EQ, Py_NE
cdef Bclass b = Bclass(5)
assert Bfunc(&b.value) == b.value
assert b.asStruct().value == b.value
cdef Btypedef b_type = &b.value
cdef Benum b_enum = Benum_value
cdef int tmp = Py_EQ

#from c cimport ClassC
#cdef ClassC c = ClassC()
#print c.value

######## b.pyx ########

from cpython.object cimport Py_EQ, Py_NE

cdef enum Benum:
    Benum_value

cdef struct Bstruct:
    int value

ctypedef long *Btypedef

cdef class Bclass:
    cdef long value
    def __init__(self, value):
        self.value = value
    cdef Bstruct asStruct(self):
        return Bstruct(value=self.value)

cdef long Bfunc(Btypedef x):
    return x[0]

######## c.pxd ########

cdef class ClassC:
    cdef int value