[pypy-commit] pypy buffer-interface2: fix for failing test which hit NotImplemented wrapper function
mattip
pypy.commits at gmail.com
Wed Oct 5 15:46:55 EDT 2016
Author: Matti Picus <matti.picus at gmail.com>
Branch: buffer-interface2
Changeset: r87605:f0b37baed36a
Date: 2016-10-05 22:45 +0300
http://bitbucket.org/pypy/pypy/changeset/f0b37baed36a/
Log: fix for failing test which hit NotImplemented wrapper function
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
@@ -113,12 +113,12 @@
@cpython_api([lltype.Ptr(Py_buffer), lltype.Char], rffi.INT_real, error=CANNOT_FAIL)
def PyBuffer_IsContiguous(space, view, fort):
- """Return 1 if the memory defined by the view is C-style (fortran is
- 'C') or Fortran-style (fortran is 'F') contiguous or either one
- (fortran is 'A'). Return 0 otherwise."""
+ """Return 1 if the memory defined by the view is C-style (fort is
+ 'C') or Fortran-style (fort is 'F') contiguous or either one
+ (fort is 'A'). Return 0 otherwise."""
# traverse the strides, checking for consistent stride increases from
# right-to-left (c) or left-to-right (fortran). Copied from cpython
- if not view.c_suboffsets:
+ if view.c_suboffsets:
return 0
if (fort == 'C'):
return _IsCContiguous(view)
diff --git a/pypy/module/cpyext/slotdefs.py b/pypy/module/cpyext/slotdefs.py
--- a/pypy/module/cpyext/slotdefs.py
+++ b/pypy/module/cpyext/slotdefs.py
@@ -15,6 +15,7 @@
readbufferproc, getbufferproc, ssizessizeobjargproc)
from pypy.module.cpyext.pyobject import from_ref, make_ref, Py_DecRef
from pypy.module.cpyext.pyerrors import PyErr_Occurred
+from pypy.module.cpyext.memoryobject import fill_Py_buffer
from pypy.module.cpyext.state import State
from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.argument import Arguments
@@ -621,13 +622,28 @@
@cpython_api([PyObject, Py_bufferP, rffi.INT_real],
rffi.INT_real, header=None, error=-1)
@func_renamer("cpyext_%s_%s" % (name.replace('.', '_'), typedef.name))
- def buff_w(space, w_self, pybuf, flags):
- # XXX this is wrong, needs a test
- raise oefmt(space.w_NotImplemented,
- "calling bf_getbuffer on a builtin type not supported yet")
- #args = Arguments(space, [w_self],
- # w_stararg=w_args, w_starstararg=w_kwds)
- #return space.call_args(space.get(buff_fn, w_self), args)
+ def buff_w(space, w_self, view, flags):
+ args = Arguments(space, [space.newint(flags)])
+ w_obj = space.call_args(space.get(buff_fn, w_self), args)
+ if view:
+ #from PyObject_GetBuffer
+ flags = widen(flags)
+ buf = space.buffer_w(w_obj, flags)
+ try:
+ view.c_buf = rffi.cast(rffi.VOIDP, buf.get_raw_address())
+ view.c_obj = make_ref(space, w_obj)
+ except ValueError:
+ if hasattr(buf, 'as_str'):
+ w_s = space.newbytes(buf.as_str())
+ else:
+ 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)
+ ret = fill_Py_buffer(space, buf, view)
+ return ret
+ return 0
api_func = buff_w.api_func
else:
# missing: tp_as_number.nb_nonzero, tp_as_number.nb_coerce
More information about the pypy-commit
mailing list