Commit dda134c7 authored by gsamain's avatar gsamain Committed by Xavier Thompson

Make read-write info cascade through entries, not nodes (potentially less...

Make read-write info cascade through entries, not nodes (potentially less optimized, but safer and correctly handles branching)
parent fb7aeee3
......@@ -727,7 +727,7 @@ class ExprNode(Node):
if self.entry.type.lock_mode == "autolock":
print "Request read lock autolock here", self.entry.name
self.entry.is_rlocked = True
self.entry.locking_node.needs_rlock = True
self.entry.needs_rlock = True
elif self.entry.type.lock_mode == "checklock":
return False
return True
......@@ -738,7 +738,7 @@ class ExprNode(Node):
if self.entry.type.lock_mode == "autolock":
print "Request write lock autolock here", self.entry.name
self.entry.is_wlocked = True
self.entry.locking_node.needs_wlock = True
self.entry.needs_wlock = True
elif self.entry.type.lock_mode == "checklock":
return False
return True
......@@ -898,8 +898,7 @@ class ExprNode(Node):
self.generate_subexpr_disposal_code(code)
def generate_assignment_code(self, rhs, code, overloaded_assignment=False,
exception_check=None, exception_value=None, needs_unlock=False,
needs_rlock=False, needs_wlock=False):
exception_check=None, exception_value=None):
# Stub method for nodes which are not legal as
# the LHS of an assignment. An error will have
# been reported earlier.
......@@ -2376,8 +2375,7 @@ class NameNode(AtomicExprNode):
code.put_error_if_unbound(self.pos, entry, self.in_nogil_context)
def generate_assignment_code(self, rhs, code, overloaded_assignment=False,
exception_check=None, exception_value=None, needs_unlock=False,
needs_rlock=False, needs_wlock=False):
exception_check=None, exception_value=None):
#print "NameNode.generate_assignment_code:", self.name ###
entry = self.entry
if entry is None:
......@@ -2387,6 +2385,9 @@ class NameNode(AtomicExprNode):
and not self.lhs_of_first_assignment and not rhs.in_module_scope):
error(self.pos, "Literal list must be assigned to pointer at time of declaration")
if entry.needs_wlock or entry.needs_rlock:
code.putln("Cy_UNLOCK(%s);" % self.result())
# is_pyglobal seems to be True for module level-globals only.
# We use this to access class->tp_dict if necessary.
if entry.is_pyglobal:
......@@ -2475,8 +2476,6 @@ class NameNode(AtomicExprNode):
code.put_cyxdecref(self.result())
if not self.type.is_memoryviewslice:
if not assigned:
if needs_unlock:
code.putln("Cy_UNLOCK(%s);" % self.result())
if overloaded_assignment:
result = rhs.move_result_rhs()
if exception_check == '+':
......@@ -2494,9 +2493,9 @@ class NameNode(AtomicExprNode):
code.putln('new (&%s) decltype(%s){%s};' % (self.result(), self.result(), result))
elif result != self.result():
code.putln('%s = %s;' % (self.result(), result))
if needs_wlock:
if entry.needs_wlock:
code.putln("Cy_WLOCK(%s);" % self.result())
elif needs_rlock:
elif entry.needs_rlock:
code.putln("Cy_RLOCK(%s);" % self.result())
if debug_disposal_code:
print("NameNode.generate_assignment_code:")
......@@ -7462,8 +7461,7 @@ class AttributeNode(ExprNode):
ExprNode.generate_disposal_code(self, code)
def generate_assignment_code(self, rhs, code, overloaded_assignment=False,
exception_check=None, exception_value=None, needs_unlock=False,
needs_rlock=False, needs_wlock=False):
exception_check=None, exception_value=None):
self.obj.generate_evaluation_code(code)
if self.is_py_attr:
code.globalstate.use_utility_code(
......@@ -7482,6 +7480,8 @@ class AttributeNode(ExprNode):
rhs.result_as(self.ctype())))
else:
select_code = self.result()
if self.entry.needs_rlock or self.entry.needs_wlock:
code.putln("Cy_UNLOCK(%s);" % select_code)
if self.type.is_pyobject and self.use_managed_ref:
rhs.make_owned_reference(code)
rhs.generate_giveref(code)
......@@ -7497,17 +7497,15 @@ class AttributeNode(ExprNode):
code.put_cygotref(select_code)
code.put_cyxdecref(select_code)
if needs_unlock:
code.putln("Cy_UNLOCK(%s);" % select_code)
if not self.type.is_memoryviewslice:
code.putln(
"%s = %s;" % (
select_code,
rhs.move_result_rhs_as(self.ctype())))
#rhs.result()))
if needs_wlock:
if self.entry.needs_wlock:
code.putln("Cy_WLOCK(%s);" % select_code)
elif needs_rlock:
elif self.entry.needs_rlock:
code.putln("Cy_RLOCK(%s);" % select_code)
rhs.generate_post_assignment_code(code)
......
......@@ -5766,14 +5766,11 @@ class SingleAssignmentNode(AssignmentNode):
self.lhs.gil_assignment_check(env)
if hasattr(self.lhs, 'entry'):
entry = self.lhs.entry
if entry.type.is_cyp_class and entry.type.lock_mode == "autolock":
if entry.locking_node is None:
env.declare_autolocked(self.lhs)
else:
self.needs_unlock = True
self.lhs.entry.locking_node = self
self.lhs.entry.is_wlocked = False
self.lhs.entry.is_rlocked = False
if entry.type.is_cyp_class and entry.type.lock_mode == "autolock"\
and not (entry.needs_rlock or entry.needs_wlock):
env.declare_autolocked(self.lhs)
#self.lhs.entry.is_wlocked = False
#self.lhs.entry.is_rlocked = False
if self.rhs.is_attribute:
self.rhs.obj.check_rhs_locked(env)
if self.lhs.is_attribute:
......@@ -5958,17 +5955,9 @@ class SingleAssignmentNode(AssignmentNode):
code,
overloaded_assignment=self.is_overloaded_assignment,
exception_check=self.exception_check,
exception_value=self.exception_value,
needs_unlock=self.needs_unlock,
needs_rlock=self.needs_rlock,
needs_wlock=self.needs_wlock)
exception_value=self.exception_value)
else:
self.lhs.generate_assignment_code(
self.rhs,
code,
needs_unlock=self.needs_unlock,
needs_rlock=self.needs_rlock,
needs_wlock=self.needs_wlock)
self.lhs.generate_assignment_code(self.rhs, code)
def generate_function_definitions(self, env, code):
self.rhs.generate_function_definitions(env, code)
......
......@@ -160,7 +160,8 @@ class Entry(object):
# is_cgetter boolean Is a c-level getter function
# is_wlocked boolean Is locked with a write lock (used for cypclass)
# is_rlocked boolean Is locked with a read lock (used for cypclass)
# locking_node Node The assignment node doing the locking
# needs_rlock boolean The entry needs a read lock (used in autolock mode)
# needs_wlock boolean The entry needs a write lock (used in autolock mode)
# TODO: utility_code and utility_code_definition serves the same purpose...
......@@ -234,7 +235,8 @@ class Entry(object):
is_cgetter = False
is_wlocked = False
is_rlocked = False
locking_node = None
needs_rlock = False
needs_wlock = False
def __init__(self, name, cname, type, pos = None, init = None):
self.name = name
......
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