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

Make auto-unlock work correctly with not-assigned expressions

parent 98920e36
...@@ -747,8 +747,6 @@ class ExprNode(Node): ...@@ -747,8 +747,6 @@ class ExprNode(Node):
self.tracked_state = env.lookup_tracked(self.entry) self.tracked_state = env.lookup_tracked(self.entry)
if self.tracked_state is None: if self.tracked_state is None:
self.tracked_state = env.declare_tracked(self.entry) self.tracked_state = env.declare_tracked(self.entry)
if self.is_autolock():
env.declare_autolocked(self)
self.was_locked = self.tracked_state.was_locked self.was_locked = self.tracked_state.was_locked
self.tracked_state.was_locked = True self.tracked_state.was_locked = True
...@@ -785,13 +783,15 @@ class ExprNode(Node): ...@@ -785,13 +783,15 @@ class ExprNode(Node):
elif self.is_autolock(): elif self.is_autolock():
self.set_autorlock(env) self.set_autorlock(env)
def ensure_lhs_locked(self, env, is_dereferenced = False): def ensure_lhs_locked(self, env, is_dereferenced = False, is_top_lhs = False):
if not is_dereferenced: if not is_dereferenced:
self.ensure_subexpr_lhs_locked(env) self.ensure_subexpr_lhs_locked(env)
else: else:
self.ensure_subexpr_rhs_locked(env) self.ensure_subexpr_rhs_locked(env)
if not self.tracked_state: if not self.tracked_state:
self.get_tracked_state(env) self.get_tracked_state(env)
if self.is_autolock() and is_top_lhs:
env.declare_autolocked(self)
if is_dereferenced and self.tracked_state: if is_dereferenced and self.tracked_state:
if not self.is_lhs_locked(env): if not self.is_lhs_locked(env):
if self.is_checklock(): if self.is_checklock():
...@@ -7616,6 +7616,9 @@ class AttributeNode(ExprNode): ...@@ -7616,6 +7616,9 @@ class AttributeNode(ExprNode):
# mirror condition for putting the memview incref here: # mirror condition for putting the memview incref here:
code.put_xdecref_clear(self.result(), self.type, have_gil=True) code.put_xdecref_clear(self.result(), self.type, have_gil=True)
else: else:
if self.is_temp and self.type.is_cyp_class and self.is_autolock()\
and self.tracked_state and (tracked_state.needs_rlock or tracked_state.needs_wlock):
code.putln("Cy_UNLOCK(%s);" % self.result())
ExprNode.generate_disposal_code(self, code) ExprNode.generate_disposal_code(self, code)
def generate_assignment_code(self, rhs, code, overloaded_assignment=False, def generate_assignment_code(self, rhs, code, overloaded_assignment=False,
......
...@@ -5814,7 +5814,7 @@ class SingleAssignmentNode(AssignmentNode): ...@@ -5814,7 +5814,7 @@ class SingleAssignmentNode(AssignmentNode):
self.lhs = self.lhs.analyse_target_types(env) self.lhs = self.lhs.analyse_target_types(env)
self.lhs.gil_assignment_check(env) self.lhs.gil_assignment_check(env)
self.rhs.ensure_rhs_locked(env) self.rhs.ensure_rhs_locked(env)
self.lhs.ensure_lhs_locked(env) self.lhs.ensure_lhs_locked(env, is_top_lhs = True)
unrolled_assignment = self.unroll_lhs(env) unrolled_assignment = self.unroll_lhs(env)
if unrolled_assignment: if unrolled_assignment:
return unrolled_assignment return unrolled_assignment
...@@ -6038,7 +6038,7 @@ class CascadedAssignmentNode(AssignmentNode): ...@@ -6038,7 +6038,7 @@ class CascadedAssignmentNode(AssignmentNode):
for i, lhs in enumerate(self.lhs_list): for i, lhs in enumerate(self.lhs_list):
lhs = self.lhs_list[i] = lhs.analyse_target_types(env) lhs = self.lhs_list[i] = lhs.analyse_target_types(env)
lhs.gil_assignment_check(env) lhs.gil_assignment_check(env)
lhs.ensure_lhs_locked(env) lhs.ensure_lhs_locked(env, is_top_lhs = True)
lhs_types.add(lhs.type) lhs_types.add(lhs.type)
rhs = self.rhs.analyse_types(env) rhs = self.rhs.analyse_types(env)
......
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