Author: Ronan Lamy <ronan.l...@gmail.com> Branch: py3k Changeset: r87006:47b8ec8f4aa3 Date: 2016-09-11 20:03 +0100 http://bitbucket.org/pypy/pypy/changeset/47b8ec8f4aa3/
Log: Delete RPython impls of PyObject_CheckBuffer and PyObject_GetBuffer once again diff --git a/pypy/module/cpyext/buffer.py b/pypy/module/cpyext/buffer.py --- a/pypy/module/cpyext/buffer.py +++ b/pypy/module/cpyext/buffer.py @@ -4,17 +4,6 @@ cpython_api, CANNOT_FAIL, Py_TPFLAGS_HAVE_NEWBUFFER) from pypy.module.cpyext.pyobject import PyObject -@cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL) -def PyObject_CheckBuffer(space, pyobj): - """Return 1 if obj supports the buffer interface otherwise 0.""" - as_buffer = pyobj.c_ob_type.c_tp_as_buffer - flags = pyobj.c_ob_type.c_tp_flags - if (flags & Py_TPFLAGS_HAVE_NEWBUFFER and as_buffer.c_bf_getbuffer): - return 1 - return 0 - - - class CBuffer(buffer.Buffer): _immutable_ = True 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 @@ -11,36 +11,7 @@ from pypy.objspace.std.memoryobject import W_MemoryView PyMemoryView_Check, PyMemoryView_CheckExact = build_type_checkers("MemoryView", "w_memoryview") -@cpython_api([PyObject, lltype.Ptr(Py_buffer), rffi.INT_real], - rffi.INT_real, error=-1) -def PyObject_GetBuffer(space, w_obj, view, flags): - """Export obj into a Py_buffer, view. These arguments must - never be NULL. The flags argument is a bit field indicating what - kind of buffer the caller is prepared to deal with and therefore what - kind of buffer the exporter is allowed to return. The buffer interface - allows for complicated memory sharing possibilities, but some caller may - not be able to handle all the complexity but may want to see if the - exporter will let them take a simpler view to its memory. - - Some exporters may not be able to share memory in every possible way and - may need to raise errors to signal to some consumers that something is - just not possible. These errors should be a BufferError unless - there is another error that is actually causing the problem. The - exporter can use flags information to simplify how much of the - Py_buffer structure is filled in with non-default values and/or - raise an error if the object can't support a simpler view of its memory. - - 0 is returned on success and -1 on error.""" - flags = widen(flags) - buf = space.buffer_w(w_obj, flags) - try: - view.c_buf = rffi.cast(rffi.VOIDP, buf.get_raw_address()) - except ValueError: - raise BufferError("could not create buffer from object") - return fill_Py_buffer(space, w_obj, view, flags) - view.c_obj = make_ref(space, w_obj) - -def fill_Py_buffer(space, buf, view): +def fill_Py_buffer(space, buf, view): # c_buf, c_obj have been filled in ndim = buf.getndim() view.c_len = buf.getlength() @@ -61,7 +32,7 @@ view.c_format[i] = '*' else: view.c_format[i] = fmt[i] - view.c_format[n] = '\x00' + view.c_format[n] = '\x00' shape = buf.getshape() strides = buf.getstrides() for i in range(ndim): @@ -156,7 +127,7 @@ view.c_obj = make_ref(space, w_s) rffi.setintfield(view, 'c_readonly', 1) isstr = True - fill_Py_buffer(space, w_obj.buf, view) + fill_Py_buffer(space, w_obj.buf, view) return view @cpython_api([lltype.Ptr(Py_buffer)], PyObject) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit