{{ message }}
gh-145142: Make str.maketrans safe under free-threading - #145157
Merged
colesbury merged 13 commits intoFeb 27, 2026
Merged
Conversation
colesbury
reviewed
Feb 23, 2026
picnixz
requested changes
Feb 24, 2026
Member
There was a problem hiding this comment.
I would suggest isolating the loop in a separate function so that we do not have those weird labels jumps and confusing names but this should be benchmarked on PGO/LTO tocheck that we do not introduce an overhead (though I am not that worried as str.maketrans() is usually not a hot function).
sharktide
reviewed
Feb 24, 2026
VanshAgarwal24036
marked this pull request as draft
February 24, 2026 12:44
VanshAgarwal24036
force-pushed
the
gh-145142-dict-next-critical-section
branch
from
February 24, 2026 15:57
d487864 to
05ba3f3
Compare
VanshAgarwal24036
marked this pull request as ready for review
February 24, 2026 16:37
VanshAgarwal24036
force-pushed
the
gh-145142-dict-next-critical-section
branch
from
February 24, 2026 17:34
206f6b2 to
4e715b0
Compare
Contributor
Author
|
I have made the requested changes; please review again. |
|
Thanks for making the requested changes! @picnixz: please review the changes made to this pull request. |
colesbury
reviewed
Feb 24, 2026
picnixz
approved these changes
Feb 27, 2026
colesbury
enabled auto-merge (squash)
February 27, 2026 15:41
eendebakpt
reviewed
Feb 27, 2026
| } | ||
|
|
||
| static int | ||
| unicode_maketrans_from_dict(PyObject *x, PyObject *newdict) |
Contributor
There was a problem hiding this comment.
Suggested change
| unicode_maketrans_from_dict(PyObject *x, PyObject *newdict) | |
| unicode_maketrans_from_dict_lock_held(PyObject *x, PyObject *newdict) |
Naming convention for methods that require locking.
|
Thanks @VanshAgarwal24036 for the PR, and @colesbury for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14. |
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this pull request
Feb 27, 2026
…gh-145157) (cherry picked from commit a249795) Co-authored-by: VanshAgarwal24036 <148854295+VanshAgarwal24036@users.noreply.github.com>
colesbury
pushed a commit
that referenced
this pull request
Feb 27, 2026
brijkapadia
pushed a commit
to brijkapadia/cpython
that referenced
this pull request
Feb 28, 2026
ljfp
pushed a commit
to ljfp/cpython
that referenced
this pull request
Apr 25, 2026
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.

Replace unsafe PyDict_Next iteration with snapshot iteration using PyDict_Items to avoid crashes when the input dict is mutated concurrently under free-threading.
Adds a regression test.