Commit 94b87c52 authored by Stefan Behnel's avatar Stefan Behnel

fix DECREF(NULL) for empty comprehensions

parent 12a1d869
......@@ -7896,7 +7896,7 @@ class ScopedExprNode(ExprNode):
# normal (non-error) exit
for entry in py_entries:
code.put_var_decref_clear(entry)
code.put_var_xdecref_clear(entry)
# error/loop body exit points
exit_scope = code.new_label('exit_scope')
......@@ -7906,7 +7906,7 @@ class ScopedExprNode(ExprNode):
if code.label_used(label):
code.put_label(label)
for entry in py_entries:
code.put_var_decref_clear(entry)
code.put_var_xdecref_clear(entry)
code.put_goto(old_label)
code.put_label(exit_scope)
code.putln('} /* exit inner scope */')
......
......@@ -329,6 +329,7 @@ def loop_over_unicode_literal():
assert uchar in 'abcdefg'
return cython.typeof(uchar)
def list_comp():
"""
>>> list_comp()
......@@ -339,6 +340,28 @@ def list_comp():
assert x == 'abc' # don't leak in Py3 code
return result
def list_comp_iterable(it):
"""
>>> list_comp_iterable([])
[]
>>> list_comp_iterable([0])
[0]
>>> list_comp_iterable([1])
[]
>>> list_comp_iterable([0, 1])
[0]
>>> list_comp_iterable([2])
[4]
>>> list_comp_iterable(range(5))
[0, 4, 8]
"""
x = 'abc'
result = [x*2 for x in it if x % 2 == 0]
assert x == 'abc' # don't leak in Py3 code
return result
def list_comp_with_lambda():
"""
>>> list_comp_with_lambda()
......
......@@ -97,6 +97,10 @@ def listcomp_as_condition(sequence):
@cython.test_assert_path_exists("//ComprehensionNode")
def sorted_listcomp(sequence):
"""
>>> sorted_listcomp([])
[]
>>> sorted_listcomp([1])
[2]
>>> sorted_listcomp([3,2,4])
[3, 4, 5]
"""
......
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