File: extern_impl_excvalue.srctree

package info (click to toggle)
cython 3.0.11%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 19,092 kB
  • sloc: python: 83,539; ansic: 18,831; cpp: 1,402; xml: 1,031; javascript: 511; makefile: 403; sh: 204; sed: 11
file content (52 lines) | stat: -rw-r--r-- 859 bytes parent folder | download
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