[pypy-commit] pypy PyBuffer-backport: Restrict marshalling to old-style buffers

rlamy pypy.commits at gmail.com
Thu May 11 11:58:09 EDT 2017


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: PyBuffer-backport
Changeset: r91254:647b63731eca
Date: 2017-05-11 16:53 +0100
http://bitbucket.org/pypy/pypy/changeset/647b63731eca/

Log:	Restrict marshalling to old-style buffers

diff --git a/pypy/objspace/std/marshal_impl.py b/pypy/objspace/std/marshal_impl.py
--- a/pypy/objspace/std/marshal_impl.py
+++ b/pypy/objspace/std/marshal_impl.py
@@ -7,6 +7,7 @@
 from pypy.interpreter.special import Ellipsis
 from pypy.interpreter.pycode import PyCode
 from pypy.interpreter import unicodehelper
+from pypy.interpreter.buffer import BufferInterfaceNotFound
 from pypy.objspace.std.boolobject import W_BoolObject
 from pypy.objspace.std.bytesobject import W_BytesObject
 from pypy.objspace.std.complexobject import W_ComplexObject
@@ -73,14 +74,12 @@
                 func(space, w_obj, m)
                 return
 
-    # any unknown object implementing the buffer protocol is
+    # any unknown object implementing the old-style buffer protocol is
     # accepted and encoded as a plain string
     try:
-        s = space.readbuf_w(w_obj)
-    except OperationError as e:
-        if e.match(space, space.w_TypeError):
-            raise oefmt(space.w_ValueError, "unmarshallable object")
-        raise
+        s = w_obj.readbuf_w(space)
+    except BufferInterfaceNotFound:
+        raise oefmt(space.w_ValueError, "unmarshallable object")
     m.atom_str(TYPE_STRING, s.as_str())
 
 def get_unmarshallers():


More information about the pypy-commit mailing list