◐ Shell
clean mode source ↗

gh-85275: Remove old buffer APIs by methane · Pull Request #105137 · python/cpython

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to elaborate how to replace the 3 "As" functions with PyObject_GetBuffer() flags? I'm not used this Py_buffer API. AsCharBuffer() use const char ** type and AsReadBuffer() use const void **buffer type: constant. But PyBuffer.buf type is void*, it's mutable. Maybe add a note about casting if needed? Or provide a full recipe. I don't know.

How do you replace buffer_len? Is it Py_buffer.len or Py_buffer.itemsize? It's a honest question, I don't know the answer :-(

You may also mention that PyObject_CheckReadBuffer() ignores any kind of exception, whereas PyObject_GetBuffer() can raise different exceptions. What is the expected exception if a type doesn't support the buffer protocol?