summaryrefslogtreecommitdiff
path: root/tests/errors/nogil.pyx
blob: dfdebeebd86db200a1a2ce4d9efa129c3205808e (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# cython: remove_unreachable=False
# mode: error

cdef object f(object x) nogil:
    pass

cdef void g(int x) nogil:
    cdef object z
    z = None

cdef void h(int x) nogil:  # allowed
    p()

cdef object p() nogil:
    pass

cdef void r() nogil:  # allowed
    q()  # allowed

cdef object m():
    cdef object x, y = 0, obj
    cdef int i, j, k
    global fred
    q()
    with nogil:
        r()  # allowed to call plain C functions
        q()
        i = 42   # allowed with type inference
        obj = None
        17L  # allowed
        <object>7j
        help
        xxx = `"Hello"`
        import fred
        from fred import obj
        for x in obj:
            pass
        obj[i]
        obj[i:j]
        obj[i:j:k]
        obj.fred
        (x, y)
        [x, y]
        {x: y}
        {x, y}
        obj and x
        t(obj)
        f(42)
        x + obj
        -obj
        x = y = obj
        x, y = y, x
        obj[i] = x
        obj.fred = x
        print obj  # allowed!
        del fred
        return obj
        raise obj  # allowed!
        if obj:
            pass
        while obj:
            pass
        for x <= obj <= y:
            pass
        try:
            pass
        except:
            pass
        try:
            pass
        finally:
            pass

cdef void q():
    pass

cdef class C:
    pass

cdef void t(C c) nogil:
    pass

def ticket_338():
    cdef object obj
    with nogil:
        for obj from 0 <= obj < 4:
            pass

def bare_pyvar_name(object x):
    with nogil:
        x

cdef int fstrings(int x, object obj) except -1 nogil:
    f""         # allowed
    f"a"        # allowed
    f"a"f"b"    # allowed
    f"{x}"
    f"{obj}"


_ERRORS = u"""
4:5: Function with Python return type cannot be declared nogil
7:5: Function declared nogil has Python locals or temporaries
9:4: Assignment of Python object not allowed without gil
12:5: Discarding owned Python object not allowed without gil
14:5: Function with Python return type cannot be declared nogil
18:5: Calling gil-requiring function not allowed without gil
27:9: Calling gil-requiring function not allowed without gil
29:8: Assignment of Python object not allowed without gil
31:16: Constructing complex number not allowed without gil
33:8: Assignment of Python object not allowed without gil
33:14: Backquote expression not allowed without gil
34:15: Assignment of Python object not allowed without gil
34:15: Python import not allowed without gil
35:13: Python import not allowed without gil
35:25: Constructing Python list not allowed without gil
36:17: Iterating over Python object not allowed without gil
38:11: Discarding owned Python object not allowed without gil
38:11: Indexing Python object not allowed without gil
39:11: Discarding owned Python object not allowed without gil
39:11: Slicing Python object not allowed without gil
40:11: Constructing Python slice object not allowed without gil
40:11: Discarding owned Python object not allowed without gil
40:11: Indexing Python object not allowed without gil
40:12: Converting to Python object not allowed without gil
40:14: Converting to Python object not allowed without gil
40:16: Converting to Python object not allowed without gil
41:11: Accessing Python attribute not allowed without gil
41:11: Discarding owned Python object not allowed without gil
42:9: Constructing Python tuple not allowed without gil
42:9: Discarding owned Python object not allowed without gil
43:8: Constructing Python list not allowed without gil
43:8: Discarding owned Python object not allowed without gil
44:9: Constructing Python dict not allowed without gil
44:9: Discarding owned Python object not allowed without gil
45:9: Constructing Python set not allowed without gil
45:9: Discarding owned Python object not allowed without gil
46:12: Discarding owned Python object not allowed without gil
46:12: Truth-testing Python object not allowed without gil
47:10: Python type test not allowed without gil
48:9: Discarding owned Python object not allowed without gil
49:10: Discarding owned Python object not allowed without gil
49:10: Operation not allowed without gil
50:8: Discarding owned Python object not allowed without gil
50:8: Operation not allowed without gil
51:8: Assignment of Python object not allowed without gil
51:12: Assignment of Python object not allowed without gil
52:8: Assignment of Python object not allowed without gil
52:11: Assignment of Python object not allowed without gil
52:15: Creating temporary Python reference not allowed without gil
52:18: Creating temporary Python reference not allowed without gil
53:11: Assignment of Python object not allowed without gil
53:11: Indexing Python object not allowed without gil
54:11: Accessing Python attribute not allowed without gil
54:11: Assignment of Python object not allowed without gil

56:8: Deleting Python object not allowed without gil
57:8: Returning Python object not allowed without gil

59:11: Truth-testing Python object not allowed without gil
61:14: Truth-testing Python object not allowed without gil
63:8: For-loop using object bounds or target not allowed without gil
63:12: Coercion from Python not allowed without the GIL
63:24: Coercion from Python not allowed without the GIL
65:8: Try-except statement not allowed without gil
86:8: For-loop using object bounds or target not allowed without gil

97:4: Discarding owned Python object not allowed without gil
97:6: String formatting not allowed without gil
98:4: Discarding owned Python object not allowed without gil
98:6: String formatting not allowed without gil
"""