Commit 412b232e authored by Noam Hershtig's avatar Noam Hershtig

Create errors tests for conditional GILStatNode

parent 73133f68
......@@ -7826,11 +7826,18 @@ class GILStatNode(NogilTryFinallyStatNode):
if self.state == 'gil':
env.has_with_gil_block = True
if self.condition is not None:
self.condition.analyse_declarations(env)
return super(GILStatNode, self).analyse_declarations(env)
def analyse_expressions(self, env):
env.use_utility_code(
UtilityCode.load_cached("ForceInitThreads", "ModuleSetupCode.c"))
if self.condition is not None:
self.condition = self.condition.analyse_expressions(env)
was_nogil = env.nogil
env.nogil = self.state == 'nogil'
node = TryFinallyStatNode.analyse_expressions(self, env)
......
......@@ -4707,7 +4707,7 @@ class ConstantFolding(Visitor.VisitorTransform, SkipDeclarations):
# If condition is not constant we keep the GILStatNode as it is.
# Either it will later become constant (e.g. a `numeric is int`
# expression in a fused typed function) and then when ConstantFolding
# expression in a fused type function) and then when ConstantFolding
# runs again it will be handled or a later transform (i.e. GilCheck)
# will raise an error
return node
......
# 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
"""
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment