Commit 510e786b authored by Xavier Thompson's avatar Xavier Thompson

Ensure automatic cypclass write lock acquisition is not nested

parent 565e6b4f
......@@ -446,11 +446,13 @@ class CypclassLockTransform(Visitor.EnvTransform):
return obj
except:
self.autolocks += 1
self.autowlocks += exclusive
return ExprNodes.CoerceToLockedNode(obj, self.current_env(), rlock_only = not exclusive)
def __call__(self, root):
self.locked = {}
self.autolocks = 0
self.autowlocks = 0
return super(CypclassLockTransform, self).__call__(root)
def visit_Node(self, node):
......@@ -503,24 +505,16 @@ class CypclassLockTransform(Visitor.EnvTransform):
autolocks = self.autolocks
node = self.visit(node)
if self.autolocks > autolocks:
self.autolocks = 0
return node.coerce_to_temp(self.current_env())
return node
def visit_IndexNode(self, node):
node.index = self.visit_value(node.index)
node.base = self.visit(node.base)
return node
def visit_DelStatNode(self, node):
for arg in node.args:
arg_entry = self.id(arg)
if arg_entry in self.locked:
# Disallow unbinding a locked name
error(arg.pos, "Deleting a locked cypclass reference")
return node
self.visitchildren(node)
return node
def visit_assignment(self, node):
autowlocks = self.autowlocks
self.visitchildren(node, exclude=['rhs'])
if self.autowlocks > autowlocks:
node.rhs = self.visit_value(node.rhs)
else:
node.rhs = self.visit(node.rhs)
def visit_SingleAssignmentNode(self, node):
lhs = node.lhs
......@@ -528,8 +522,7 @@ class CypclassLockTransform(Visitor.EnvTransform):
# Disallow re-binding a locked name
error(lhs.pos, "Assigning to a locked cypclass reference")
return node
node.rhs = self.visit_value(node.rhs)
self.visitchildren(node, exclude=['rhs'])
self.visit_assignment(node)
return node
def visit_CascadedAssignmentNode(self, node):
......@@ -538,8 +531,17 @@ class CypclassLockTransform(Visitor.EnvTransform):
# Disallow re-binding a locked name
error(lhs.pos, "Assigning to a locked cypclass reference")
return node
node.rhs = self.visit_value(node.rhs)
self.visitchildren(node, exclude=['rhs'])
self.visit_assignment(node)
return node
def visit_DelStatNode(self, node):
for arg in node.args:
arg_entry = self.id(arg)
if arg_entry in self.locked:
# Disallow unbinding a locked name
error(arg.pos, "Deleting a locked cypclass reference")
return node
self.visitchildren(node)
return node
def visit_WithTargetAssignmentStatNode(self, node):
......
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