[pypy-commit] pypy py3.5-memoryview: started to implement tuple indexing and finishing cast of memoryview, much more changes are needed to implement that
plan_rich
pypy.commits at gmail.com
Thu Aug 18 04:22:24 EDT 2016
Author: Richard Plangger <planrichi at gmail.com>
Branch: py3.5-memoryview
Changeset: r86260:a25cfe739e3f
Date: 2016-08-17 11:08 +0200
http://bitbucket.org/pypy/pypy/changeset/a25cfe739e3f/
Log: started to implement tuple indexing and finishing cast of
memoryview, much more changes are needed to implement that
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -1428,6 +1428,7 @@
BUF_SIMPLE = 0x0000
BUF_WRITABLE = 0x0001
+ BUF_C = 0x0002
BUF_FORMAT = 0x0004
BUF_ND = 0x0008
BUF_STRIDES = 0x0010 | BUF_ND
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
@@ -12,7 +12,6 @@
from pypy.interpreter.typedef import TypeDef, GetSetProperty, make_weakref_descr
from pypy.module.struct.formatiterator import UnpackFormatIterator, PackFormatIterator
-
class W_MemoryView(W_Root):
"""Implement the built-in 'memoryview' type as a wrapper around
an interp-level buffer.
@@ -24,6 +23,7 @@
self._hash = -1
self.format = format
self.itemsize = itemsize
+ self.flags = 0
def buffer_w_ex(self, space, flags):
self._check_released(space)
@@ -226,8 +226,18 @@
return size
def descr_cast(self, space, w_format, w_shape=None):
+ self._check_released(space)
+
+ if not space.isinstance_w(w_obj, space.w_unicode):
+ raise OperationError(space.w_TypeError, \
+ space.wrap("memoryview: format argument must be a string"))
+
# XXX fixme. does not do anything near cpython (see memoryobjet.c memory_cast)
- self._check_released(space)
+ #if self.flags & (space.BUF_CONTIG_RO|space.BUF_C) == 0:
+ # raise OperationError(space.w_TypeError, \
+ # space.wrap("memoryview: casts are restricted" \
+ # " to C-contiguous views"))
+
fmt = space.str_w(w_format)
newitemsize = self.get_native_fmtchar(fmt)
return W_MemoryView(self.buf, fmt, newitemsize)
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
@@ -165,3 +165,8 @@
def test_hex(self):
assert memoryview(b"abc").hex() == u'616263'
+
+ @py.test.skip("needs numpy ndarray")
+ def test_tuple_indexing(self):
+ content = ndarray(list(range(12)))
+ assert memoryview(content)[0,0] == 0
More information about the pypy-commit
mailing list