Author: Richard Plangger <[email protected]>
Branch: py3.5-memoryview
Changeset: r86686:1d9d5dc5f9bb
Date: 2016-08-29 13:48 +0200
http://bitbucket.org/pypy/pypy/changeset/1d9d5dc5f9bb/

Log:    new test, some more fixes after the merge

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
@@ -11,6 +11,7 @@
 from pypy.interpreter.gateway import interp2app
 from pypy.interpreter.typedef import TypeDef, GetSetProperty,  
make_weakref_descr
 from pypy.module.struct.formatiterator import UnpackFormatIterator, 
PackFormatIterator
+from pypy.objspace.std.bytesobject import getbytevalue
 from rpython.rlib.unroll import unrolling_iterable
 
 MEMORYVIEW_MAX_DIM = 64
@@ -149,12 +150,11 @@
         if dim >= self.getndim():
             bytecount = (stride * dimshape)
             count = bytecount // itemsize
-            return self._tolist(space, SubBuffer(buf, start, bytecount), 
count, fmt)
+            return self._tolist(space, buf, count, fmt)
         items = [None] * dimshape
 
         for i in range(dimshape):
-            bytecount = stride
-            item = self._tolist_rec(space, SubBuffer(buf, start, bytecount), 
start, idim+1, fmt)
+            item = self._tolist_rec(space, SubBuffer(buf, start, stride), 
start, idim+1, fmt)
             items[i] = item
             start += stride
 
@@ -223,7 +223,7 @@
 
         start, stop, step, size = space.decode_index4(w_index, 
self.getlength())
         # ^^^ for a non-slice index, this returns (index, 0, 0, 1)
-       itemsize = self.getitemsize()
+        itemsize = self.getitemsize()
         if itemsize > 1:
             start *= itemsize
             size *= itemsize
@@ -239,13 +239,13 @@
                 return space.newint(ord(ch))
             else:
                 # TODO: this probably isn't very fast
-                buf = SubBuffer(self.buf, start * itemsize, itemsize)
+                buf = SubBuffer(self.buf, start, itemsize)
                 fmtiter = UnpackFormatIterator(space, buf)
                 fmtiter.interpret(self.format)
                 return fmtiter.result_w[0]
         elif step == 1:
             buf = SubBuffer(self.buf, start, size)
-            return W_MemoryView(buf, self.getformat(), self.itemsize)
+            return W_MemoryView(buf, self.getformat(), itemsize)
         else:
             # XXX needs to return a W_MemoryView with a NonContiguousSubBuffer
             # maybe?  Need to check the cpyext requirements for that
@@ -408,7 +408,6 @@
         return False
 
     def descr_cast(self, space, w_format, w_shape=None):
-        # XXX fixme. does not do anything near cpython (see memoryobjet.c 
memory_cast)
         self._check_released(space)
 
         if not space.isinstance_w(w_format, space.w_unicode):
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
@@ -4,6 +4,7 @@
 from pypy.interpreter.gateway import interp2app
 from pypy.interpreter.typedef import TypeDef
 from rpython.rlib.buffer import Buffer
+from pypy.conftest import option
 
 class AppTestMemoryView:
     spaceconfig = dict(usemodules=['array'])
@@ -273,9 +274,6 @@
     __new__ = interp2app(W_MockArray.descr_new),
 )
 
-from pypy.objspace.std.transparent import register_proxyable
-from pypy.conftest import option
-
 class AppTestMemoryViewMockBuffer(object):
     spaceconfig = dict(usemodules=[])
     def setup_class(cls):
@@ -352,3 +350,16 @@
         assert i32view.tolist() == [[1,2,3]]
         i32view = byteview.cast('i', shape=(1,3))
         assert i32view.tolist() == [[1,2,3]]
+
+    def test_cast_bytes(self):
+        bytes = b"\x02\x00\x03\x00\x04\x00" \
+                b"\x05\x00\x06\x00\x07\x00"
+        view = memoryview(bytes)
+        v = view.cast('h', shape=(3,2))
+        assert v.tolist() == [[2,3],[4,5],[6,7]]
+        try:
+            v = view.cast('h', shape=(3,3))
+            assert False, "shape is too big for bytes"
+        except TypeError:
+            pass
+
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to