[pypy-commit] pypy refactor-buffer-api: move buffer to rpython
bdkearns
noreply at buildbot.pypy.org
Thu Apr 24 01:47:38 CEST 2014
Author: Brian Kearns <bdkearns at gmail.com>
Branch: refactor-buffer-api
Changeset: r70905:a0c9719c5500
Date: 2014-04-23 19:41 -0400
http://bitbucket.org/pypy/pypy/changeset/a0c9719c5500/
Log: move buffer to rpython
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,7 +2,7 @@
# A convenient read-write buffer. Located here for want of a better place.
#
-from pypy.interpreter.buffer import Buffer
+from rpython.rlib.buffer import Buffer
from pypy.interpreter.gateway import unwrap_spec
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
@@ -1,10 +1,10 @@
-from pypy.interpreter.buffer import Buffer
from pypy.interpreter.error import oefmt
from pypy.interpreter.gateway import unwrap_spec, interp2app
from pypy.interpreter.typedef import TypeDef, make_weakref_descr
from pypy.module._cffi_backend import cdataobj, ctypeptr, ctypearray
from pypy.objspace.std.bufferobject import W_Buffer
+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
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
@@ -4,7 +4,7 @@
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 Buffer
+from rpython.rlib.buffer import Buffer
from rpython.rlib.rstring import StringBuilder
from rpython.rlib.rarithmetic import r_longlong, intmask
from rpython.rlib import rposix
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,4 +1,4 @@
-from pypy.interpreter.buffer import Buffer
+from rpython.rlib.buffer import Buffer
# XXX not the most efficient implementation
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
@@ -1,6 +1,7 @@
from __future__ import with_statement
from rpython.rlib import jit
+from rpython.rlib.buffer import Buffer
from rpython.rlib.objectmodel import keepalive_until_here
from rpython.rlib.rarithmetic import ovfcheck, widen
from rpython.rlib.unroll import unrolling_iterable
@@ -9,7 +10,6 @@
from rpython.rtyper.lltypesystem.rstr import copy_string_to_raw
from pypy.interpreter.baseobjspace import W_Root
-from pypy.interpreter.buffer import Buffer
from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.gateway import (
interp2app, interpindirect2app, unwrap_spec)
diff --git a/pypy/module/cpyext/bufferobject.py b/pypy/module/cpyext/bufferobject.py
--- a/pypy/module/cpyext/bufferobject.py
+++ b/pypy/module/cpyext/bufferobject.py
@@ -1,5 +1,5 @@
+from rpython.rlib.buffer import StringBuffer, SubBuffer
from rpython.rtyper.lltypesystem import rffi, lltype
-from pypy.interpreter.buffer import StringBuffer, SubBuffer
from pypy.interpreter.error import OperationError
from pypy.module.cpyext.api import (
cpython_api, Py_ssize_t, cpython_struct, bootstrap_function,
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
@@ -15,8 +15,8 @@
from pypy.module.cpyext.pyerrors import PyErr_Occurred
from pypy.module.cpyext.state import State
from pypy.interpreter.error import OperationError, oefmt
-from pypy.interpreter.buffer import Buffer
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
from rpython.tool.sourcetools import func_renamer
diff --git a/pypy/module/micronumpy/concrete.py b/pypy/module/micronumpy/concrete.py
--- a/pypy/module/micronumpy/concrete.py
+++ b/pypy/module/micronumpy/concrete.py
@@ -1,6 +1,6 @@
-from pypy.interpreter.buffer import Buffer
from pypy.interpreter.error import OperationError, oefmt
from rpython.rlib import jit
+from rpython.rlib.buffer import Buffer
from rpython.rlib.debug import make_sure_not_resized
from rpython.rlib.rawstorage import alloc_raw_storage, free_raw_storage, \
raw_storage_getitem, raw_storage_setitem, RAW_STORAGE
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,8 +2,8 @@
from pypy.interpreter.baseobjspace import W_Root
from pypy.interpreter.typedef import TypeDef
from pypy.interpreter.gateway import interp2app, unwrap_spec
-from pypy.interpreter.buffer import Buffer
from rpython.rlib import rmmap, rarithmetic
+from rpython.rlib.buffer import Buffer
from rpython.rlib.rmmap import RValueError, RTypeError, RMMapError
if rmmap.HAVE_LARGEFILE_SUPPORT:
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
@@ -1,10 +1,10 @@
from rpython.annotator.model import SomeInstance, s_None
from pypy.interpreter import argument, gateway
from pypy.interpreter.baseobjspace import W_Root, ObjSpace, SpaceCache
-from pypy.interpreter.buffer import Buffer
from pypy.interpreter.typedef import TypeDef, GetSetProperty
from pypy.objspace.std.stdtypedef import StdTypeDef
from pypy.objspace.std.sliceobject import W_SliceObject
+from rpython.rlib.buffer import Buffer
from rpython.rlib.objectmodel import instantiate, we_are_translated, specialize
from rpython.rlib.nonconst import NonConstant
from rpython.rlib.rarithmetic import r_uint, r_singlefloat
diff --git a/pypy/objspace/std/bufferobject.py b/pypy/objspace/std/bufferobject.py
--- a/pypy/objspace/std/bufferobject.py
+++ b/pypy/objspace/std/bufferobject.py
@@ -3,7 +3,7 @@
"""
import operator
-from pypy.interpreter import buffer
+from rpython.rlib.buffer import Buffer, StringBuffer, SubBuffer
from pypy.interpreter.baseobjspace import W_Root
from pypy.interpreter.error import OperationError
from pypy.interpreter.gateway import interp2app, unwrap_spec
@@ -19,7 +19,7 @@
"""
def __init__(self, buf):
- assert isinstance(buf, buffer.Buffer)
+ assert isinstance(buf, Buffer)
self.buf = buf
def buffer_w(self, space, flags):
@@ -45,7 +45,6 @@
builder = StringBuilder(len(unistr) * UNICODE_SIZE)
for unich in unistr:
pack_unichar(unich, builder)
- from pypy.interpreter.buffer import StringBuffer
buf = StringBuffer(builder.build())
else:
buf = space.readbuf_w(w_object)
@@ -59,7 +58,7 @@
if size < -1:
raise OperationError(space.w_ValueError,
space.wrap("size must be zero or positive"))
- buf = buffer.SubBuffer(buf, offset, size)
+ buf = SubBuffer(buf, offset, size)
return W_Buffer(buf)
def descr_len(self, space):
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
@@ -2,10 +2,10 @@
from rpython.rlib.objectmodel import (
import_from_mixin, newlist_hint, resizelist_hint)
+from rpython.rlib.buffer import Buffer
from rpython.rlib.rstring import StringBuilder
from pypy.interpreter.baseobjspace import W_Root
-from pypy.interpreter.buffer import Buffer
from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.gateway import WrappedDefault, interp2app, unwrap_spec
from pypy.interpreter.signature import Signature
diff --git a/pypy/objspace/std/bytesobject.py b/pypy/objspace/std/bytesobject.py
--- a/pypy/objspace/std/bytesobject.py
+++ b/pypy/objspace/std/bytesobject.py
@@ -3,10 +3,10 @@
from rpython.rlib.jit import we_are_jitted
from rpython.rlib.objectmodel import (
compute_hash, compute_unique_id, import_from_mixin)
+from rpython.rlib.buffer import StringBuffer
from rpython.rlib.rstring import StringBuilder, replace
from pypy.interpreter.baseobjspace import W_Root
-from pypy.interpreter.buffer import StringBuffer
from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.gateway import (
WrappedDefault, interp2app, interpindirect2app, unwrap_spec)
diff --git a/pypy/objspace/std/memoryobject.py b/pypy/objspace/std/memoryobject.py
--- a/pypy/objspace/std/memoryobject.py
+++ b/pypy/objspace/std/memoryobject.py
@@ -3,7 +3,7 @@
"""
import operator
-from pypy.interpreter import buffer
+from rpython.rlib.buffer import Buffer, SubBuffer
from pypy.interpreter.baseobjspace import W_Root
from pypy.interpreter.error import OperationError
from pypy.interpreter.gateway import interp2app, unwrap_spec
@@ -35,7 +35,7 @@
"""
def __init__(self, buf):
- assert isinstance(buf, buffer.Buffer)
+ assert isinstance(buf, Buffer)
self.buf = buf
def buffer_w(self, space, flags):
@@ -85,7 +85,7 @@
size = stop - start
if size < 0:
size = 0
- buf = buffer.SubBuffer(self.buf, start, size)
+ buf = SubBuffer(self.buf, start, size)
return W_MemoryView(buf)
def descr_tobytes(self, space):
diff --git a/pypy/interpreter/buffer.py b/rpython/rlib/buffer.py
rename from pypy/interpreter/buffer.py
rename to rpython/rlib/buffer.py
diff --git a/pypy/interpreter/test/test_buffer.py b/rpython/rlib/test/test_buffer.py
rename from pypy/interpreter/test/test_buffer.py
rename to rpython/rlib/test/test_buffer.py
--- a/pypy/interpreter/test/test_buffer.py
+++ b/rpython/rlib/test/test_buffer.py
@@ -1,43 +1,9 @@
-import py
-from rpython.tool.udir import udir
+from rpython.rlib.buffer import *
-testdir = udir.ensure('test_buffer', dir=1)
-
-class TestBuffer:
- def test_buffer_w(self):
- space = self.space
- w_hello = space.wrap('hello world')
- buf = space.buffer_w(w_hello, space.BUF_SIMPLE)
- assert buf.getlength() == 11
- assert buf.as_str() == 'hello world'
- assert buf.getslice(1, 6, 1, 5) == 'ello '
- assert space.buffer_w(space.newbuffer(buf), space.BUF_SIMPLE) is buf
- assert space.bufferstr_w(w_hello) == 'hello world'
- assert space.bufferstr_w(space.newbuffer(space.buffer_w(w_hello, space.BUF_SIMPLE))) == 'hello world'
- space.raises_w(space.w_TypeError, space.buffer_w, space.wrap(5), space.BUF_SIMPLE)
-
- def test_file_write(self):
- space = self.space
- w_buffer = space.newbuffer(space.buffer_w(space.wrap('hello world'), space.BUF_SIMPLE))
- filename = str(testdir.join('test_file_write'))
- space.appexec([w_buffer, space.wrap(filename)], """(buffer, filename):
- f = open(filename, 'wb')
- f.write(buffer)
- f.close()
- """)
- f = open(filename, 'rb')
- data = f.read()
- f.close()
- assert data == 'hello world'
-
- def test_unicode(self):
- space = self.space
- s = space.bufferstr_w(space.wrap(u'hello'))
- assert type(s) is str
- assert s == 'hello'
- space.raises_w(space.w_UnicodeEncodeError,
- space.bufferstr_w, space.wrap(u'\xe9'))
-
-
-# Note: some app-level tests for buffer are in objspace/std/test/test_memoryview.py.
+def test_string_buffer():
+ buf = StringBuffer('hello world')
+ assert buf.getitem(4) == 'o'
+ assert buf.getlength() == 11
+ assert buf.getslice(1, 6, 1, 5) == 'ello '
+ assert buf.as_str() == 'hello world'
More information about the pypy-commit
mailing list