Armin Rigo | dcde494 | 2008-08-29 21:21:52 +0000 | [diff] [blame] | 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() |