File: cfuncptr.pyx

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 (54 lines) | stat: -rw-r--r-- 2,545 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
53
54
# mode: error

cdef int exceptmaybeminus2(int bad) except ?-2:
    if bad:
        raise RuntimeError
    else:
        return 0

def fail_exceptmaybeminus2(bad):
    cdef int (*fptr_a)(int) except -2
    cdef int (*fptr_b)(int) except -1
    cdef int (*fptr_c)(int) except ?-1
    fptr_a = exceptmaybeminus2
    fptr_b = exceptmaybeminus2
    fptr_c = exceptmaybeminus2

cdef extern from *:
    # define this as extern since Cython converts internal "except*" to "except -1"
    cdef int exceptstar(int bad) except *

    struct mystruct:
        int (*func_ptr)(int param) nogil
        void (*func_ptr_void)(int param) nogil

def fail_exceptstar(bad):
    cdef int (*fptr_a)(int) noexcept
    cdef int (*fptr_b)(int) except -1
    cdef int (*fptr_c)(int) except ?-1
    fptr_a = exceptstar
    fptr_b = exceptstar
    fptr_c = exceptstar

cdef int cb(int param) nogil:
    return param

cdef void cb_void(int param) except * nogil:
    return

def fail_struct_pointer():
    cdef mystruct ms = mystruct(&cb, &cb_void)


_ERRORS = """
13:13: Cannot assign type 'int (int) except? -2' to 'int (*)(int) except -2'. Exception values are incompatible.
14:13: Cannot assign type 'int (int) except? -2' to 'int (*)(int) except -1'. Exception values are incompatible.
15:13: Cannot assign type 'int (int) except? -2' to 'int (*)(int) except? -1'. Exception values are incompatible.
29:13: Cannot assign type 'int (int) except *' to 'int (*)(int) noexcept'. Exception values are incompatible. Suggest adding 'noexcept' to the type of 'exceptstar'.
30:13: Cannot assign type 'int (int) except *' to 'int (*)(int) except -1'. Exception values are incompatible.
31:13: Cannot assign type 'int (int) except *' to 'int (*)(int) except? -1'. Exception values are incompatible.
40:32: Cannot assign type 'int (*)(int) except? -1 nogil' to 'int (*)(int) noexcept nogil'. Exception values are incompatible. Suggest adding 'noexcept' to the type of the value being assigned.
40:32: Cannot assign type 'int (*)(int) except? -1 nogil' to 'int (*)(int) noexcept nogil'. Exception values are incompatible. Suggest adding 'noexcept' to the type of the value being assigned.
40:37: Cannot assign type 'void (*)(int) except * nogil' to 'void (*)(int) noexcept nogil'. Exception values are incompatible. Suggest adding 'noexcept' to the type of the value being assigned.
40:37: Cannot assign type 'void (*)(int) except * nogil' to 'void (*)(int) noexcept nogil'. Exception values are incompatible. Suggest adding 'noexcept' to the type of the value being assigned.
"""