Commit c2d76d32 authored by da-woods's avatar da-woods Committed by Stefan Behnel

Fixed handling of kwds in generator closures (GH-3268)

parent dd64445f
...@@ -3256,6 +3256,12 @@ class DefNode(FuncDefNode): ...@@ -3256,6 +3256,12 @@ class DefNode(FuncDefNode):
def put_into_closure(entry): def put_into_closure(entry):
if entry.in_closure: if entry.in_closure:
code.putln('%s = %s;' % (entry.cname, entry.original_cname)) code.putln('%s = %s;' % (entry.cname, entry.original_cname))
if entry.xdecref_cleanup:
# mostly applies to the starstar arg - this can sometimes be NULL
# so must be xincrefed instead
code.put_var_xincref(entry)
code.put_var_xgiveref(entry)
else:
code.put_var_incref(entry) code.put_var_incref(entry)
code.put_var_giveref(entry) code.put_var_giveref(entry)
for arg in self.args: for arg in self.args:
......
...@@ -522,3 +522,37 @@ def test_generator_frame(a=1): ...@@ -522,3 +522,37 @@ def test_generator_frame(a=1):
""" """
b = a + 1 b = a + 1
yield b yield b
# GH Issue 3265 - **kwds could cause a crash in some cases due to not
# handling NULL pointers (in testing it shows as a REFNANNY error).
# This was on creation of the generator and
# doesn't really require it to be iterated through:
def some_function():
return 0
def test_generator_kwds1(**kwargs):
"""
>>> for a in test_generator_kwds1():
... print(a)
0
"""
yield some_function(**kwargs)
def test_generator_kwds2(**kwargs):
"""
>>> for a in test_generator_kwds2():
... print(a)
0
"""
yield 0
def test_generator_kwds3(**kwargs):
"""
This didn't actually crash before but is still worth a try
>>> len(list(test_generator_kwds3()))
0
>>> for a in test_generator_kwds3(a=1):
... print(a)
a
"""
yield from kwargs.keys()
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