Author: Ronan Lamy <ronan.l...@gmail.com>
Branch: PyBuffer
Changeset: r91142:0db5e3751f7b
Date: 2017-04-27 18:24 +0100
http://bitbucket.org/pypy/pypy/changeset/0db5e3751f7b/

Log:    Merge RawBuffer and ByteBuffer

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
@@ -9,9 +9,7 @@
 from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault
 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.buffer import ByteBuffer, SubBuffer
 from rpython.rlib.rstring import StringBuilder
 from rpython.rlib.rarithmetic import r_longlong, intmask
 from rpython.rlib import rposix
@@ -160,26 +158,6 @@
     readinto1 = interp2app(W_BufferedIOBase.readinto1_w),
 )
 
-class RawBuffer(Buffer):
-    _immutable_ = True
-
-    def __init__(self, n):
-        self.length = n
-        self.buf = resizable_list_supporting_raw_ptr(['\0'] * n)
-        self.readonly = False
-
-    def getlength(self):
-        return self.length
-
-    def getitem(self, index):
-        return self.buf[index]
-
-    def setitem(self, index, char):
-        self.buf[index] = char
-
-    def get_raw_address(self):
-        return nonmoving_raw_ptr_for_resizable_list(self.buf)
-
 class BufferedMixin:
     _mixin_ = True
 
@@ -218,7 +196,7 @@
             raise oefmt(space.w_ValueError,
                         "buffer size must be strictly positive")
 
-        self.buffer = RawBuffer(self.buffer_size)
+        self.buffer = ByteBuffer(self.buffer_size)
 
         self.lock = TryLock(space)
 
@@ -626,7 +604,7 @@
         if n <= current_size:
             return self._read_fast(n)
 
-        result_buffer = RawBuffer(n)
+        result_buffer = ByteBuffer(n)
         remaining = n
         written = 0
         if current_size:
@@ -742,8 +720,8 @@
                 pos = 0
                 found = False
                 while pos < have:
-                    # 'buffer.buf[]' instead of 'buffer[]' because RPython...
-                    c = self.buffer.buf[pos]
+                    # 'buffer.data[]' instead of 'buffer[]' because RPython...
+                    c = self.buffer.data[pos]
                     pos += 1
                     if c == '\n':
                         self.pos = pos
@@ -802,7 +780,7 @@
                 # Make some place by shifting the buffer
                 for i in range(self.write_pos, self.write_end):
                     # XXX: messing with buffer internals
-                    self.buffer.buf[i - self.write_pos] = self.buffer.buf[i]
+                    self.buffer.data[i - self.write_pos] = self.buffer.data[i]
                 self.write_end -= self.write_pos
                 self.raw_pos -= self.write_pos
                 newpos = self.pos - self.write_pos
diff --git a/rpython/rlib/buffer.py b/rpython/rlib/buffer.py
--- a/rpython/rlib/buffer.py
+++ b/rpython/rlib/buffer.py
@@ -1,7 +1,8 @@
 """
 Buffer protocol support.
 """
-from rpython.rlib.rgc import nonmoving_raw_ptr_for_resizable_list
+from rpython.rlib.rgc import (
+    nonmoving_raw_ptr_for_resizable_list, resizable_list_supporting_raw_ptr)
 from rpython.rlib.signature import signature
 from rpython.rlib import types
 
@@ -62,8 +63,8 @@
 class ByteBuffer(Buffer):
     _immutable_ = True
 
-    def __init__(self, len):
-        self.data = ['\x00'] * len
+    def __init__(self, n):
+        self.data = resizable_list_supporting_raw_ptr(['\0'] * n)
         self.readonly = False
 
     def getlength(self):
@@ -117,7 +118,8 @@
     _attrs_ = ['buffer', 'offset', 'size', 'readonly']
     _immutable_ = True
 
-    @signature(types.any(), types.instance(Buffer), types.int(), types.int(), 
returns=types.none())
+    @signature(types.any(), types.instance(Buffer), types.int(), types.int(),
+               returns=types.none())
     def __init__(self, buffer, offset, size):
         self.readonly = buffer.readonly
         if isinstance(buffer, SubBuffer):     # don't nest them
diff --git a/rpython/rlib/rstring.py b/rpython/rlib/rstring.py
--- a/rpython/rlib/rstring.py
+++ b/rpython/rlib/rstring.py
@@ -8,7 +8,6 @@
 from rpython.rlib import jit
 from rpython.rlib.objectmodel import newlist_hint, resizelist_hint, 
specialize, not_rpython
 from rpython.rlib.rarithmetic import ovfcheck, LONG_BIT as BLOOM_WIDTH
-from rpython.rlib.buffer import Buffer
 from rpython.rlib.unicodedata import unicodedb_5_2_0 as unicodedb
 from rpython.rtyper.extregistry import ExtRegistryEntry
 from rpython.tool.pairtype import pairtype
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to