[pypy-svn] pypy default: Fixed a segfault in StringIO.

alex_gaynor commits-noreply at bitbucket.org
Fri Feb 4 04:48:48 CET 2011


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: 
Changeset: r41598:5fcda453df94
Date: 2011-02-03 22:48 -0500
http://bitbucket.org/pypy/pypy/changeset/5fcda453df94/

Log:	Fixed a segfault in StringIO.

diff --git a/pypy/module/_io/test/test_stringio.py b/pypy/module/_io/test/test_stringio.py
--- a/pypy/module/_io/test/test_stringio.py
+++ b/pypy/module/_io/test/test_stringio.py
@@ -239,3 +239,28 @@
         assert sio.newlines == ("\n", "\r\n")
         sio.write(u"c\rd")
         assert sio.newlines == ("\r", "\n", "\r\n")
+
+    def test_iterator(self):
+        import io
+
+        s = u"1234567890\n"
+        sio = io.StringIO(s * 10)
+
+        assert iter(sio) is sio
+        assert hasattr(sio, "__iter__")
+        assert hasattr(sio, "next")
+
+        i = 0
+        for line in sio:
+            assert line == s
+            i += 1
+        assert i == 10
+        sio.seek(0)
+        i = 0
+        for line in sio:
+            assert line == s
+            i += 1
+        assert i == 10
+        sio = io.StringIO(s * 2)
+        sio.close()
+        raises(ValueError, next, sio)

diff --git a/pypy/module/_io/interp_stringio.py b/pypy/module/_io/interp_stringio.py
--- a/pypy/module/_io/interp_stringio.py
+++ b/pypy/module/_io/interp_stringio.py
@@ -121,6 +121,8 @@
 
     @unwrap_spec('self', ObjSpace, int)
     def readline_w(self, space, limit=-1):
+        self._check_closed(space)
+
         if self.pos >= len(self.buf):
             return space.wrap(u"")
 


More information about the Pypy-commit mailing list