Commit ffea991b authored by Stefan Behnel's avatar Stefan Behnel

fix ticket #712: sequence unpacking of known types crashed the compiler

parent e0fa6040
...@@ -4055,6 +4055,8 @@ class SequenceNode(ExprNode): ...@@ -4055,6 +4055,8 @@ class SequenceNode(ExprNode):
# Need to work around the fact that generate_evaluation_code # Need to work around the fact that generate_evaluation_code
# allocates the temps in a rather hacky way -- the assignment # allocates the temps in a rather hacky way -- the assignment
# is evaluated twice, within each if-block. # is evaluated twice, within each if-block.
for item in self.unpacked_items:
item.allocate(code)
special_unpack = (rhs.type is py_object_type special_unpack = (rhs.type is py_object_type
or rhs.type in (tuple_type, list_type) or rhs.type in (tuple_type, list_type)
or not rhs.type.is_builtin_type) or not rhs.type.is_builtin_type)
...@@ -4072,8 +4074,6 @@ class SequenceNode(ExprNode): ...@@ -4072,8 +4074,6 @@ class SequenceNode(ExprNode):
sequence_type_test = "(%s) || (%s)" % (tuple_check, list_check) sequence_type_test = "(%s) || (%s)" % (tuple_check, list_check)
code.putln("if (%s) {" % sequence_type_test) code.putln("if (%s) {" % sequence_type_test)
code.putln("PyObject* sequence = %s;" % rhs.py_result()) code.putln("PyObject* sequence = %s;" % rhs.py_result())
for item in self.unpacked_items:
item.allocate(code)
if len(sequence_types) == 2: if len(sequence_types) == 2:
code.putln("if (likely(Py%s_CheckExact(sequence))) {" % sequence_types[0]) code.putln("if (likely(Py%s_CheckExact(sequence))) {" % sequence_types[0])
self.generate_special_parallel_unpacking_code(code, sequence_types[0]) self.generate_special_parallel_unpacking_code(code, sequence_types[0])
......
# mode: run
# ticket: 712
def single_from_string():
"""
>>> print(single_from_string())
a
"""
(a,) = 'a'
return a
def single_from_set():
"""
>>> print(single_from_set())
a
"""
(a,) = set(["a"])
return a
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