Commit 3279d914 authored by Stefan Behnel's avatar Stefan Behnel

work around missing temp variable declaration when a multiplied tuple ends up as cached constant

parent 6fc4bd3c
...@@ -4432,8 +4432,17 @@ class SequenceNode(ExprNode): ...@@ -4432,8 +4432,17 @@ class SequenceNode(ExprNode):
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())
if mult: if mult:
counter = code.funcstate.allocate_temp(self.mult_factor.type, manage_ref=False) # FIXME: can't use a temp variable here as the code may
offset = '%s * %s + ' % (counter, arg_count) # end up in the constant building function. Temps
# currently don't work there.
#counter = code.funcstate.allocate_temp(self.mult_factor.type, manage_ref=False)
counter = '__pyx_n'
code.putln('{ Py_ssize_t %s;' % counter)
if arg_count == 1:
offset = counter + ' + '
else:
offset = '%s * %s + ' % (counter, arg_count)
code.putln('for (%s=0; %s < %s; %s++) {' % ( code.putln('for (%s=0; %s < %s; %s++) {' % (
counter, counter, mult, counter counter, counter, mult, counter
)) ))
...@@ -4452,7 +4461,8 @@ class SequenceNode(ExprNode): ...@@ -4452,7 +4461,8 @@ class SequenceNode(ExprNode):
code.put_giveref(arg.py_result()) code.put_giveref(arg.py_result())
if mult: if mult:
code.putln('}') code.putln('}')
code.funcstate.release_temp(counter) #code.funcstate.release_temp(counter)
code.putln('}')
def generate_subexpr_disposal_code(self, code): def generate_subexpr_disposal_code(self, code):
if self.mult_factor: if self.mult_factor:
......
...@@ -167,6 +167,14 @@ def multiplied_lists_with_side_effects(): ...@@ -167,6 +167,14 @@ def multiplied_lists_with_side_effects():
""" """
return [side_effect(1), side_effect(2), side_effect(3)] * 5 return [side_effect(1), side_effect(2), side_effect(3)] * 5
@cython.test_fail_if_path_exists("//MulNode")
def multiplied_const_tuple():
"""
>>> multiplied_const_tuple() == (1,2) * 5
True
"""
return (1,2) * 5
@cython.test_fail_if_path_exists("//PrimaryCmpNode") @cython.test_fail_if_path_exists("//PrimaryCmpNode")
def compile_time_DEF(): def compile_time_DEF():
""" """
......
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