[pypy-commit] pypy refactor-buffer-api: replace usage of bufferstr_w in marshal

bdkearns noreply at buildbot.pypy.org
Thu Apr 24 22:52:13 CEST 2014


Author: Brian Kearns <bdkearns at gmail.com>
Branch: refactor-buffer-api
Changeset: r70938:4027486ec885
Date: 2014-04-24 16:34 -0400
http://bitbucket.org/pypy/pypy/changeset/4027486ec885/

Log:	replace usage of bufferstr_w in marshal

diff --git a/pypy/module/marshal/interp_marshal.py b/pypy/module/marshal/interp_marshal.py
--- a/pypy/module/marshal/interp_marshal.py
+++ b/pypy/module/marshal/interp_marshal.py
@@ -476,13 +476,7 @@
     # Unmarshaller with inlined buffer string
     def __init__(self, space, w_str):
         Unmarshaller.__init__(self, space, None)
-        try:
-            self.bufstr = space.bufferstr_w(w_str)
-        except OperationError, e:
-            if not e.match(space, space.w_TypeError):
-                raise
-            raise OperationError(space.w_TypeError, space.wrap(
-                'marshal.loads() arg must be string or buffer'))
+        self.bufstr = space.getarg_w('s#', w_str)
         self.bufpos = 0
         self.limit = len(self.bufstr)
 
diff --git a/pypy/module/marshal/test/test_marshal.py b/pypy/module/marshal/test/test_marshal.py
--- a/pypy/module/marshal/test/test_marshal.py
+++ b/pypy/module/marshal/test/test_marshal.py
@@ -14,6 +14,10 @@
         print(repr(s))
         x = marshal.loads(s)
         assert x == case and type(x) is type(case)
+
+        exc = raises(TypeError, marshal.loads, memoryview(s))
+        assert str(exc.value) == "must be string or read-only buffer, not memoryview"
+
         f = StringIO.StringIO()
         marshal.dump(case, f)
         f.seek(0)


More information about the pypy-commit mailing list