intbitset icon indicating copy to clipboard operation
intbitset copied to clipboard

PyObject_AsReadBuffer removed in Python 3.13

Open eclipseo opened this issue 2 years ago • 0 comments

Hello,

Fedora Python SIG is testing Python 3.13 building, planning to include it in Fedora 41.

Currently intbitset is failing because it is using the old buffer protocol from Python 2 which was kept as a compatibility layer until Python 3.12:

https://docs.python.org/3/c-api/objbuffer.html

Deprecated since version 3.0.

These functions were part of the “old buffer protocol” API in Python 2. In Python 3, this protocol doesn’t exist anymore but the functions are still exposed to ease porting 2.x code. They act as a compatibility wrapper around the new buffer protocol, but they don’t give you control over the lifetime of the resources acquired when a buffer is exported.

https://docs.python.org/3.13/whatsnew/3.13.html https://github.com/python/cpython/issues/85275

Remove old buffer protocols deprecated in Python 3.0. Use Buffer Protocol instead.

PyObject_CheckReadBuffer() : Use PyObject_CheckBuffer() to test if the object supports the buffer protocol. Note that PyObject_CheckBuffer() doesn’t guarantee that PyObject_GetBuffer() will succeed. To test if the object is actually readable, see the next example of PyObject_GetBuffer().

PyObject_AsCharBuffer(), PyObject_AsReadBuffer() : PyObject_GetBuffer() and PyBuffer_Release() instead:

    Py_buffer view;
    if (PyObject_GetBuffer(obj, &view, PyBUF_SIMPLE) < 0) {
        return NULL;
    }
    // Use `view.buf` and `view.len` to read from the buffer.
    // You may need to cast buf as `(const char*)view.buf`.
    PyBuffer_Release(&view);`

PyObject_AsWriteBuffer() : Use PyObject_GetBuffer() and PyBuffer_Release() instead:

    Py_buffer view;
    if (PyObject_GetBuffer(obj, &view, PyBUF_WRITABLE) < 0) {
        return NULL;
    }
    // Use `view.buf` and `view.len` to write to the buffer.
    PyBuffer_Release(&view);

(Contributed by Inada Naoki in gh-85275.)

eclipseo avatar Oct 31 '23 06:10 eclipseo