Author: Ronan Lamy <[email protected]>
Branch: PyBuffer-backport
Changeset: r91238:393498f6a662
Date: 2017-05-11 03:37 +0100
http://bitbucket.org/pypy/pypy/changeset/393498f6a662/

Log:    Ensure that buffer() returns read-only buffers

diff --git a/pypy/objspace/std/bufferobject.py 
b/pypy/objspace/std/bufferobject.py
--- a/pypy/objspace/std/bufferobject.py
+++ b/pypy/objspace/std/bufferobject.py
@@ -5,7 +5,7 @@
 from rpython.rlib.objectmodel import compute_hash
 
 from pypy.interpreter.baseobjspace import W_Root
-from pypy.interpreter.buffer import SimpleView
+from pypy.interpreter.buffer import SimpleView, BufferInterfaceNotFound
 from pypy.interpreter.error import OperationError, oefmt
 from pypy.interpreter.gateway import interp2app, unwrap_spec
 from pypy.interpreter.typedef import TypeDef
@@ -40,7 +40,10 @@
     @staticmethod
     @unwrap_spec(offset=int, size=int)
     def descr_new_buffer(space, w_subtype, w_object, offset=0, size=-1):
-        buf = space.readbuf_w(w_object)
+        try:
+            buf = w_object.readbuf_w(space)
+        except BufferInterfaceNotFound:
+            raise oefmt(space.w_TypeError, "expected a readable buffer object")
         if offset == 0 and size == -1:
             return W_Buffer(buf)
         # handle buffer slices
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to