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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
f3e94744
Commit
f3e94744
authored
Oct 06, 2010
by
Lisandro Dalcin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix Python exception checking within nogil blocks
parent
17111fa7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
346 additions
and
5 deletions
+346
-5
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+30
-2
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+6
-3
tests/run/exceptions_nogil.pyx
tests/run/exceptions_nogil.pyx
+310
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
f3e94744
...
@@ -2692,6 +2692,7 @@ class SimpleCallNode(CallNode):
...
@@ -2692,6 +2692,7 @@ class SimpleCallNode(CallNode):
# coerced_self ExprNode or None used internally
# coerced_self ExprNode or None used internally
# wrapper_call bool used internally
# wrapper_call bool used internally
# has_optional_args bool used internally
# has_optional_args bool used internally
# nogil bool used internally
subexprs
=
[
'self'
,
'coerced_self'
,
'function'
,
'args'
,
'arg_tuple'
]
subexprs
=
[
'self'
,
'coerced_self'
,
'function'
,
'args'
,
'arg_tuple'
]
...
@@ -2865,8 +2866,13 @@ class SimpleCallNode(CallNode):
...
@@ -2865,8 +2866,13 @@ class SimpleCallNode(CallNode):
elif
func_type
.
exception_value
is
not
None
\
elif
func_type
.
exception_value
is
not
None
\
or
func_type
.
exception_check
:
or
func_type
.
exception_check
:
self
.
is_temp
=
1
self
.
is_temp
=
1
# C
++ exception handler
# C
alled in 'nogil' context?
self
.
nogil
=
env
.
nogil
self
.
nogil
=
env
.
nogil
if
(
self
.
nogil
and
func_type
.
exception_check
and
func_type
.
exception_check
!=
'+'
):
env
.
use_utility_code
(
pyerr_occurred_withgil_utility_code
)
# C++ exception handler
if
func_type
.
exception_check
==
'+'
:
if
func_type
.
exception_check
==
'+'
:
if
func_type
.
exception_value
is
None
:
if
func_type
.
exception_value
is
None
:
env
.
use_utility_code
(
cpp_exception_utility_code
)
env
.
use_utility_code
(
cpp_exception_utility_code
)
...
@@ -2940,7 +2946,10 @@ class SimpleCallNode(CallNode):
...
@@ -2940,7 +2946,10 @@ class SimpleCallNode(CallNode):
if
exc_val
is
not
None
:
if
exc_val
is
not
None
:
exc_checks
.
append
(
"%s == %s"
%
(
self
.
result
(),
exc_val
))
exc_checks
.
append
(
"%s == %s"
%
(
self
.
result
(),
exc_val
))
if
exc_check
:
if
exc_check
:
exc_checks
.
append
(
"PyErr_Occurred()"
)
if
self
.
nogil
:
exc_checks
.
append
(
"__Pyx_ErrOccurredWithGIL()"
)
else
:
exc_checks
.
append
(
"PyErr_Occurred()"
)
if
self
.
is_temp
or
exc_checks
:
if
self
.
is_temp
or
exc_checks
:
rhs
=
self
.
c_call_code
()
rhs
=
self
.
c_call_code
()
if
self
.
result
():
if
self
.
result
():
...
@@ -7144,6 +7153,25 @@ static void __Pyx_CppExn2PyErr() {
...
@@ -7144,6 +7153,25 @@ static void __Pyx_CppExn2PyErr() {
impl
=
""
impl
=
""
)
)
pyerr_occurred_withgil_utility_code
=
UtilityCode
(
proto
=
"""
static CYTHON_INLINE int __Pyx_ErrOccurredWithGIL(void); /* proto */
"""
,
impl
=
"""
static CYTHON_INLINE int __Pyx_ErrOccurredWithGIL(void) {
int err;
#ifdef WITH_THREAD
PyGILState_STATE _save = PyGILState_Ensure();
#endif
err = !!PyErr_Occurred();
#ifdef WITH_THREAD
PyGILState_Release(_save);
#endif
return err;
}
"""
)
#------------------------------------------------------------------------------------
#------------------------------------------------------------------------------------
raise_noneattr_error_utility_code
=
UtilityCode
(
raise_noneattr_error_utility_code
=
UtilityCode
(
...
...
Cython/Compiler/Nodes.py
View file @
f3e94744
...
@@ -5084,12 +5084,15 @@ class GILStatNode(TryFinallyStatNode):
...
@@ -5084,12 +5084,15 @@ class GILStatNode(TryFinallyStatNode):
def
generate_execution_code
(
self
,
code
):
def
generate_execution_code
(
self
,
code
):
code
.
mark_pos
(
self
.
pos
)
code
.
mark_pos
(
self
.
pos
)
code
.
putln
(
"{"
)
if
self
.
state
==
'gil'
:
if
self
.
state
==
'gil'
:
code
.
putln
(
"#ifdef WITH_THREAD"
)
code
.
putln
(
"#ifdef WITH_THREAD"
)
code
.
putln
(
"
{
PyGILState_STATE _save = PyGILState_Ensure();"
)
code
.
putln
(
"PyGILState_STATE _save = PyGILState_Ensure();"
)
code
.
putln
(
"#endif"
)
code
.
putln
(
"#endif"
)
else
:
else
:
code
.
putln
(
"{ PyThreadState *_save;"
)
code
.
putln
(
"#ifdef WITH_THREAD"
)
code
.
putln
(
"PyThreadState *_save;"
)
code
.
putln
(
"#endif"
)
code
.
putln
(
"Py_UNBLOCK_THREADS"
)
code
.
putln
(
"Py_UNBLOCK_THREADS"
)
TryFinallyStatNode
.
generate_execution_code
(
self
,
code
)
TryFinallyStatNode
.
generate_execution_code
(
self
,
code
)
code
.
putln
(
"}"
)
code
.
putln
(
"}"
)
...
@@ -5108,7 +5111,7 @@ class GILExitNode(StatNode):
...
@@ -5108,7 +5111,7 @@ class GILExitNode(StatNode):
def
generate_execution_code
(
self
,
code
):
def
generate_execution_code
(
self
,
code
):
if
self
.
state
==
'gil'
:
if
self
.
state
==
'gil'
:
code
.
putln
(
"#ifdef WITH_THREAD"
)
code
.
putln
(
"#ifdef WITH_THREAD"
)
code
.
putln
(
"PyGILState_Release(_save);
}
"
)
code
.
putln
(
"PyGILState_Release(_save);"
)
code
.
putln
(
"#endif"
)
code
.
putln
(
"#endif"
)
else
:
else
:
code
.
putln
(
"Py_BLOCK_THREADS"
)
code
.
putln
(
"Py_BLOCK_THREADS"
)
...
...
tests/run/exceptions_nogil.pyx
0 → 100644
View file @
f3e94744
cdef
void
foo
(
int
i
)
except
*
with
gil
:
if
i
!=
0
:
raise
ValueError
cdef
int
bar
(
int
i
)
except
?
-
1
with
gil
:
if
i
!=
0
:
raise
ValueError
return
0
cdef
int
spam
(
int
i
)
except
?
-
1
with
gil
:
if
i
!=
0
:
raise
TypeError
return
-
1
def
test_foo
():
"""
>>> test_foo()
"""
#
foo
(
0
)
foo
(
0
)
with
nogil
:
foo
(
0
)
foo
(
0
)
#
try
:
with
nogil
:
foo
(
0
)
finally
:
pass
#
try
:
with
nogil
:
foo
(
0
)
with
nogil
:
foo
(
0
)
finally
:
pass
#
try
:
with
nogil
:
foo
(
0
)
with
nogil
:
foo
(
1
)
except
:
with
nogil
:
foo
(
0
)
finally
:
with
nogil
:
foo
(
0
)
pass
#
try
:
with
nogil
:
foo
(
0
)
foo
(
0
)
finally
:
pass
#
try
:
with
nogil
:
foo
(
0
)
foo
(
1
)
except
:
with
nogil
:
foo
(
0
)
finally
:
with
nogil
:
foo
(
0
)
pass
#
try
:
with
nogil
:
foo
(
0
)
try
:
with
nogil
:
foo
(
1
)
except
:
with
nogil
:
foo
(
1
)
finally
:
with
nogil
:
foo
(
0
)
pass
except
:
with
nogil
:
foo
(
0
)
finally
:
with
nogil
:
foo
(
0
)
pass
#
try
:
with
nogil
:
foo
(
0
)
try
:
with
nogil
:
foo
(
1
)
except
:
with
nogil
:
foo
(
1
)
finally
:
with
nogil
:
foo
(
1
)
pass
except
:
with
nogil
:
foo
(
0
)
finally
:
with
nogil
:
foo
(
0
)
pass
#
def
test_bar
():
"""
>>> test_bar()
"""
#
bar
(
0
)
bar
(
0
)
with
nogil
:
bar
(
0
)
bar
(
0
)
#
try
:
with
nogil
:
bar
(
0
)
finally
:
pass
#
try
:
with
nogil
:
bar
(
0
)
with
nogil
:
bar
(
0
)
finally
:
pass
#
try
:
with
nogil
:
bar
(
0
)
with
nogil
:
bar
(
1
)
except
ValueError
:
with
nogil
:
bar
(
0
)
finally
:
with
nogil
:
bar
(
0
)
pass
#
try
:
with
nogil
:
bar
(
0
)
bar
(
0
)
finally
:
pass
#
try
:
with
nogil
:
bar
(
0
)
bar
(
1
)
except
ValueError
:
with
nogil
:
bar
(
0
)
finally
:
with
nogil
:
bar
(
0
)
pass
#
try
:
with
nogil
:
bar
(
0
)
try
:
with
nogil
:
bar
(
1
)
except
ValueError
:
with
nogil
:
bar
(
1
)
finally
:
with
nogil
:
bar
(
0
)
pass
except
ValueError
:
with
nogil
:
bar
(
0
)
finally
:
with
nogil
:
bar
(
0
)
pass
#
try
:
with
nogil
:
bar
(
0
)
try
:
with
nogil
:
bar
(
1
)
except
ValueError
:
with
nogil
:
bar
(
1
)
finally
:
with
nogil
:
bar
(
1
)
pass
except
ValueError
:
with
nogil
:
bar
(
0
)
finally
:
with
nogil
:
bar
(
0
)
pass
#
def
test_spam
():
"""
>>> test_spam()
"""
#
spam
(
0
)
spam
(
0
)
with
nogil
:
spam
(
0
)
spam
(
0
)
#
try
:
with
nogil
:
spam
(
0
)
finally
:
pass
#
try
:
with
nogil
:
spam
(
0
)
with
nogil
:
spam
(
0
)
finally
:
pass
#
try
:
with
nogil
:
spam
(
0
)
with
nogil
:
spam
(
1
)
except
TypeError
:
with
nogil
:
spam
(
0
)
finally
:
with
nogil
:
spam
(
0
)
pass
#
try
:
with
nogil
:
spam
(
0
)
spam
(
0
)
finally
:
pass
#
try
:
with
nogil
:
spam
(
0
)
spam
(
1
)
except
TypeError
:
with
nogil
:
spam
(
0
)
finally
:
with
nogil
:
spam
(
0
)
pass
#
try
:
with
nogil
:
spam
(
0
)
try
:
with
nogil
:
spam
(
1
)
except
TypeError
:
with
nogil
:
spam
(
1
)
finally
:
with
nogil
:
spam
(
0
)
pass
except
TypeError
:
with
nogil
:
spam
(
0
)
finally
:
with
nogil
:
spam
(
0
)
pass
#
try
:
with
nogil
:
spam
(
0
)
try
:
with
nogil
:
spam
(
1
)
except
TypeError
:
with
nogil
:
spam
(
1
)
finally
:
with
nogil
:
spam
(
1
)
pass
except
TypeError
:
with
nogil
:
spam
(
0
)
finally
:
with
nogil
:
spam
(
0
)
pass
#
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