Skip to content

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Sep 15, 2025

Replace PyBytes_FromStringAndSize(NULL, size) with the new public PyBytesWriter API.

Replace PyBytes_FromStringAndSize(NULL, size) with the new public
PyBytesWriter API.
@vstinner
Copy link
Member Author

cc @picnixz

@vstinner
Copy link
Member Author

@picnixz: Please review the updated code.

@picnixz
Copy link
Member

picnixz commented Sep 15, 2025

Wait, does Create overallocate the buffer? because in sha3 and hashopenssl we don't need extra bytes (we just need the exact size that is asked).

@vstinner
Copy link
Member Author

Wait, does Create overallocate the buffer? because in sha3 and hashopenssl we don't need extra bytes (we just need the exact size that is asked).

PyBytesWrite_Create(n) allocates exactly n bytes, it doesn't use overallocation. Only PyBytesWriter_Grow() and PyBytesWriter_Resize() use overallocation.

@vstinner vstinner merged commit a68efdf into python:main Sep 15, 2025
47 checks passed
@vstinner vstinner deleted the pybyteswriter_hashopenssl branch September 15, 2025 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants