]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
#7782: add a test for test_iter.
authorEzio Melotti <ezio.melotti@gmail.com>
Sun, 18 Nov 2012 21:14:42 +0000 (23:14 +0200)
committerEzio Melotti <ezio.melotti@gmail.com>
Sun, 18 Nov 2012 21:14:42 +0000 (23:14 +0200)
Lib/test/test_iter.py

index e424303305737cd0ba2f05559d6a2498ff6cd395..4d971835cb15b485b44756b82fe3d40e08b161f5 100644 (file)
@@ -876,6 +876,21 @@ class TestCase(unittest.TestCase):
         except TypeError:
             pass
 
+    def test_extending_list_with_iterator_does_not_segfault(self):
+        # The code to extend a list with an iterator has a fair
+        # amount of nontrivial logic in terms of guessing how
+        # much memory to allocate in advance, "stealing" refs,
+        # and then shrinking at the end.  This is a basic smoke
+        # test for that scenario.
+        def gen():
+            for i in range(500):
+                yield i
+        lst = [0] * 500
+        for i in range(240):
+            lst.pop(0)
+        lst.extend(gen())
+        self.assertEqual(len(lst), 760)
+
 
 def test_main():
     run_unittest(TestCase)