Author: Ronan Lamy <[email protected]>
Branch: PyBuffer
Changeset: r91128:462160738ca6
Date: 2017-04-25 18:57 +0100
http://bitbucket.org/pypy/pypy/changeset/462160738ca6/
Log: import rpython.rlib.buffer objects directly; remove 'BinaryBuffer'
alias
diff --git a/pypy/interpreter/buffer.py b/pypy/interpreter/buffer.py
--- a/pypy/interpreter/buffer.py
+++ b/pypy/interpreter/buffer.py
@@ -1,6 +1,5 @@
from rpython.rlib.rstruct.error import StructError
-from rpython.rlib.buffer import Buffer as BinaryBuffer
-from rpython.rlib.buffer import StringBuffer, ByteBuffer, SubBuffer
+from rpython.rlib.buffer import StringBuffer, SubBuffer
from pypy.interpreter.error import oefmt
@@ -42,7 +41,7 @@
return StringBuffer(self.as_str())
def as_binary_rw(self):
- """Return a writable BinaryBuffer sharing the same data as `self`."""
+ """Return a writable Buffer sharing the same data as `self`."""
raise BufferInterfaceNotFound
def getformat(self):
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
@@ -4,14 +4,15 @@
from pypy.interpreter.typedef import TypeDef, make_weakref_descr
from pypy.module._cffi_backend import cdataobj, ctypeptr, ctypearray
from pypy.module._cffi_backend import ctypestruct
+from pypy.interpreter.buffer import SimpleView
-from pypy.interpreter.buffer import SimpleView, BinaryBuffer
+from rpython.rlib.buffer import Buffer
from rpython.rtyper.annlowlevel import llstr
from rpython.rtyper.lltypesystem import rffi
from rpython.rtyper.lltypesystem.rstr import copy_string_to_raw
-class LLBuffer(BinaryBuffer):
+class LLBuffer(Buffer):
_immutable_ = True
def __init__(self, raw_cdata, size):
@@ -34,7 +35,7 @@
def getslice(self, start, stop, step, size):
if step == 1:
return rffi.charpsize2str(rffi.ptradd(self.raw_cdata, start), size)
- return BinaryBuffer.getslice(self, start, stop, step, size)
+ return Buffer.getslice(self, start, stop, step, size)
def setslice(self, start, string):
raw_cdata = rffi.ptradd(self.raw_cdata, start)
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
@@ -7,7 +7,9 @@
from pypy.interpreter.typedef import (
TypeDef, GetSetProperty, generic_new_descr, interp_attrproperty_w)
from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault
-from pypy.interpreter.buffer import SimpleView, BinaryBuffer, SubBuffer
+from pypy.interpreter.buffer import SimpleView
+
+from rpython.rlib.buffer import Buffer, SubBuffer
from rpython.rlib.rgc import (
nonmoving_raw_ptr_for_resizable_list, resizable_list_supporting_raw_ptr)
from rpython.rlib.rstring import StringBuilder
@@ -158,7 +160,7 @@
readinto1 = interp2app(W_BufferedIOBase.readinto1_w),
)
-class RawBuffer(BinaryBuffer):
+class RawBuffer(Buffer):
_immutable_ = True
def __init__(self, n):
diff --git a/pypy/module/_io/interp_bytesio.py
b/pypy/module/_io/interp_bytesio.py
--- a/pypy/module/_io/interp_bytesio.py
+++ b/pypy/module/_io/interp_bytesio.py
@@ -2,7 +2,8 @@
from pypy.interpreter.typedef import (
TypeDef, generic_new_descr, GetSetProperty)
from pypy.interpreter.gateway import interp2app, unwrap_spec
-from pypy.interpreter.buffer import SimpleView, BinaryBuffer
+from pypy.interpreter.buffer import SimpleView
+from rpython.rlib.buffer import Buffer
from rpython.rlib.rStringIO import RStringIO
from rpython.rlib.rarithmetic import r_longlong
from rpython.rlib.objectmodel import import_from_mixin
@@ -11,7 +12,7 @@
import sys
-class BytesIOBuffer(BinaryBuffer):
+class BytesIOBuffer(Buffer):
_immutable_ = True
def __init__(self, w_bytesio):
diff --git a/pypy/module/_rawffi/buffer.py b/pypy/module/_rawffi/buffer.py
--- a/pypy/module/_rawffi/buffer.py
+++ b/pypy/module/_rawffi/buffer.py
@@ -1,11 +1,11 @@
from rpython.rtyper.lltypesystem import rffi
-from pypy.interpreter.buffer import BinaryBuffer
+from rpython.rlib.buffer import Buffer
# XXX not the most efficient implementation
-class RawFFIBuffer(BinaryBuffer):
+class RawFFIBuffer(Buffer):
_immutable_ = True
def __init__(self, datainstance):
@@ -15,22 +15,6 @@
def getlength(self):
return self.datainstance.getrawsize()
- def getformat(self):
- return self.datainstance.fmt
-
- #XXX we keep the default of 1 for now. I *think* it does not make
- # sense to give another answer here without also tweaking the
- # 'shape' and 'strides'. At least it makes memoryobject.py think the
- # buffer is not C-contiguous, which is nonsense (e.g. cast() are
- # refused). Now, the memoryview we get from a ctypes object is the
- # one that would correspond to an array of chars of the same
- # size---which is wrong, because ctypes gives a more complicated
- # result on CPython (at least 3.5), but at least it corresponds to
- # the basics. (For example, CPython 3.5 gives a zero-dimensional
- # memoryview if the ctypes type is not an array.)
- #def getitemsize(self):
- # return self.datainstance.itemsize
-
def getitem(self, index):
ll_buffer = self.datainstance.ll_buffer
return ll_buffer[index]
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
@@ -5,8 +5,9 @@
from rpython.rtyper.annlowlevel import llstr
from rpython.rtyper.lltypesystem import lltype, rffi
from rpython.rtyper.lltypesystem.rstr import copy_string_to_raw
+from rpython.rlib.buffer import Buffer
-from pypy.interpreter.buffer import BufferView, BinaryBuffer
+from pypy.interpreter.buffer import BufferView
from pypy.interpreter.baseobjspace import W_Root
from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.gateway import (
@@ -845,7 +846,7 @@
v.typecode = k
unroll_typecodes = unrolling_iterable(types.keys())
-class ArrayData(BinaryBuffer):
+class ArrayData(Buffer):
_immutable_ = True
readonly = False
def __init__(self, w_array):
diff --git a/pypy/module/cpyext/slotdefs.py b/pypy/module/cpyext/slotdefs.py
--- a/pypy/module/cpyext/slotdefs.py
+++ b/pypy/module/cpyext/slotdefs.py
@@ -19,9 +19,11 @@
from pypy.module.cpyext.memoryobject import fill_Py_buffer
from pypy.module.cpyext.state import State
from pypy.module.cpyext import userslot
-from pypy.interpreter.buffer import BufferView, BinaryBuffer
+from pypy.interpreter.buffer import BufferView
from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.argument import Arguments
+
+from rpython.rlib.buffer import Buffer
from rpython.rlib.unroll import unrolling_iterable
from rpython.rlib.objectmodel import specialize, not_rpython
from rpython.tool.sourcetools import func_renamer
@@ -425,7 +427,7 @@
fq = FQ()
-class CBuffer(BinaryBuffer):
+class CBuffer(Buffer):
_immutable_ = True
def __init__(self, view):
self.view = view
diff --git a/pypy/module/mmap/interp_mmap.py b/pypy/module/mmap/interp_mmap.py
--- a/pypy/module/mmap/interp_mmap.py
+++ b/pypy/module/mmap/interp_mmap.py
@@ -2,7 +2,9 @@
from pypy.interpreter.baseobjspace import W_Root
from pypy.interpreter.typedef import TypeDef, GetSetProperty,
make_weakref_descr
from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault
-from pypy.interpreter.buffer import BinaryBuffer, SimpleView
+from pypy.interpreter.buffer import SimpleView
+
+from rpython.rlib.buffer import Buffer
from rpython.rlib import rmmap, rarithmetic, objectmodel
from rpython.rlib.rmmap import RValueError, RTypeError, RMMapError
from rpython.rlib.rstring import StringBuilder
@@ -307,7 +309,7 @@
return OperationError(space.w_SystemError, space.newtext('%s' % e))
-class MMapBuffer(BinaryBuffer):
+class MMapBuffer(Buffer):
_immutable_ = True
def __init__(self, space, mmap, readonly):
@@ -327,7 +329,7 @@
if step == 1:
return self.mmap.getslice(start, size)
else:
- return BinaryBuffer.getslice(self, start, stop, step, size)
+ return Buffer.getslice(self, start, stop, step, size)
def setitem(self, index, char):
self.check_valid_writeable()
diff --git a/pypy/objspace/std/bytearrayobject.py
b/pypy/objspace/std/bytearrayobject.py
--- a/pypy/objspace/std/bytearrayobject.py
+++ b/pypy/objspace/std/bytearrayobject.py
@@ -10,13 +10,14 @@
from rpython.rlib.rgc import (resizable_list_supporting_raw_ptr,
nonmoving_raw_ptr_for_resizable_list)
from rpython.rlib import jit
+from rpython.rlib.buffer import Buffer
from pypy.interpreter.baseobjspace import W_Root
from pypy.interpreter.error import OperationError, oefmt
from pypy.objspace.std.bytesobject import makebytesdata_w, newbytesdata_w
from pypy.interpreter.gateway import WrappedDefault, interp2app, unwrap_spec
from pypy.interpreter.typedef import TypeDef
-from pypy.interpreter.buffer import SimpleView, BinaryBuffer
+from pypy.interpreter.buffer import SimpleView
from pypy.objspace.std.sliceobject import W_SliceObject, unwrap_start_stop
from pypy.objspace.std.stringmethods import StringMethods, _get_buffer
from pypy.objspace.std.stringmethods import _descr_getslice_slowpath
@@ -1274,7 +1275,7 @@
start += step
-class BytearrayBuffer(BinaryBuffer):
+class BytearrayBuffer(Buffer):
_immutable_ = True
readonly = False
@@ -1304,7 +1305,7 @@
if start != 0 or stop != len(data):
data = data[start:stop]
return "".join(data)
- return BinaryBuffer.getslice(self, start, stop, step, size)
+ return Buffer.getslice(self, start, stop, step, size)
def setslice(self, start, string):
# No bounds checks.
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit