Commit 4d34d4e7 authored by Mark Florisson's avatar Mark Florisson

cython.parallel: Use restore exception utility code when code.error_label is used

--HG--
extra : transplant_source : %27mb%12_V%3D%F4%A3%B2%03%DC%1Ew%F1%23%B8P%A4Q
parent f55ea374
...@@ -6404,6 +6404,7 @@ class ParallelStatNode(StatNode, ParallelNode): ...@@ -6404,6 +6404,7 @@ class ParallelStatNode(StatNode, ParallelNode):
code.put_goto(code.return_label) code.put_goto(code.return_label)
if self.error_label_used: if self.error_label_used:
code.globalstate.use_utility_code(restore_exception_utility_code)
code.putln(" case 4:") code.putln(" case 4:")
self.restore_parallel_exception(code) self.restore_parallel_exception(code)
code.put_goto(code.error_label) code.put_goto(code.error_label)
...@@ -6485,7 +6486,7 @@ class ParallelRangeNode(ParallelStatNode): ...@@ -6485,7 +6486,7 @@ class ParallelRangeNode(ParallelStatNode):
is_prange = True is_prange = True
nogil = False nogil = None
schedule = None schedule = None
num_threads = None num_threads = None
...@@ -6522,6 +6523,10 @@ class ParallelRangeNode(ParallelStatNode): ...@@ -6522,6 +6523,10 @@ class ParallelRangeNode(ParallelStatNode):
(self.schedule,)) (self.schedule,))
def analyse_expressions(self, env): def analyse_expressions(self, env):
if self.nogil:
was_nogil = env.nogil
env.nogil = True
if self.target is None: if self.target is None:
error(self.pos, "prange() can only be used as part of a for loop") error(self.pos, "prange() can only be used as part of a for loop")
return return
...@@ -6573,6 +6578,9 @@ class ParallelRangeNode(ParallelStatNode): ...@@ -6573,6 +6578,9 @@ class ParallelRangeNode(ParallelStatNode):
super(ParallelRangeNode, self).analyse_expressions(env) super(ParallelRangeNode, self).analyse_expressions(env)
if self.nogil:
env.nogil = was_nogil
def nogil_check(self, env): def nogil_check(self, env):
names = 'start', 'stop', 'step', 'target' names = 'start', 'stop', 'step', 'target'
nodes = self.start, self.stop, self.step, self.target nodes = self.start, self.stop, self.step, self.target
......
# mode: error
from cython.parallel import *
def psum(int n):
cdef double sum
cdef int i
cdef double x,step,t1,t2
sum=0
step=1.0/n
for i in prange(n,nogil=True):
x = (i)*step
sum+=4.0/(1.0+x*x)
return sum*step
_ERRORS = u"""
e_cython_parallel_nogil_env.pyx:12:15: Pythonic division not allowed without gil, consider using cython.cdivision(True)
"""
...@@ -705,3 +705,18 @@ def outer_parallel_section(): ...@@ -705,3 +705,18 @@ def outer_parallel_section():
for i in prange(10, nogil=True): for i in prange(10, nogil=True):
sum += inner_parallel_section() sum += inner_parallel_section()
return sum return sum
cdef int nogil_cdef_except_clause() nogil except 0:
return 1
cdef void nogil_cdef_except_star() nogil except *:
pass
def test_nogil_cdef_except_clause():
"""
>>> test_nogil_cdef_except_clause()
"""
cdef int i
for i in prange(10, nogil=True):
nogil_cdef_except_clause()
nogil_cdef_except_star()
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