[pypy-commit] pypy default: Fix some segfaults after a file is detached.

amauryfa noreply at buildbot.pypy.org
Sat Jun 13 00:00:59 CEST 2015


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: 
Changeset: r78060:cef7d7a0598d
Date: 2015-06-12 23:43 +0200
http://bitbucket.org/pypy/pypy/changeset/cef7d7a0598d/

Log:	Fix some segfaults after a file is detached.

diff --git a/pypy/module/_io/interp_bufferedio.py b/pypy/module/_io/interp_bufferedio.py
--- a/pypy/module/_io/interp_bufferedio.py
+++ b/pypy/module/_io/interp_bufferedio.py
@@ -196,9 +196,11 @@
         return space.getattr(self.w_raw, space.wrap("closed"))
 
     def name_get_w(self, space):
+        self._check_init(space)
         return space.getattr(self.w_raw, space.wrap("name"))
 
     def mode_get_w(self, space):
+        self._check_init(space)
         return space.getattr(self.w_raw, space.wrap("mode"))
 
     def readable_w(self, space):
@@ -214,6 +216,7 @@
         return space.call_method(self.w_raw, "seekable")
 
     def isatty_w(self, space):
+        self._check_init(space)
         return space.call_method(self.w_raw, "isatty")
 
     def repr_w(self, space):
@@ -221,7 +224,7 @@
         try:
             w_name = space.getattr(self, space.wrap("name"))
         except OperationError, e:
-            if not e.match(space, space.w_AttributeError):
+            if not e.match(space, space.w_Exception):
                 raise
             return space.wrap("<%s>" % (typename,))
         else:
diff --git a/pypy/module/_io/test/test_bufferedio.py b/pypy/module/_io/test/test_bufferedio.py
--- a/pypy/module/_io/test/test_bufferedio.py
+++ b/pypy/module/_io/test/test_bufferedio.py
@@ -180,6 +180,20 @@
         assert not raw.closed
         raw.close()
 
+    def test_detached(self):
+        import _io
+        class MockRawIO(_io._RawIOBase):
+            def readable(self):
+                return True
+        raw = MockRawIO()
+        buf = _io.BufferedReader(raw)
+        assert buf.detach() is raw
+        raises(ValueError, buf.detach)
+
+        raises(ValueError, getattr, buf, 'mode')
+        raises(ValueError, buf.isatty)
+        repr(buf)  # Should still work
+
     def test_tell(self):
         import _io
         raw = _io.FileIO(self.tmpfile)


More information about the pypy-commit mailing list