Commit d3c79c9b authored by Dag Sverre Seljebotn's avatar Dag Sverre Seljebotn

Disable array literals outside of pointer declaration

parent 9b19cce7
......@@ -935,7 +935,7 @@ class NameNode(AtomicExprNode):
is_name = True
is_cython_module = False
cython_attribute = None
skip_assignment_decref = False
lhs_of_first_assignment = False
entry = None
def create_analysed_rvalue(pos, env, entry):
......@@ -1157,6 +1157,10 @@ class NameNode(AtomicExprNode):
if entry is None:
return # There was an error earlier
if (self.entry.type.is_ptr and isinstance(rhs, ListNode)
and not self.lhs_of_first_assignment):
error(self.pos, "Literal list must be assigned to pointer at time of declaration")
# 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:
......@@ -1200,7 +1204,7 @@ class NameNode(AtomicExprNode):
#print "...from", rhs ###
#print "...LHS type", self.type, "ctype", self.ctype() ###
#print "...RHS type", rhs.type, "ctype", rhs.ctype() ###
if not self.skip_assignment_decref:
if not self.lhs_of_first_assignment:
if entry.is_local and not Options.init_local_none:
initalized = entry.scope.control_flow.get_state((entry.name, 'initalized'), self.pos)
if initalized is True:
......@@ -1223,7 +1227,7 @@ class NameNode(AtomicExprNode):
import Buffer
Buffer.put_assign_to_buffer(self.result(), rhstmp, buffer_aux, self.entry.type,
is_initialized=not self.skip_assignment_decref,
is_initialized=not self.lhs_of_first_assignment,
pos=self.pos, code=code)
code.putln("%s = 0;" % rhstmp)
code.funcstate.release_temp(rhstmp)
......
......@@ -152,12 +152,11 @@ class FinalOptimizePhase(Visitor.CythonTransform):
def visit_SingleAssignmentNode(self, node):
if node.first:
lhs = node.lhs
lhs.lhs_of_first_assignment = True
if isinstance(lhs, ExprNodes.NameNode) and lhs.entry.type.is_pyobject:
# Have variable initialized to 0 rather than None
lhs.entry.init_to_none = False
lhs.entry.init = 0
# Set a flag in NameNode to skip the decref
lhs.skip_assignment_decref = True
return node
def visit_SimpleCallNode(self, node):
......
def f():
cdef int* p
if False:
p = [1, 2, 3]
_ERRORS = u"""
4:10: Literal list must be assigned to pointer at time of declaration
"""
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