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
Xavier Thompson
cython
Commits
c6fd6ed8
Commit
c6fd6ed8
authored
Sep 01, 2020
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Disallow explicitly locking a global cypclass variable and add associated unit tests
parent
13b1a497
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
23 deletions
+11
-23
Cython/Compiler/CypclassTransforms.py
Cython/Compiler/CypclassTransforms.py
+3
-0
tests/errors/cypclass_lock_error.pyx
tests/errors/cypclass_lock_error.pyx
+8
-0
tests/run/cypclass_lock.pyx
tests/run/cypclass_lock.pyx
+0
-23
No files found.
Cython/Compiler/CypclassTransforms.py
View file @
c6fd6ed8
...
...
@@ -595,6 +595,9 @@ class CypclassLockTransform(Visitor.EnvTransform):
if
not
node
.
obj
.
type
.
is_cyp_class
:
error
(
node
.
obj
.
pos
,
"Locking non-cypclass reference"
)
return
node
if
not
obj_ref_id
.
is_local
or
obj_ref_id
.
is_arg
:
error
(
node
.
obj
.
pos
,
"Can only lock local variables or arguments"
)
return
node
with
self
.
stacklock
(
obj_ref_id
,
node
.
state
):
self
.
visit
(
node
.
body
)
return
node
...
...
tests/errors/cypclass_lock_error.pyx
View file @
c6fd6ed8
...
...
@@ -25,6 +25,13 @@ def incorrect_locks():
obj
.
a
take_read_locked
(
obj
)
cdef
A
global_cyobject
cdef
void
global_lock_taking
():
with
wlocked
global_cyobject
:
global_cyobject
.
setter
(
global_cyobject
.
getter
()
+
1
)
_ERRORS
=
u"""
20:4: Reference 'obj' is not correctly locked in this expression (write lock required)
21:4: Reference 'obj' is not correctly locked in this expression (read lock required)
...
...
@@ -32,4 +39,5 @@ _ERRORS = u"""
24:26: Reference 'obj' is not correctly locked in this expression (write lock required)
25:4: Reference 'obj' is not correctly locked in this expression (read lock required)
26:21: Reference 'obj' is not correctly locked in this expression (read lock required)
32:17: Can only lock local variables or arguments
"""
tests/run/cypclass_lock.pyx
View file @
c6fd6ed8
...
...
@@ -35,29 +35,6 @@ def test_argument_recursivity(n):
argument_recursivity
(
obj
,
n
)
print
obj
.
a
cdef
A
global_cyobject
cdef
init_global_cyobject
():
global
global_cyobject
global_cyobject
=
A
()
cdef
void
recursive_lock_taking
(
int
arg
):
global
global_cyobject
if
arg
>
0
:
with
wlocked
global_cyobject
:
global_cyobject
.
setter
(
global_cyobject
.
getter
()
+
1
)
recursive_lock_taking
(
arg
-
1
)
def
test_recursive_side_effect_locking
(
n
):
"""
>>> test_recursive_side_effect_locking(42)
42
"""
init_global_cyobject
()
recursive_lock_taking
(
42
)
with
rlocked
global_cyobject
:
print
global_cyobject
.
getter
()
cdef
cypclass
Container
:
A
object
__init__
(
self
):
...
...
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