[pypy-commit] pypy py3.5: Reimplement PyMemoryView_GET_BUFFER and PyMemoryView_GET_BASE as macros
rlamy
pypy.commits at gmail.com
Wed Jan 25 14:06:11 EST 2017
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: py3.5
Changeset: r89769:25624675b30b
Date: 2017-01-25 19:05 +0000
http://bitbucket.org/pypy/pypy/changeset/25624675b30b/
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
@@ -118,15 +118,6 @@
"a bytes-like object is required, not '%T'", w_exporter)
return generic_cpy_call(space, pb.c_bf_getbuffer, exporter, view, flags)
- at 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()
@@ -259,9 +250,3 @@
py_mem.c_view.c_shape = view.c_shape
# XXX ignore suboffsets?
return py_obj
-
- at 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'
More information about the pypy-commit
mailing list