Commit d93be9df authored by Mark Florisson's avatar Mark Florisson

Allow nogil try/finally without 'with gil' block

parent f0cfc682
......@@ -2281,9 +2281,6 @@ class GilCheck(VisitorTransform):
# which is wrapped in a StatListNode. Just unpack that.
node.finally_clause, = node.finally_clause.stats
if node.state == 'gil':
self.seen_with_gil_statement = True
self.visitchildren(node)
self.nogil = was_nogil
return node
......@@ -2319,24 +2316,14 @@ class GilCheck(VisitorTransform):
def visit_TryFinallyStatNode(self, node):
"""
Take care of try/finally statements in nogil code sections. The
'try' must contain a 'with gil:' statement somewhere.
Take care of try/finally statements in nogil code sections.
"""
if not self.nogil or isinstance(node, Nodes.GILStatNode):
return self.visit_Node(node)
node.nogil_check = None
node.is_try_finally_in_nogil = True
# First, visit the body and check for errors
self.seen_with_gil_statement = False
self.visitchildren(node.body)
if not self.seen_with_gil_statement:
error(node.pos, "Cannot use try/finally in nogil sections unless "
"it contains a 'with gil' statement.")
self.visitchildren(node.finally_clause)
self.visitchildren(node)
return node
def visit_Node(self, node):
......
......@@ -159,6 +159,5 @@ _ERRORS = u"""
62:14: Coercion from Python not allowed without the GIL
62:25: Coercion from Python not allowed without the GIL
64:8: Try-except statement not allowed without gil
68:8: Cannot use try/finally in nogil sections unless it contains a 'with gil' statement.
85:8: For-loop using object bounds or target not allowed without gil
"""
......@@ -438,3 +438,21 @@ def test_nogil_try_finally_return():
"""
with nogil:
nogil_try_finally_return()
cdef int error_func() except -1 with gil:
raise Exception("propagate this")
def test_nogil_try_finally_error_label():
"""
>>> test_nogil_try_finally_error_label()
print me first
propagate this
"""
try:
with nogil:
try:
error_func()
finally:
with gil: print "print me first"
except Exception, e:
print e.args[0]
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