Commit 629acd77 authored by Xavier Thompson's avatar Xavier Thompson

Disallow explicitly locking a global cypclass variable and add associated unit tests

parent ce93bf52
......@@ -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
......
......@@ -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
"""
......@@ -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):
......
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