Commit 9a50e59c authored by gsamain's avatar gsamain

Make auto-unlock work correctly with not-assigned expressions

parent a6f398f2
...@@ -715,8 +715,6 @@ class ExprNode(Node): ...@@ -715,8 +715,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
...@@ -753,13 +751,15 @@ class ExprNode(Node): ...@@ -753,13 +751,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():
...@@ -7461,6 +7461,9 @@ class AttributeNode(ExprNode): ...@@ -7461,6 +7461,9 @@ class AttributeNode(ExprNode):
code.putln("%s.memview = NULL;" % self.result()) code.putln("%s.memview = NULL;" % self.result())
code.putln("%s.data = NULL;" % self.result()) code.putln("%s.data = NULL;" % self.result())
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,
......
...@@ -5568,7 +5568,7 @@ class SingleAssignmentNode(AssignmentNode): ...@@ -5568,7 +5568,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
...@@ -5792,7 +5792,7 @@ class CascadedAssignmentNode(AssignmentNode): ...@@ -5792,7 +5792,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