[3.14] gh-156995: Fix _PyBytes_Resize() in Free Threading (#156996) - #157373
Merged
Conversation
On Free Threading, _PyBytes_Resize(&obj, 1) no longer returns a single byte singleton if the current thread is different than the thread which created the object. Co-authored-by: Cody Maloney <cmaloney@users.noreply.github.com> Co-authored-by: Victor Stinner <vstinner@python.org> (cherry picked from commit fd569ea)
Member
Author
|
I failed to find a function in Python 3.14 stdlib which still mutates the bytes object after calling bytes = PyBytes_FromStringAndSize(NULL, size);
... write into bytes ...
_PyBytes_Resize(&bytes, n);
return bytes; // bytes no longer mutated from this pointThere is |
Member
Author
|
This change should be backported to Python 3.13, but the fix there is different because _PyBytes_Resize() doesn't test |
vstinner
added a commit
to vstinner/cpython
that referenced
this pull request
Sep 13, 2026
…on#156996) (python#157373) _PyBytes_Resize(&obj, 1) no longer returns a single byte singleton if the reference count is greater than 1. (cherry picked from commit fd569ea) Co-authored-by: Stan Ulbrych <stan@python.org> Co-authored-by: Cody Maloney <cmaloney@users.noreply.github.com> Co-authored-by: Victor Stinner <vstinner@python.org>
|
GH-157436 is a backport of this pull request to the 3.14 branch. |
|
GH-157436 is a backport of this pull request to the 3.13 branch. |
vstinner
added a commit
that referenced
this pull request
Sep 13, 2026
…157373) (#157436) [3.14] gh-156995: Fix _PyBytes_Resize() in Free Threading (#156996) (#157373) _PyBytes_Resize(&obj, 1) no longer returns a single byte singleton if the reference count is greater than 1. (cherry picked from commit fd569ea) Co-authored-by: Stan Ulbrych <stan@python.org> Co-authored-by: Cody Maloney <cmaloney@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On Free Threading, _PyBytes_Resize(&obj, 1) no longer returns a single byte singleton is the current thread is different than the thread which created the object.
(cherry picked from commit fd569ea)
bytearray.take_bytes()can corrupt shared single-byte bytes objects #156995