Skip to content

Commit dcde494

Browse files
committed
A collection of crashers, all variants of the idea
of issue #3720.
1 parent d4ae97b commit dcde494

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

Lib/test/crashers/iter.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Calls to PyIter_Next, or direct calls to tp_iternext, on an object
2+
# which might no longer be an iterable because its 'next' method was
3+
# removed. These are all variants of Issue3720.
4+
5+
"""
6+
Run this script with an argument between 1 and <N> to test for
7+
different crashes.
8+
"""
9+
N = 8
10+
11+
import sys
12+
13+
class Foo(object):
14+
def __iter__(self):
15+
return self
16+
def next(self):
17+
del Foo.next
18+
return (1, 2)
19+
20+
def case1():
21+
list(enumerate(Foo()))
22+
23+
def case2():
24+
x, y = Foo()
25+
26+
def case3():
27+
filter(None, Foo())
28+
29+
def case4():
30+
map(None, Foo(), Foo())
31+
32+
def case5():
33+
max(Foo())
34+
35+
def case6():
36+
sum(Foo(), ())
37+
38+
def case7():
39+
dict(Foo())
40+
41+
def case8():
42+
sys.stdout.writelines(Foo())
43+
44+
# etc...
45+
46+
47+
if __name__ == '__main__':
48+
if len(sys.argv) < 2:
49+
print __doc__.replace('<N>', str(N))
50+
else:
51+
n = int(sys.argv[1])
52+
func = globals()['case%d' % n]
53+
func()

0 commit comments

Comments
 (0)