Commit 173b578c authored by Vitja Makarov's avatar Vitja Makarov

Fix control-flow and closure entries

parent 3a89c5a0
...@@ -1556,7 +1556,7 @@ class NameNode(AtomicExprNode): ...@@ -1556,7 +1556,7 @@ class NameNode(AtomicExprNode):
code.error_goto_if_null(self.result(), self.pos))) code.error_goto_if_null(self.result(), self.pos)))
code.put_gotref(self.py_result()) code.put_gotref(self.py_result())
elif entry.is_local: elif entry.is_local or entry.in_closure or entry.from_closure:
if entry.type.is_pyobject: if entry.type.is_pyobject:
if (self.cf_maybe_null or self.cf_is_null) and not self.allow_null: if (self.cf_maybe_null or self.cf_is_null) and not self.allow_null:
code.putln('if (unlikely(!%s)) { PyErr_SetString(PyExc_UnboundLocalError, "%s"); %s }' % code.putln('if (unlikely(!%s)) { PyErr_SetString(PyExc_UnboundLocalError, "%s"); %s }' %
...@@ -1635,14 +1635,14 @@ class NameNode(AtomicExprNode): ...@@ -1635,14 +1635,14 @@ class NameNode(AtomicExprNode):
code.put_xgotref(self.py_result()) code.put_xgotref(self.py_result())
else: else:
code.put_gotref(self.py_result()) code.put_gotref(self.py_result())
if entry.is_local: if entry.is_cglobal:
code.put_decref(self.result(), self.ctype())
else:
if not self.cf_is_null: if not self.cf_is_null:
if self.cf_maybe_null: if self.cf_maybe_null:
code.put_xdecref(self.result(), self.ctype()) code.put_xdecref(self.result(), self.ctype())
else: else:
code.put_decref(self.result(), self.ctype()) code.put_decref(self.result(), self.ctype())
else:
code.put_decref(self.result(), self.ctype())
if is_external_ref: if is_external_ref:
code.put_giveref(rhs.py_result()) code.put_giveref(rhs.py_result())
......
...@@ -473,9 +473,11 @@ def check_definitions(flow, compiler_directives): ...@@ -473,9 +473,11 @@ def check_definitions(flow, compiler_directives):
for node, entry in references.iteritems(): for node, entry in references.iteritems():
if Uninitialized in node.cf_state: if Uninitialized in node.cf_state:
node.cf_maybe_null = True node.cf_maybe_null = True
if entry.from_closure or node.allow_null: if not entry.from_closure and len(node.cf_state) == 1:
node.cf_is_null = True
if node.allow_null or entry.from_closure:
pass # Can be uninitialized here pass # Can be uninitialized here
elif len(node.cf_state) == 1: elif node.cf_is_null:
if entry.type.is_pyobject or entry.type.is_unspecified: if entry.type.is_pyobject or entry.type.is_unspecified:
messages.error( messages.error(
node.pos, node.pos,
...@@ -486,9 +488,7 @@ def check_definitions(flow, compiler_directives): ...@@ -486,9 +488,7 @@ def check_definitions(flow, compiler_directives):
node.pos, node.pos,
"local variable '%s' referenced before assignment" "local variable '%s' referenced before assignment"
% entry.name) % entry.name)
node.cf_is_null = True elif warn_maybe_uninitialized:
else:
if warn_maybe_uninitialized:
messages.warning( messages.warning(
node.pos, node.pos,
"local variable '%s' might be referenced before assignment" "local variable '%s' might be referenced before assignment"
......
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