Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
c2d76d32
Commit
c2d76d32
authored
Jan 08, 2020
by
da-woods
Committed by
Stefan Behnel
Jan 08, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed handling of kwds in generator closures (GH-3268)
parent
dd64445f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
2 deletions
+42
-2
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+8
-2
tests/run/generators.pyx
tests/run/generators.pyx
+34
-0
No files found.
Cython/Compiler/Nodes.py
View file @
c2d76d32
...
...
@@ -3256,8 +3256,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
:
...
...
tests/run/generators.pyx
View file @
c2d76d32
...
...
@@ -522,3 +522,37 @@ def test_generator_frame(a=1):
"""
b
=
a
+
1
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
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment