[pypy-commit] pypy newmemoryview-app-level: fix failing tests, document branch and new app-level functionality

mattip pypy.commits at gmail.com
Tue Mar 5 06:58:44 EST 2019


Author: Matti Picus <matti.picus at gmail.com>
Branch: newmemoryview-app-level
Changeset: r96209:e7f2a1847440
Date: 2019-03-05 13:58 +0200
http://bitbucket.org/pypy/pypy/changeset/e7f2a1847440/

Log:	fix failing tests, document branch and new app-level functionality

diff --git a/lib_pypy/_ctypes/array.py b/lib_pypy/_ctypes/array.py
--- a/lib_pypy/_ctypes/array.py
+++ b/lib_pypy/_ctypes/array.py
@@ -249,7 +249,7 @@
             shape.append(obj._length_)
             try:
                 obj[0]._length_
-            except AttributeError:
+            except (AttributeError, IndexError):
                 break
             obj = obj[0]
 
@@ -257,7 +257,7 @@
         try:
             itemsize = struct.calcsize(fmt[1:])
         except:
-            itemsize = len(memoryview(obj[0]))
+            itemsize = len(buffer(obj[0]))
         return __pypy__.newmemoryview(memoryview(self._buffer), itemsize, fmt, shape)
 
 ARRAY_CACHE = {}
diff --git a/pypy/doc/__pypy__-module.rst b/pypy/doc/__pypy__-module.rst
--- a/pypy/doc/__pypy__-module.rst
+++ b/pypy/doc/__pypy__-module.rst
@@ -18,8 +18,17 @@
  - ``bytebuffer(length)``: return a new read-write buffer of the given length.
    It works like a simplified array of characters (actually, depending on the
    configuration the ``array`` module internally uses this).
+
  - ``attach_gdb()``: start a GDB at the interpreter-level (or a PDB before translation).
 
+ - ``newmemoryview(buffer, itemsize, format, shape=None, strides=None)``:
+   create a `memoryview` instance with the data from ``buffer`` and the
+   specified itemsize, format, and optional shape and strides.
+
+ - ``bufferable``: a base class that must override the
+   ``__buffer__(self, flags)`` method. This method should return a memoryview
+   instance of the class instance. It is called by the C-API's ``tp_as_buffer.
+   bf_getbuffer``.
 
 Transparent Proxy Functionality
 -------------------------------
diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -37,3 +37,9 @@
 
 Use utf8 internally to represent unicode, with the goal of never using rpython-level unicode
 
+.. branch: newmemoryview
+
+Since _ctypes is implemented in pure python over libffi, add interfaces and
+methods to support the buffer interface from python. Specifically, add a
+``__pypy__.newmemoryview`` function to create a memoryview and extend the use
+of the PyPy-specific ``__buffer__`` class method.


More information about the pypy-commit mailing list