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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Xavier Thompson
cython
Commits
83e4a348
Commit
83e4a348
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
08e66edb
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
2 deletions
+43
-2
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+8
-2
tests/run/generators.pyx
tests/run/generators.pyx
+35
-0
No files found.
Cython/Compiler/Nodes.py
View file @
83e4a348
...
@@ -3232,6 +3232,12 @@ class DefNode(FuncDefNode):
...
@@ -3232,6 +3232,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
:
...
...
tests/run/generators.pyx
View file @
83e4a348
...
@@ -502,3 +502,38 @@ def test_generator_abc():
...
@@ -502,3 +502,38 @@ def test_generator_abc():
True
True
"""
"""
yield
1
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
()
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