[pypy-commit] pypy issue2444: move code
mattip
pypy.commits at gmail.com
Mon Dec 26 13:32:42 EST 2016
Author: Matti Picus <matti.picus at gmail.com>
Branch: issue2444
Changeset: r89234:8ef3af61fe40
Date: 2016-12-25 23:10 +0200
http://bitbucket.org/pypy/pypy/changeset/8ef3af61fe40/
Log: move code
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
@@ -38,6 +38,30 @@
view.c_obj = make_ref(space, w_obj)
return ret
+ at 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."""
+ view = lltype.malloc(Py_buffer, flavor='raw', zero=True)
+ if not isinstance(w_obj, W_MemoryView):
+ return view
+ ndim = w_obj.buf.getndim()
+ if ndim >= Py_MAX_NDIMS:
+ # XXX warn?
+ return view
+ fill_Py_buffer(space, w_obj.buf, view)
+ try:
+ view.c_buf = rffi.cast(rffi.VOIDP, w_obj.buf.get_raw_address())
+ view.c_obj = make_ref(space, w_obj)
+ rffi.setintfield(view, 'c_readonly', w_obj.buf.readonly)
+ except ValueError:
+ w_s = w_obj.descr_tobytes(space)
+ view.c_obj = make_ref(space, w_s)
+ view.c_buf = rffi.cast(rffi.VOIDP, rffi.str2charp(space.str_w(w_s), track_allocation=False))
+ rffi.setintfield(view, 'c_readonly', 1)
+ return view
+
def fill_Py_buffer(space, buf, view):
# c_buf, c_obj have been filled in
ndim = buf.getndim()
@@ -149,29 +173,3 @@
# XXX needed for numpy on py3k
raise NotImplementedError('PyMemoryView_GET_BASE')
- at 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."""
- view = lltype.malloc(Py_buffer, flavor='raw', zero=True)
- if not isinstance(w_obj, W_MemoryView):
- return view
- ndim = w_obj.buf.getndim()
- if ndim >= Py_MAX_NDIMS:
- # XXX warn?
- return view
- fill_Py_buffer(space, w_obj.buf, view)
- try:
- view.c_buf = rffi.cast(rffi.VOIDP, w_obj.buf.get_raw_address())
- view.c_obj = make_ref(space, w_obj)
- rffi.setintfield(view, 'c_readonly', w_obj.buf.readonly)
- isstr = False
- except ValueError:
- w_s = w_obj.descr_tobytes(space)
- view.c_obj = make_ref(space, w_s)
- view.c_buf = rffi.cast(rffi.VOIDP, rffi.str2charp(space.str_w(w_s), track_allocation=False))
- rffi.setintfield(view, 'c_readonly', 1)
- isstr = True
- return view
-
More information about the pypy-commit
mailing list