You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PyBytesWriter_GetData should mention that PyBytesWriter_Resize can also invalidate the returned pointer #146353
See relevant discussion on PyO3/pyo3#5906 and the discussion linked from that.
PyBytesWriter_Resize may need to reallocate the buffer to grow it. If this happens, any pointer previously returned by PyBytesWriter_GetData will be invalidated, but this is not documented -- only PyBytesWriter_Finish and PyBytesWriter_Discard are documented to invalidate previous data pointers.
I am happy to submit a PR for this issue if that would be helpful. (I assume I only need to modify Doc/c-api/bytes.rst?)
I think we can say "Unless stated otherwise, the pointer is valid until a PyBytesWriter function is called" and then we modify case by case the functions that do not invalidate the pointer. If there are more functions like that, we just document those that invalidate the pointer.
Activity
sergey-miryanov commentedon Mar 24, 2026
cc @vstinner
vstinner commentedon Mar 24, 2026
Go ahead. In fact, many
PyBytesWriterfunctions can invalidate the data pointer. Any function callingPyBytesWriter_Resize():You may just say:
vstinner commentedon Mar 24, 2026
Correct.
TeamSpen210 commentedon Mar 24, 2026
Should probably be more specific, state that
PyBytesWriter_GetSize()andPyBytesWriter_GetData()are exceptions and don't invalidate.picnixz commentedon Apr 3, 2026
I think we can say "Unless stated otherwise, the pointer is valid until a PyBytesWriter function is called" and then we modify case by case the functions that do not invalidate the pointer. If there are more functions like that, we just document those that invalidate the pointer.
gh-146353: Document `PyBytesWriter_GetData` pointer validity (GH-151418)
[3.15] gh-146353: Document `PyBytesWriter_GetData` pointer validity (G…
pythongh-146353: Document `PyBytesWriter_GetData` pointer validity (p…