Author: mattip <matti.pi...@gmail.com>
Branch: cpyext-ext
Changeset: r83441:f52a0d372df2
Date: 2016-03-30 20:09 +0300
http://bitbucket.org/pypy/pypy/changeset/f52a0d372df2/

Log:    cannot raise NotImplemented on a CANNOT_FAIL function that returns a
        pointer

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
@@ -1,4 +1,5 @@
-from pypy.module.cpyext.api import cpython_api, Py_buffer, build_type_checkers
+from pypy.module.cpyext.api import (cpython_api, Py_buffer, CANNOT_FAIL,
+                                    build_type_checkers)
 from pypy.module.cpyext.pyobject import PyObject
 from rpython.rtyper.lltypesystem import lltype
 
@@ -13,11 +14,27 @@
     # return the obj field of the Py_buffer created by PyMemoryView_GET_BUFFER
     raise NotImplementedError
 
-@cpython_api([PyObject], lltype.Ptr(Py_buffer))
-def PyMemoryView_GET_BUFFER(space, obj):
+@cpython_api([PyObject], lltype.Ptr(Py_buffer), error=CANNOT_FAIL)
+def PyMemoryView_GET_BUFFER(space, w_obj):
     """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."""
-    raise NotImplementedError
+    view = lltype.malloc(Py_buffer, flavor='raw', zero=True)
+    # TODO - fill in fields
+    '''
+    view.c_buf = buf
+    view.c_len = length
+    view.c_obj = obj
+    Py_IncRef(space, obj)
+    view.c_itemsize = 1
+    rffi.setintfield(view, 'c_readonly', readonly)
+    rffi.setintfield(view, 'c_ndim', 0)
+    view.c_format = lltype.nullptr(rffi.CCHARP.TO)
+    view.c_shape = lltype.nullptr(Py_ssize_tP.TO)
+    view.c_strides = lltype.nullptr(Py_ssize_tP.TO)
+    view.c_suboffsets = lltype.nullptr(Py_ssize_tP.TO)
+    view.c_internal = lltype.nullptr(rffi.VOIDP.TO)
+    ''' 
+    return view
 
 
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to