diff options
author | Inada Naoki <songofacandy@gmail.com> | 2023-06-02 01:12:40 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-02 01:12:40 (GMT) |
commit | 37498fc95012ba8e147db646b841bc3d36ddf4af (patch) | |
tree | cd71e0d73e0eb7e013f12862593b909cd739014d /Objects | |
parent | ef300937c2a1b3ebe19c2835f3b46585825c1e1f (diff) | |
download | cpython-37498fc95012ba8e147db646b841bc3d36ddf4af.zip cpython-37498fc95012ba8e147db646b841bc3d36ddf4af.tar.gz cpython-37498fc95012ba8e147db646b841bc3d36ddf4af.tar.bz2 |
gh-85275: Remove old buffer APIs (#105137)
They are now abi-only.
Co-authored-by: Victor Stinner <vstinner@python.org>
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/abstract.c | 44 |
1 files changed, 35 insertions, 9 deletions
diff --git a/Objects/abstract.c b/Objects/abstract.c index e957859..00087bd 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -294,11 +294,17 @@ PyObject_CheckBuffer(PyObject *obj) return (tp_as_buffer != NULL && tp_as_buffer->bf_getbuffer != NULL); } +// Old buffer protocols (deprecated, abi only) -/* We release the buffer right after use of this function which could +/* Checks whether an arbitrary object supports the (character, single segment) + buffer interface. + + Returns 1 on success, 0 on failure. + + We release the buffer right after use of this function which could cause issues later on. Don't use these functions in new code. */ -int +PyAPI_FUNC(int) /* abi_only */ PyObject_CheckReadBuffer(PyObject *obj) { PyBufferProcs *pb = Py_TYPE(obj)->tp_as_buffer; @@ -333,7 +339,13 @@ as_read_buffer(PyObject *obj, const void **buffer, Py_ssize_t *buffer_len) return 0; } -int +/* Takes an arbitrary object which must support the (character, single segment) + buffer interface and returns a pointer to a read-only memory location + usable as character based input for subsequent processing. + + Return 0 on success. buffer and buffer_len are only set in case no error + occurs. Otherwise, -1 is returned and an exception set. */ +PyAPI_FUNC(int) /* abi_only */ PyObject_AsCharBuffer(PyObject *obj, const char **buffer, Py_ssize_t *buffer_len) @@ -341,16 +353,30 @@ PyObject_AsCharBuffer(PyObject *obj, return as_read_buffer(obj, (const void **)buffer, buffer_len); } -int PyObject_AsReadBuffer(PyObject *obj, - const void **buffer, - Py_ssize_t *buffer_len) +/* Same as PyObject_AsCharBuffer() except that this API expects (readable, + single segment) buffer interface and returns a pointer to a read-only memory + location which can contain arbitrary data. + + 0 is returned on success. buffer and buffer_len are only set in case no + error occurs. Otherwise, -1 is returned and an exception set. */ +PyAPI_FUNC(int) /* abi_only */ +PyObject_AsReadBuffer(PyObject *obj, + const void **buffer, + Py_ssize_t *buffer_len) { return as_read_buffer(obj, buffer, buffer_len); } -int PyObject_AsWriteBuffer(PyObject *obj, - void **buffer, - Py_ssize_t *buffer_len) +/* Takes an arbitrary object which must support the (writable, single segment) + buffer interface and returns a pointer to a writable memory location in + buffer of size 'buffer_len'. + + Return 0 on success. buffer and buffer_len are only set in case no error + occurs. Otherwise, -1 is returned and an exception set. */ +PyAPI_FUNC(int) /* abi_only */ +PyObject_AsWriteBuffer(PyObject *obj, + void **buffer, + Py_ssize_t *buffer_len) { PyBufferProcs *pb; Py_buffer view; |