Author: Ronan Lamy <[email protected]>
Branch: 
Changeset: r89770:f475e5872e53
Date: 2017-01-25 21:41 +0200
http://bitbucket.org/pypy/pypy/changeset/f475e5872e53/

Log:    Reimplement PyMemoryView_GET_BUFFER and PyMemoryView_GET_BASE as
        macros

diff --git a/pypy/module/cpyext/include/memoryobject.h 
b/pypy/module/cpyext/include/memoryobject.h
--- a/pypy/module/cpyext/include/memoryobject.h
+++ b/pypy/module/cpyext/include/memoryobject.h
@@ -14,6 +14,10 @@
 } PyMemoryViewObject;
 
 
+/* Get a pointer to the memoryview's private copy of the exporter's buffer. */
+#define PyMemoryView_GET_BUFFER(op) (&((PyMemoryViewObject *)(op))->view)
+/* Get a pointer to the exporting object (this may be NULL!). */
+#define PyMemoryView_GET_BASE(op) (((PyMemoryViewObject *)(op))->view.obj)
 
 
 #ifdef __cplusplus
diff --git a/pypy/module/cpyext/memoryobject.py 
b/pypy/module/cpyext/memoryobject.py
--- a/pypy/module/cpyext/memoryobject.py
+++ b/pypy/module/cpyext/memoryobject.py
@@ -128,15 +128,6 @@
     view.c_obj = make_ref(space, w_obj)
     return ret
 
-@cpython_api([PyObject], Py_bufferP, error=CANNOT_FAIL)
-def PyMemoryView_GET_BUFFER(space, pyobj):
-    """Return a pointer to the buffer-info structure wrapped by the given
-    object.  The object must be a memoryview instance; this macro doesn't
-    check its type, you must do it yourself or you will risk crashes."""
-    # XXX move to a c-macro
-    py_memobj = rffi.cast(PyMemoryViewObject, pyobj)
-    return py_memobj.c_view
-
 def fill_Py_buffer(space, buf, view):
     # c_buf, c_obj have been filled in
     ndim = buf.getndim()
@@ -269,9 +260,3 @@
     # XXX ignore suboffsets?
     return py_obj
 
-@cpython_api([PyObject], PyObject)
-def PyMemoryView_GET_BASE(space, w_obj):
-    # return the obj field of the Py_buffer created by PyMemoryView_GET_BUFFER
-    # XXX needed for numpy on py3k
-    raise NotImplementedError('PyMemoryView_GET_BASE')
-
diff --git a/pypy/module/cpyext/test/test_memoryobject.py 
b/pypy/module/cpyext/test/test_memoryobject.py
--- a/pypy/module/cpyext/test/test_memoryobject.py
+++ b/pypy/module/cpyext/test/test_memoryobject.py
@@ -5,6 +5,7 @@
 from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
 from rpython.rlib.buffer import StringBuffer
 from pypy.module.cpyext.pyobject import from_ref
+from pypy.module.cpyext.memoryobject import PyMemoryViewObject
 
 only_pypy ="config.option.runappdirect and '__pypy__' not in 
sys.builtin_module_names" 
 
@@ -20,8 +21,10 @@
 
     def test_frombuffer(self, space, api):
         w_buf = space.newbuffer(StringBuffer("hello"))
-        w_memoryview = from_ref(space, api.PyMemoryView_FromObject(w_buf))
-        view = api.PyMemoryView_GET_BUFFER(w_memoryview)
+        c_memoryview = rffi.cast(
+            PyMemoryViewObject, api.PyMemoryView_FromObject(w_buf))
+        w_memoryview = from_ref(space, c_memoryview)
+        view = c_memoryview.c_view
         assert view.c_ndim == 1
         f = rffi.charp2str(view.c_format)
         assert f == 'B'
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to