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