Skip to content

Commit 6f8a6ee

Browse files
authored
bpo-41103: Remove old buffer protocol support (#21117)
They are deprecated since Python 3.0.
1 parent 77ed29b commit 6f8a6ee

File tree

8 files changed

+9
-204
lines changed

8 files changed

+9
-204
lines changed

Doc/c-api/abstract.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,3 @@ but whose items have not been set to some non-\ ``NULL`` value yet.
2424
mapping.rst
2525
iter.rst
2626
buffer.rst
27-
objbuffer.rst

Doc/c-api/objbuffer.rst

Lines changed: 0 additions & 55 deletions
This file was deleted.

Doc/data/refcounts.dat

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,21 +1568,6 @@ PyOS_FSPath:PyObject*:path:0:
15681568
PyObject_ASCII:PyObject*::+1:
15691569
PyObject_ASCII:PyObject*:o:0:
15701570

1571-
PyObject_AsCharBuffer:int:::
1572-
PyObject_AsCharBuffer:PyObject*:obj:0:
1573-
PyObject_AsCharBuffer:const char**:buffer::
1574-
PyObject_AsCharBuffer:Py_ssize_t*:buffer_len::
1575-
1576-
PyObject_AsReadBuffer:int:::
1577-
PyObject_AsReadBuffer:PyObject*:obj:0:
1578-
PyObject_AsReadBuffer:const void**:buffer::
1579-
PyObject_AsReadBuffer:Py_ssize_t*:buffer_len::
1580-
1581-
PyObject_AsWriteBuffer:int:::
1582-
PyObject_AsWriteBuffer:PyObject*:obj:0:
1583-
PyObject_AsWriteBuffer:void**:buffer::
1584-
PyObject_AsWriteBuffer:Py_ssize_t*:buffer_len::
1585-
15861571
PyObject_Bytes:PyObject*::+1:
15871572
PyObject_Bytes:PyObject*:o:0:
15881573

@@ -1618,9 +1603,6 @@ PyObject_CallObject:PyObject*:args:0:
16181603
PyObject_CheckBuffer:int:::
16191604
PyObject_CheckBuffer:PyObject*:obj:0:
16201605

1621-
PyObject_CheckReadBuffer:int:::
1622-
PyObject_CheckReadBuffer:PyObject*:o:0:
1623-
16241606
PyObject_DelAttr:int:::
16251607
PyObject_DelAttr:PyObject*:o:0:
16261608
PyObject_DelAttr:PyObject*:attr_name:0:

Doc/whatsnew/3.10.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,8 @@ Porting to Python 3.10
204204

205205
Removed
206206
-------
207+
208+
* ``PyObject_AsCharBuffer()``, ``PyObject_AsReadBuffer()``, ``PyObject_CheckReadBuffer()``,
209+
and ``PyObject_AsWriteBuffer()`` are removed. Please migrate to new buffer protocol;
210+
:c:func:`PyObject_GetBuffer` and :c:func:`PyBuffer_Release`.
211+
(Contributed by Inada Naoki in :issue:`41103`.

Include/abstract.h

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -309,53 +309,6 @@ PyAPI_FUNC(int) PyObject_DelItemString(PyObject *o, const char *key);
309309
PyAPI_FUNC(int) PyObject_DelItem(PyObject *o, PyObject *key);
310310

311311

312-
/* === Old Buffer API ============================================ */
313-
314-
/* FIXME: usage of these should all be replaced in Python itself
315-
but for backwards compatibility we will implement them.
316-
Their usage without a corresponding "unlock" mechanism
317-
may create issues (but they would already be there). */
318-
319-
/* Takes an arbitrary object which must support the (character, single segment)
320-
buffer interface and returns a pointer to a read-only memory location
321-
useable as character based input for subsequent processing.
322-
323-
Return 0 on success. buffer and buffer_len are only set in case no error
324-
occurs. Otherwise, -1 is returned and an exception set. */
325-
Py_DEPRECATED(3.0)
326-
PyAPI_FUNC(int) PyObject_AsCharBuffer(PyObject *obj,
327-
const char **buffer,
328-
Py_ssize_t *buffer_len);
329-
330-
/* Checks whether an arbitrary object supports the (character, single segment)
331-
buffer interface.
332-
333-
Returns 1 on success, 0 on failure. */
334-
Py_DEPRECATED(3.0) PyAPI_FUNC(int) PyObject_CheckReadBuffer(PyObject *obj);
335-
336-
/* Same as PyObject_AsCharBuffer() except that this API expects (readable,
337-
single segment) buffer interface and returns a pointer to a read-only memory
338-
location which can contain arbitrary data.
339-
340-
0 is returned on success. buffer and buffer_len are only set in case no
341-
error occurs. Otherwise, -1 is returned and an exception set. */
342-
Py_DEPRECATED(3.0)
343-
PyAPI_FUNC(int) PyObject_AsReadBuffer(PyObject *obj,
344-
const void **buffer,
345-
Py_ssize_t *buffer_len);
346-
347-
/* Takes an arbitrary object which must support the (writable, single segment)
348-
buffer interface and returns a pointer to a writable memory location in
349-
buffer of size 'buffer_len'.
350-
351-
Return 0 on success. buffer and buffer_len are only set in case no error
352-
occurs. Otherwise, -1 is returned and an exception set. */
353-
Py_DEPRECATED(3.0)
354-
PyAPI_FUNC(int) PyObject_AsWriteBuffer(PyObject *obj,
355-
void **buffer,
356-
Py_ssize_t *buffer_len);
357-
358-
359312
/* === New Buffer API ============================================ */
360313

361314
/* Takes an arbitrary object and returns the result of calling
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
``PyObject_AsCharBuffer()``, ``PyObject_AsReadBuffer()``,
2+
``PyObject_CheckReadBuffer()``, and ``PyObject_AsWriteBuffer()`` are
3+
removed. Please migrate to new buffer protocol; :c:func:`PyObject_GetBuffer`
4+
and :c:func:`PyBuffer_Release`.

Objects/abstract.c

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -292,85 +292,6 @@ PyObject_CheckBuffer(PyObject *obj)
292292
}
293293

294294

295-
/* We release the buffer right after use of this function which could
296-
cause issues later on. Don't use these functions in new code.
297-
*/
298-
int
299-
PyObject_CheckReadBuffer(PyObject *obj)
300-
{
301-
PyBufferProcs *pb = Py_TYPE(obj)->tp_as_buffer;
302-
Py_buffer view;
303-
304-
if (pb == NULL ||
305-
pb->bf_getbuffer == NULL)
306-
return 0;
307-
if ((*pb->bf_getbuffer)(obj, &view, PyBUF_SIMPLE) == -1) {
308-
PyErr_Clear();
309-
return 0;
310-
}
311-
PyBuffer_Release(&view);
312-
return 1;
313-
}
314-
315-
static int
316-
as_read_buffer(PyObject *obj, const void **buffer, Py_ssize_t *buffer_len)
317-
{
318-
Py_buffer view;
319-
320-
if (obj == NULL || buffer == NULL || buffer_len == NULL) {
321-
null_error();
322-
return -1;
323-
}
324-
if (PyObject_GetBuffer(obj, &view, PyBUF_SIMPLE) != 0)
325-
return -1;
326-
327-
*buffer = view.buf;
328-
*buffer_len = view.len;
329-
PyBuffer_Release(&view);
330-
return 0;
331-
}
332-
333-
int
334-
PyObject_AsCharBuffer(PyObject *obj,
335-
const char **buffer,
336-
Py_ssize_t *buffer_len)
337-
{
338-
return as_read_buffer(obj, (const void **)buffer, buffer_len);
339-
}
340-
341-
int PyObject_AsReadBuffer(PyObject *obj,
342-
const void **buffer,
343-
Py_ssize_t *buffer_len)
344-
{
345-
return as_read_buffer(obj, buffer, buffer_len);
346-
}
347-
348-
int PyObject_AsWriteBuffer(PyObject *obj,
349-
void **buffer,
350-
Py_ssize_t *buffer_len)
351-
{
352-
PyBufferProcs *pb;
353-
Py_buffer view;
354-
355-
if (obj == NULL || buffer == NULL || buffer_len == NULL) {
356-
null_error();
357-
return -1;
358-
}
359-
pb = Py_TYPE(obj)->tp_as_buffer;
360-
if (pb == NULL ||
361-
pb->bf_getbuffer == NULL ||
362-
((*pb->bf_getbuffer)(obj, &view, PyBUF_WRITABLE) != 0)) {
363-
PyErr_SetString(PyExc_TypeError,
364-
"expected a writable bytes-like object");
365-
return -1;
366-
}
367-
368-
*buffer = view.buf;
369-
*buffer_len = view.len;
370-
PyBuffer_Release(&view);
371-
return 0;
372-
}
373-
374295
/* Buffer C-API for Python 3.0 */
375296

376297
int

PC/python3dll.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,11 +392,8 @@ EXPORT_FUNC(PyNumber_Subtract)
392392
EXPORT_FUNC(PyNumber_ToBase)
393393
EXPORT_FUNC(PyNumber_TrueDivide)
394394
EXPORT_FUNC(PyNumber_Xor)
395-
EXPORT_FUNC(PyObject_AsCharBuffer)
396395
EXPORT_FUNC(PyObject_ASCII)
397396
EXPORT_FUNC(PyObject_AsFileDescriptor)
398-
EXPORT_FUNC(PyObject_AsReadBuffer)
399-
EXPORT_FUNC(PyObject_AsWriteBuffer)
400397
EXPORT_FUNC(PyObject_Bytes)
401398
EXPORT_FUNC(PyObject_Call)
402399
EXPORT_FUNC(PyObject_CallFunction)
@@ -405,7 +402,6 @@ EXPORT_FUNC(PyObject_CallMethod)
405402
EXPORT_FUNC(PyObject_CallMethodObjArgs)
406403
EXPORT_FUNC(PyObject_CallObject)
407404
EXPORT_FUNC(PyObject_Calloc)
408-
EXPORT_FUNC(PyObject_CheckReadBuffer)
409405
EXPORT_FUNC(PyObject_ClearWeakRefs)
410406
EXPORT_FUNC(PyObject_DelItem)
411407
EXPORT_FUNC(PyObject_DelItemString)

0 commit comments

Comments
 (0)