Author: Matti Picus <[email protected]>
Branch: unicode-utf8-py3
Changeset: r95022:9283282e9030
Date: 2018-08-22 12:23 +0300
http://bitbucket.org/pypy/pypy/changeset/9283282e9030/
Log: merge py3.5 into branch
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -1520,10 +1520,19 @@
if readonly and flags & self.BUF_WRITABLE == self.BUF_WRITABLE:
raise oefmt(self.w_BufferError, "Object is not writable.")
+ def _try_buffer_w(self, w_obj, flags):
+ if not we_are_translated():
+ if w_obj.buffer_w.im_func != W_Root.buffer_w.im_func:
+ # when 'buffer_w()' is overridden in the subclass of
+ # W_Root, we need to specify __buffer="read" or
+ # __buffer="read-write" in the TypeDef.
+ assert type(w_obj).typedef.buffer is not None
+ return w_obj.buffer_w(self, flags)
+
def buffer_w(self, w_obj, flags):
# New buffer interface, returns a buffer based on flags
(PyObject_GetBuffer)
try:
- return w_obj.buffer_w(self, flags)
+ return self._try_buffer_w(w_obj, flags)
except BufferInterfaceNotFound:
raise oefmt(self.w_TypeError,
"'%T' does not support the buffer interface", w_obj)
@@ -1531,14 +1540,14 @@
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).as_readbuf()
+ return self._try_buffer_w(w_obj, self.BUF_SIMPLE).as_readbuf()
except BufferInterfaceNotFound:
self._getarg_error("bytes-like object", w_obj)
def writebuf_w(self, w_obj):
# Old buffer interface, returns a writeable buffer
(PyObject_AsWriteBuffer)
try:
- return w_obj.buffer_w(self, self.BUF_WRITABLE).as_writebuf()
+ return self._try_buffer_w(w_obj, self.BUF_WRITABLE).as_writebuf()
except (BufferInterfaceNotFound, OperationError):
self._getarg_error("read-write bytes-like object", w_obj)
@@ -1572,7 +1581,7 @@
# NB. CPython forbids surrogates here
return StringBuffer(w_obj.text_w(self))
try:
- return w_obj.buffer_w(self, self.BUF_SIMPLE).as_readbuf()
+ return self._try_buffer_w(w_obj, self.BUF_SIMPLE).as_readbuf()
except BufferInterfaceNotFound:
self._getarg_error("bytes or buffer", w_obj)
elif code == 's#':
@@ -1584,7 +1593,7 @@
if self.isinstance_w(w_obj, self.w_unicode): # NB. CPython forbids
return w_obj.text_w(self) # surrogates here
try:
- return w_obj.buffer_w(self, self.BUF_SIMPLE).as_str()
+ return self._try_buffer_w(w_obj, self.BUF_SIMPLE).as_str()
except BufferInterfaceNotFound:
self._getarg_error("bytes or read-only buffer", w_obj)
elif code == 'w*':
diff --git a/pypy/interpreter/typedef.py b/pypy/interpreter/typedef.py
--- a/pypy/interpreter/typedef.py
+++ b/pypy/interpreter/typedef.py
@@ -28,6 +28,9 @@
self.bases = bases
# Used in cpyext to fill tp_as_buffer slots
assert __buffer in {None, 'read-write', 'read'}, "Unknown value for
__buffer"
+ for base in bases:
+ if __buffer is None:
+ __buffer = base.buffer
self.buffer = __buffer
self.heaptype = False
self.hasdict = '__dict__' in rawdict
diff --git a/pypy/module/_cffi_backend/cbuffer.py
b/pypy/module/_cffi_backend/cbuffer.py
--- a/pypy/module/_cffi_backend/cbuffer.py
+++ b/pypy/module/_cffi_backend/cbuffer.py
@@ -156,7 +156,7 @@
return MiniBuffer(LLBuffer(ptr, size), w_cdata)
MiniBuffer.typedef = TypeDef(
- "_cffi_backend.buffer",
+ "_cffi_backend.buffer", None, None, "read-write",
__new__ = interp2app(MiniBuffer___new__),
__len__ = interp2app(MiniBuffer.descr_len),
__getitem__ = interp2app(MiniBuffer.descr_getitem),
diff --git a/pypy/module/_rawffi/array.py b/pypy/module/_rawffi/array.py
--- a/pypy/module/_rawffi/array.py
+++ b/pypy/module/_rawffi/array.py
@@ -191,7 +191,7 @@
W_ArrayInstance.typedef = TypeDef(
- 'ArrayInstance',
+ 'ArrayInstance', None, None, "read-write",
__repr__ = interp2app(W_ArrayInstance.descr_repr),
__setitem__ = interp2app(W_ArrayInstance.descr_setitem),
__getitem__ = interp2app(W_ArrayInstance.descr_getitem),
@@ -215,7 +215,7 @@
self._free()
W_ArrayInstanceAutoFree.typedef = TypeDef(
- 'ArrayInstanceAutoFree',
+ 'ArrayInstanceAutoFree', None, None, "read-write",
__repr__ = interp2app(W_ArrayInstance.descr_repr),
__setitem__ = interp2app(W_ArrayInstance.descr_setitem),
__getitem__ = interp2app(W_ArrayInstance.descr_getitem),
diff --git a/pypy/module/_rawffi/callback.py b/pypy/module/_rawffi/callback.py
--- a/pypy/module/_rawffi/callback.py
+++ b/pypy/module/_rawffi/callback.py
@@ -135,7 +135,7 @@
return W_CallbackPtr(space, w_callable, w_args, w_result, flags)
W_CallbackPtr.typedef = TypeDef(
- 'CallbackPtr',
+ 'CallbackPtr', None, None, "read",
__new__ = interp2app(descr_new_callbackptr),
byptr = interp2app(W_CallbackPtr.byptr),
buffer = GetSetProperty(W_CallbackPtr.getbuffer),
diff --git a/pypy/module/_rawffi/structure.py b/pypy/module/_rawffi/structure.py
--- a/pypy/module/_rawffi/structure.py
+++ b/pypy/module/_rawffi/structure.py
@@ -379,7 +379,7 @@
W_StructureInstance.typedef = TypeDef(
- 'StructureInstance',
+ 'StructureInstance', None, None, "read-write",
__repr__ = interp2app(W_StructureInstance.descr_repr),
__getattr__ = interp2app(W_StructureInstance.getattr),
__setattr__ = interp2app(W_StructureInstance.setattr),
@@ -401,7 +401,7 @@
self._free()
W_StructureInstanceAutoFree.typedef = TypeDef(
- 'StructureInstanceAutoFree',
+ 'StructureInstanceAutoFree', None, None, "read-write",
__repr__ = interp2app(W_StructureInstance.descr_repr),
__getattr__ = interp2app(W_StructureInstance.getattr),
__setattr__ = interp2app(W_StructureInstance.setattr),
diff --git a/pypy/module/cpyext/test/test_buffer.py
b/pypy/module/cpyext/test/test_buffer.py
--- a/pypy/module/cpyext/test/test_buffer.py
+++ b/pypy/module/cpyext/test/test_buffer.py
@@ -9,13 +9,21 @@
void* buf;
Py_ssize_t buf_len;
if (PyObject_AsWriteBuffer(args, &buf, &buf_len) < 0) {
- PyErr_SetString(PyExc_ValueError, "bad value");
+ //PyErr_SetString(PyExc_ValueError, "bad value");
return NULL;
}
return PyLong_FromLong(buf_len);
""")])
assert module.write_buffer_len(bytearray(b'123')) == 3
assert module.write_buffer_len(array.array('i', [1, 2, 3])) == 12
+ #
+ import _cffi_backend
+ BChar = _cffi_backend.new_primitive_type("char")
+ BCharPtr = _cffi_backend.new_pointer_type(BChar)
+ BCharArray = _cffi_backend.new_array_type(BCharPtr, None)
+ p = _cffi_backend.newp(BCharArray, b"abcde")
+ bb = _cffi_backend.buffer(p)
+ assert module.write_buffer_len(bb) == 6
class AppTestMmap(AppTestCpythonExtensionBase):
diff --git a/pypy/module/cpyext/test/test_cpyext.py
b/pypy/module/cpyext/test/test_cpyext.py
--- a/pypy/module/cpyext/test/test_cpyext.py
+++ b/pypy/module/cpyext/test/test_cpyext.py
@@ -138,6 +138,7 @@
"""Base class for all cpyext tests."""
spaceconfig = dict(usemodules=['cpyext', 'thread', 'struct', 'array',
'itertools', 'time', 'binascii', 'mmap',
+ '_cffi_backend',
])
@classmethod
diff --git a/pypy/module/micronumpy/boxes.py b/pypy/module/micronumpy/boxes.py
--- a/pypy/module/micronumpy/boxes.py
+++ b/pypy/module/micronumpy/boxes.py
@@ -656,7 +656,7 @@
def descr__getattr__(self, space, w_key):
return space.getattr(self.w_obj, w_key)
-W_GenericBox.typedef = TypeDef("numpy.generic",
+W_GenericBox.typedef = TypeDef("numpy.generic", None, None, "read-write",
__new__ = interp2app(W_GenericBox.descr__new__.im_func),
__getitem__ = interp2app(W_GenericBox.descr_getitem),
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
@@ -2408,7 +2408,7 @@
if _WIN32:
have_functions.append("HAVE_MS_WINDOWS")
-def get_terminal_size(space, w_fd=None):
+def _get_terminal_size(space, w_fd=None):
if w_fd is None:
fd = rfile.RFile(rfile.c_stdout(), close2=(None, None)).fileno()
else:
@@ -2448,7 +2448,13 @@
w_columns = space.newint(r_uint(winsize.c_ws_col))
w_lines = space.newint(r_uint(winsize.c_ws_row))
+ return w_columns, w_lines
+def get_terminal_size(space, w_fd=None):
+ try:
+ w_columns, w_lines = _get_terminal_size(space, w_fd)
+ except OSError as e:
+ raise wrap_oserror(space, e, eintr_retry=False)
w_tuple = space.newtuple([w_columns, w_lines])
w_terminal_size = space.getattr(space.getbuiltinmodule(os.name),
space.newtext('terminal_size'))
diff --git a/pypy/module/posix/test/test_posix2.py
b/pypy/module/posix/test/test_posix2.py
--- a/pypy/module/posix/test/test_posix2.py
+++ b/pypy/module/posix/test/test_posix2.py
@@ -1488,6 +1488,16 @@
raises(OSError, os.getxattr, self.path, 'user.test')
assert os.listxattr(self.path, follow_symlinks=False) == init_names
+ def test_get_terminal_size(self):
+ os = self.posix
+ for args in [(), (1,), (0,), (42421,)]:
+ try:
+ w, h = os.get_terminal_size(*args)
+ except (ValueError, OSError):
+ continue
+ assert isinstance(w, int)
+ assert isinstance(h, int)
+
class AppTestEnvironment(object):
def setup_class(cls):
diff --git a/pypy/objspace/fake/objspace.py b/pypy/objspace/fake/objspace.py
--- a/pypy/objspace/fake/objspace.py
+++ b/pypy/objspace/fake/objspace.py
@@ -369,6 +369,9 @@
def warn(self, w_msg, w_warningcls, stacklevel=2):
pass
+ def _try_buffer_w(self, w_obj, flags):
+ return w_obj.buffer_w(self, flags)
+
# ----------
def translates(self, func=None, argtypes=None, seeobj_w=[], **kwds):
diff --git a/pypy/objspace/std/test/test_memoryobject.py
b/pypy/objspace/std/test/test_memoryobject.py
--- a/pypy/objspace/std/test/test_memoryobject.py
+++ b/pypy/objspace/std/test/test_memoryobject.py
@@ -376,7 +376,7 @@
return MockBuffer(space, self.w_list, self.w_dim, self.w_fmt, \
self.w_size, self.w_strides, self.w_shape)
-W_MockArray.typedef = TypeDef("MockArray",
+W_MockArray.typedef = TypeDef("MockArray", None, None, "read-write",
__new__ = interp2app(W_MockArray.descr_new),
)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit