summaryrefslogtreecommitdiff
path: root/tests/run/extern_impl_excvalue.srctree
blob: 2495d740c272fa84eeadc607a19071465aee95b4 (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
PYTHON setup.py build_ext --inplace
PYTHON -c "import foo"
PYTHON -c "import a"
PYTHON -c "import b"

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

from Cython.Build import cythonize
from distutils.core import setup

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

######## foo.pxd ########

cdef int bar() except *

cdef extern from "bar_impl.c":
    struct mystruct:
        int (*func_ptr)(int param) nogil

######## foo.pyx ########

cdef extern from "bar_impl.c":
    int bar() except *

######## bar_impl.c ########

static int bar() { return -1; }

typedef struct mystruct {
  int (*func_ptr)(int param);
} mystruct_t;

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

cimport cython
from foo cimport bar

assert bar() == -1


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

from foo cimport mystruct

cdef int cb(int param) noexcept nogil:
    return param

cdef mystruct ms = mystruct(&cb)
assert ms.func_ptr(5) == 5