Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PyObject_AsReadBuffer removed in Python 3.13 #93

Open
eclipseo opened this issue Oct 31, 2023 · 0 comments · May be fixed by #97
Open

PyObject_AsReadBuffer removed in Python 3.13 #93

eclipseo opened this issue Oct 31, 2023 · 0 comments · May be fixed by #97

Comments

@eclipseo
Copy link

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
python/cpython#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 added a commit to eclipseo/intbitset that referenced this issue Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant