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
Kirill Smelkov
cython
Commits
412b232e
Commit
412b232e
authored
Feb 23, 2019
by
Noam Hershtig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create errors tests for conditional GILStatNode
parent
73133f68
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
89 additions
and
1 deletion
+89
-1
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+7
-0
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+1
-1
tests/errors/nogil_conditional.pyx
tests/errors/nogil_conditional.pyx
+81
-0
No files found.
Cython/Compiler/Nodes.py
View file @
412b232e
...
...
@@ -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
)
...
...
Cython/Compiler/Optimize.py
View file @
412b232e
...
...
@@ -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 type
d
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
...
...
tests/errors/nogil_conditional.pyx
0 → 100644
View file @
412b232e
# 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
"""
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