Author: Ronan Lamy <[email protected]>
Branch: PyBuffer
Changeset: r91104:f8384c7210fb
Date: 2017-04-20 18:57 +0100
http://bitbucket.org/pypy/pypy/changeset/f8384c7210fb/
Log: Merge space.getarg_w('y*') and space.readbuf_w()
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -11,7 +11,7 @@
INT_MIN, INT_MAX, UINT_MAX, USHRT_MAX
from pypy.interpreter.buffer import (
- BufferInterfaceNotFound, SimpleBuffer, StringBuffer)
+ BufferInterfaceNotFound, StringBuffer)
from pypy.interpreter.executioncontext import (ExecutionContext, ActionFlag,
make_finalizer_queue)
from pypy.interpreter.error import OperationError, new_exception_class, oefmt
@@ -1475,10 +1475,9 @@
def readbuf_w(self, w_obj):
# Old buffer interface, returns a readonly buffer
(PyObject_AsReadBuffer)
try:
- return w_obj.buffer_w(self, self.BUF_SIMPLE)
+ return w_obj.buffer_w(self, self.BUF_SIMPLE).as_binary()
except BufferInterfaceNotFound:
- raise oefmt(self.w_TypeError,
- "expected an object with a buffer interface")
+ self._getarg_error("bytes-like object", w_obj)
def writebuf_w(self, w_obj):
# Old buffer interface, returns a writeable buffer
(PyObject_AsWriteBuffer)
@@ -1538,10 +1537,7 @@
elif code == 'w*':
return self.writebuf_w(w_obj)
elif code == 'y*':
- try:
- return w_obj.buffer_w(self, self.BUF_SIMPLE).as_binary()
- except BufferInterfaceNotFound:
- self._getarg_error("bytes-like object", w_obj)
+ return self.readbuf_w(w_obj)
elif code == 'y#':
if self.isinstance_w(w_obj, self.w_bytes):
return w_obj.bytes_w(self)
diff --git a/pypy/module/_cffi_backend/func.py
b/pypy/module/_cffi_backend/func.py
--- a/pypy/module/_cffi_backend/func.py
+++ b/pypy/module/_cffi_backend/func.py
@@ -105,15 +105,7 @@
# ____________________________________________________________
def _fetch_as_read_buffer(space, w_x):
- # xxx do we really need to implement the same mess as in CPython 2.7
- # w.r.t. buffers and memoryviews??
- try:
- buf = space.readbuf_w(w_x)
- except OperationError as e:
- if not e.match(space, space.w_TypeError):
- raise
- buf = space.buffer_w(w_x, space.BUF_SIMPLE)
- return buf.as_binary()
+ return space.readbuf_w(w_x)
def _fetch_as_write_buffer(space, w_x):
return space.writebuf_w(w_x)
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
@@ -769,7 +769,7 @@
def write_w(self, space, w_data):
self._check_closed(space, "write to closed file")
- data = space.getarg_w('y*', w_data).as_str()
+ data = space.readbuf_w(w_data).as_str()
size = len(data)
with self.lock:
diff --git a/pypy/module/_io/interp_fileio.py b/pypy/module/_io/interp_fileio.py
--- a/pypy/module/_io/interp_fileio.py
+++ b/pypy/module/_io/interp_fileio.py
@@ -410,7 +410,7 @@
def write_w(self, space, w_data):
self._check_closed(space)
self._check_writable(space)
- data = space.getarg_w('y*', w_data).as_str()
+ data = space.readbuf_w(w_data).as_str()
while True:
try:
diff --git a/pypy/module/_sre/interp_sre.py b/pypy/module/_sre/interp_sre.py
--- a/pypy/module/_sre/interp_sre.py
+++ b/pypy/module/_sre/interp_sre.py
@@ -164,7 +164,7 @@
string = space.bytes_w(w_string)
length = len(string)
else:
- buf = space.readbuf_w(w_string).as_binary()
+ buf = space.readbuf_w(w_string)
length = buf.getlength()
assert length >= 0
return (length, unicodestr, string, buf)
diff --git a/pypy/module/array/interp_array.py
b/pypy/module/array/interp_array.py
--- a/pypy/module/array/interp_array.py
+++ b/pypy/module/array/interp_array.py
@@ -402,7 +402,7 @@
machine values, as if it had been read from a file using the
fromfile() method).
"""
- buf = space.getarg_w('y*', w_s)
+ buf = space.readbuf_w(w_s)
s = buf.as_str()
self._frombytes(space, s)
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
@@ -444,7 +444,7 @@
# Unmarshaller with inlined buffer string
def __init__(self, space, w_str):
Unmarshaller.__init__(self, space, None)
- self.buf = space.getarg_w('y*', w_str)
+ self.buf = space.readbuf_w(w_str)
self.bufpos = 0
self.limit = self.buf.getlength()
diff --git a/pypy/module/posix/interp_posix.py
b/pypy/module/posix/interp_posix.py
--- a/pypy/module/posix/interp_posix.py
+++ b/pypy/module/posix/interp_posix.py
@@ -285,7 +285,7 @@
def write(space, fd, w_data):
"""Write a string to a file descriptor. Return the number of bytes
actually written, which may be smaller than len(data)."""
- data = space.getarg_w('y*', w_data)
+ data = space.readbuf_w(w_data)
while True:
try:
res = os.write(fd, data.as_str())
@@ -392,7 +392,7 @@
def pwrite(space, fd, w_data, offset):
"""Write a string to a file descriptor at a given offset.
"""
- data = space.getarg_w('y*', w_data)
+ data = space.readbuf_w(w_data)
while True:
try:
res = rposix.pwrite(fd, data.as_str(), offset)
diff --git a/pypy/module/struct/interp_struct.py
b/pypy/module/struct/interp_struct.py
--- a/pypy/module/struct/interp_struct.py
+++ b/pypy/module/struct/interp_struct.py
@@ -112,7 +112,7 @@
return do_unpack(space, format, w_str)
def do_unpack(space, format, w_str):
- buf = space.getarg_w('y*', w_str)
+ buf = space.readbuf_w(w_str)
return _unpack(space, format, buf)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit