Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
339e91d4
Commit
339e91d4
authored
Jan 25, 2013
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Plain Diff
Issue #13454: Fix a crash when deleting an iterator created by itertools.tee()
if all other iterators were very advanced before.
parents
5070c27a
a3e9128a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
1 deletion
+31
-1
Lib/test/test_itertools.py
Lib/test/test_itertools.py
+8
-0
Misc/NEWS
Misc/NEWS
+3
-0
Modules/itertoolsmodule.c
Modules/itertoolsmodule.c
+20
-1
No files found.
Lib/test/test_itertools.py
View file @
339e91d4
...
...
@@ -1267,6 +1267,14 @@ class TestBasicOps(unittest.TestCase):
self
.
pickletest
(
a
,
compare
=
ans
)
self
.
pickletest
(
b
,
compare
=
ans
)
# Issue 13454: Crash when deleting backward iterator from tee()
def
test_tee_del_backward
(
self
):
forward
,
backward
=
tee
(
range
(
20000000
))
for
i
in
forward
:
pass
del
backward
def
test_StopIteration
(
self
):
self
.
assertRaises
(
StopIteration
,
next
,
zip
())
...
...
Misc/NEWS
View file @
339e91d4
...
...
@@ -150,6 +150,9 @@ Core and Builtins
Library
-------
-
Issue
#
13454
:
Fix
a
crash
when
deleting
an
iterator
created
by
itertools
.
tee
()
if
all
other
iterators
were
very
advanced
before
.
-
Issue
#
12411
:
Fix
to
cgi
.
parse_multipart
to
correctly
use
bytes
boundaries
and
bytes
data
.
Patch
by
Jonas
Wagner
.
...
...
Modules/itertoolsmodule.c
View file @
339e91d4
...
...
@@ -473,14 +473,31 @@ teedataobject_traverse(teedataobject *tdo, visitproc visit, void * arg)
return
0
;
}
static
void
teedataobject_safe_decref
(
PyObject
*
obj
)
{
while
(
obj
&&
Py_TYPE
(
obj
)
==
&
teedataobject_type
&&
Py_REFCNT
(
obj
)
==
1
)
{
PyObject
*
nextlink
=
((
teedataobject
*
)
obj
)
->
nextlink
;
((
teedataobject
*
)
obj
)
->
nextlink
=
NULL
;
Py_DECREF
(
obj
);
obj
=
nextlink
;
}
Py_XDECREF
(
obj
);
}
static
int
teedataobject_clear
(
teedataobject
*
tdo
)
{
int
i
;
PyObject
*
tmp
;
Py_CLEAR
(
tdo
->
it
);
for
(
i
=
0
;
i
<
tdo
->
numread
;
i
++
)
Py_CLEAR
(
tdo
->
values
[
i
]);
Py_CLEAR
(
tdo
->
nextlink
);
tmp
=
tdo
->
nextlink
;
tdo
->
nextlink
=
NULL
;
teedataobject_safe_decref
(
tmp
);
return
0
;
}
...
...
@@ -617,6 +634,8 @@ tee_next(teeobject *to)
if
(
to
->
index
>=
LINKCELLS
)
{
link
=
teedataobject_jumplink
(
to
->
dataobj
);
if
(
link
==
NULL
)
return
NULL
;
Py_DECREF
(
to
->
dataobj
);
to
->
dataobj
=
(
teedataobject
*
)
link
;
to
->
index
=
0
;
...
...
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