Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
0da93240
Commit
0da93240
authored
May 24, 2011
by
Mark Florisson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Lock around error info decrefs in nogil try/finally
parent
86be47c1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
4 deletions
+58
-4
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+12
-3
tests/errors/nogil.pyx
tests/errors/nogil.pyx
+1
-1
tests/run/with_gil.pyx
tests/run/with_gil.pyx
+45
-0
No files found.
Cython/Compiler/Nodes.py
View file @
0da93240
...
...
@@ -5488,10 +5488,16 @@ class TryFinallyStatNode(StatNode):
over_label
=
code
.
new_label
()
code
.
put_goto
(
over_label
)
code
.
put_label
(
finally_error_label
)
code
.
putln
(
"if (__pyx_why == %d) {"
%
(
error_label_case
+
1
))
if
self
.
is_try_finally_in_nogil
:
code
.
put_ensure_gil
(
declare_gilstate
=
False
)
for
var
in
Naming
.
exc_vars
:
code
.
putln
(
"Py_XDECREF(%s);"
%
var
)
if
self
.
is_try_finally_in_nogil
:
code
.
put_release_ensured_gil
()
code
.
putln
(
"}"
)
code
.
put_goto
(
old_error_label
)
code
.
put_label
(
over_label
)
...
...
@@ -5543,7 +5549,8 @@ class TryFinallyStatNode(StatNode):
def
put_error_uncatcher
(
self
,
code
,
i
,
error_label
):
code
.
globalstate
.
use_utility_code
(
restore_exception_utility_code
)
code
.
putln
(
"case %s: {"
%
i
)
code
.
putln
(
"case %s: {"
%
i
)
if
self
.
is_try_finally_in_nogil
:
code
.
put_ensure_gil
(
declare_gilstate
=
False
)
...
...
@@ -5555,10 +5562,12 @@ class TryFinallyStatNode(StatNode):
code
.
put_release_ensured_gil
()
for
var
in
Naming
.
exc_vars
:
code
.
putln
(
"%s = 0;"
%
var
)
code
.
putln
(
"%s = 0;"
%
var
)
code
.
put_goto
(
error_label
)
code
.
putln
(
"}"
)
code
.
putln
(
"}"
)
def
annotate
(
self
,
code
):
self
.
body
.
annotate
(
code
)
...
...
tests/errors/nogil.pyx
View file @
0da93240
...
...
@@ -157,6 +157,6 @@ _ERRORS = u"""
59:17: Truth-testing Python object not allowed without gil
61:8: For-loop using object bounds or target not allowed without gil
63:8: Try-except statement not allowed without gil
67:8:
Try-finally statement not allowed without gil
67:8:
Cannot use try/finally in nogil sections unless it contains a 'with gil' statement.
84:8: For-loop using object bounds or target not allowed without gil
"""
tests/run/with_gil.pyx
View file @
0da93240
...
...
@@ -387,3 +387,48 @@ def test_nogil_try_finally_propagate_exception():
puts
(
"Execute finally clause"
)
except
Exception
,
e
:
print
e
def
test_nogil_try_finally_return_in_with_gil
(
x
):
"""
>>> test_nogil_try_finally_return_in_with_gil(10)
(None, None, None)
10
"""
# For some reason, this exception is set, clear it first
# (<type 'exceptions.ImportError'>,
# ImportError('cannot import name _TextTestResult',),
# <traceback object at 0x10073c4d0>)
sys
.
exc_clear
()
with
nogil
:
try
:
with
gil
:
raise
Exception
(
"Swallow me!"
)
finally
:
with
gil
:
print
sys
.
exc_info
()
return
x
print
"I am not executed"
,
sys
.
exc_info
()
cdef
void
nogil_try_finally_return
()
nogil
:
try
:
with
gil
:
raise
Exception
(
"I am swallowed in nogil code... right?"
)
finally
:
with
gil
:
print
sys
.
exc_info
()
return
with
gil
:
print
"I am not executed"
,
sys
.
exc_info
()
def
test_nogil_try_finally_return
():
"""
>>> test_nogil_try_finally_return()
(None, None, None)
"""
sys
.
exc_clear
()
with
nogil
:
nogil_try_finally_return
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment