[pypy-commit] pypy PyBuffer: Move ByteBuffer to pypy.interpreter.buffer
rlamy
pypy.commits at gmail.com
Sat Mar 25 11:50:32 EDT 2017
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: PyBuffer
Changeset: r90806:3c2915c596d5
Date: 2017-03-25 15:49 +0000
http://bitbucket.org/pypy/pypy/changeset/3c2915c596d5/
Log: Move ByteBuffer to pypy.interpreter.buffer
diff --git a/pypy/interpreter/buffer.py b/pypy/interpreter/buffer.py
--- a/pypy/interpreter/buffer.py
+++ b/pypy/interpreter/buffer.py
@@ -1,3 +1,4 @@
+from rpython.rlib.rgc import nonmoving_raw_ptr_for_resizable_list
class Buffer(object):
"""Abstract base class for buffers."""
@@ -73,6 +74,25 @@
def releasebuffer(self):
pass
+class ByteBuffer(Buffer):
+ _immutable_ = True
+
+ def __init__(self, len):
+ self.data = ['\x00'] * len
+ self.readonly = False
+
+ def getlength(self):
+ return len(self.data)
+
+ def getitem(self, index):
+ return self.data[index]
+
+ def setitem(self, index, char):
+ self.data[index] = char
+
+ def get_raw_address(self):
+ return nonmoving_raw_ptr_for_resizable_list(self.data)
+
class StringBuffer(Buffer):
_attrs_ = ['readonly', 'value']
_immutable_ = True
diff --git a/pypy/module/__pypy__/bytebuffer.py b/pypy/module/__pypy__/bytebuffer.py
--- a/pypy/module/__pypy__/bytebuffer.py
+++ b/pypy/module/__pypy__/bytebuffer.py
@@ -2,29 +2,8 @@
# A convenient read-write buffer. Located here for want of a better place.
#
-from pypy.interpreter.buffer import Buffer
+from pypy.interpreter.buffer import ByteBuffer
from pypy.interpreter.gateway import unwrap_spec
-from rpython.rlib.rgc import nonmoving_raw_ptr_for_resizable_list
-
-
-class ByteBuffer(Buffer):
- _immutable_ = True
-
- def __init__(self, len):
- self.data = ['\x00'] * len
- self.readonly = False
-
- def getlength(self):
- return len(self.data)
-
- def getitem(self, index):
- return self.data[index]
-
- def setitem(self, index, char):
- self.data[index] = char
-
- def get_raw_address(self):
- return nonmoving_raw_ptr_for_resizable_list(self.data)
@unwrap_spec(length=int)
def bytebuffer(space, length):
More information about the pypy-commit
mailing list