Author: Ronan Lamy <ronan.l...@gmail.com>
Branch: py3.5
Changeset: r93877:baf4067a05b0
Date: 2018-02-23 21:02 +0000
http://bitbucket.org/pypy/pypy/changeset/baf4067a05b0/

Log:    Don't segfault when calling ffi.from_buffer() on
        io.BytesIO().getbuffer()

diff --git a/pypy/module/_cffi_backend/test/test_ffi_obj.py 
b/pypy/module/_cffi_backend/test/test_ffi_obj.py
--- a/pypy/module/_cffi_backend/test/test_ffi_obj.py
+++ b/pypy/module/_cffi_backend/test/test_ffi_obj.py
@@ -288,6 +288,15 @@
         ffi.cast("unsigned short *", c)[1] += 500
         assert list(a) == [10000, 20500, 30000]
 
+    def test_from_buffer_BytesIO(self):
+        from _cffi_backend import FFI
+        import _io
+        ffi = FFI()
+        a = _io.BytesIO(b"Hello, world!")
+        buf = a.getbuffer()
+        # used to segfault
+        raises(TypeError, ffi.from_buffer, buf)
+
     def test_memmove(self):
         import sys
         import _cffi_backend as _cffi1_backend
diff --git a/pypy/module/_io/interp_bytesio.py 
b/pypy/module/_io/interp_bytesio.py
--- a/pypy/module/_io/interp_bytesio.py
+++ b/pypy/module/_io/interp_bytesio.py
@@ -48,6 +48,9 @@
         finally:
             w_bytesio.seek(tell)
 
+    def get_raw_address(self):
+        raise ValueError("BytesIOBuffer does not have a raw address")
+
 
 class W_BytesIO(W_BufferedIOBase):
     import_from_mixin(RStringIO)
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to