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

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

parent 08e66edb
......@@ -3232,8 +3232,14 @@ class DefNode(FuncDefNode):
def put_into_closure(entry):
if entry.in_closure:
code.putln('%s = %s;' % (entry.cname, entry.original_cname))
code.put_var_incref(entry)
code.put_var_giveref(entry)
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_giveref(entry)
for arg in self.args:
put_into_closure(arg.entry)
for arg in self.star_arg, self.starstar_arg:
......
......@@ -502,3 +502,38 @@ def test_generator_abc():
True
"""
yield 1
# 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