summaryrefslogtreecommitdiff
path: root/tests/errors/nogil_conditional.pyx
blob: e800eb1993ff2a1064098762b4b7bc5c68b4fb2b (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# cython: remove_unreachable=False
# mode: error

cdef int f_nogil(int x) nogil:
    cdef int y
    y = x + 10
    return y


def f_gil(x):
    y = 0
    y = x + 100
    return y


def illegal_gil_usage():
    cdef int res = 0
    with nogil(True):
        res = f_gil(res)

        with nogil(True):
            res = f_gil(res)

        with gil(False):
            res = f_gil(res)

    with nogil(False):
        res = f_nogil(res)


def foo(a):
    return a < 10


def non_constant_condition(int x) -> int:
    cdef int res = x
    with nogil(x < 10):
        res = f_nogil(res)

    with gil(foo(x)):
         res = f_gil(res)


ctypedef fused number_or_object:
    float
    object


def fused_type(number_or_object x):
    with nogil(number_or_object is object):
        res = x + 1

    # This should be fine
    with nogil(number_or_object is float):
        res = x + 1

    return res


_ERRORS = u"""
19:14: Accessing Python global or builtin not allowed without gil
19:19: Calling gil-requiring function not allowed without gil
19:19: Coercion from Python not allowed without the GIL
19:19: Constructing Python tuple not allowed without gil
19:20: Converting to Python object not allowed without gil
21:13: Trying to release the GIL while it was previously released.
22:18: Accessing Python global or builtin not allowed without gil
22:23: Calling gil-requiring function not allowed without gil
22:23: Coercion from Python not allowed without the GIL
22:23: Constructing Python tuple not allowed without gil
22:24: Converting to Python object not allowed without gil
25:18: Accessing Python global or builtin not allowed without gil
25:23: Calling gil-requiring function not allowed without gil
25:23: Coercion from Python not allowed without the GIL
25:23: Constructing Python tuple not allowed without gil
25:24: Converting to Python object not allowed without gil
37:17: Non-constant condition in a `with nogil(<condition>)` statement
40:16: Non-constant condition in a `with gil(<condition>)` statement
51:8: Assignment of Python object not allowed without gil
51:16: Calling gil-requiring function not allowed without gil
"""