GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-145142: Make str.maketrans safe under free-threading by VanshAgarwal24036 · Pull Request #145157 · python/cpython

Conversation

@VanshAgarwal24036

@VanshAgarwal24036 VanshAgarwal24036 commented Feb 23, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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.

  • Issue: str.maketrans on a mutating dict is not thread-safe #145142

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added the awaiting review label Feb 23, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Feb 23, 2026
str.maketrans on a mutating dict is not thread-safe #145142
Closed
colesbury
colesbury reviewed Feb 23, 2026
View reviewed changes

@colesbury colesbury left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

A few comments below

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/test/test_free_threading/test_maketrans_threading.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Objects/unicodeobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Misc/NEWS.d/next/Core_and_Builtins/2026-02-23-23-18-28.gh-issue-145142.T-XbVe.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_free_threading/test_maketrans_threading.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

picnixz
picnixz requested changes Feb 24, 2026
View reviewed changes

@picnixz picnixz left a comment •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

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).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Objects/unicodeobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Objects/unicodeobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot added awaiting changes and removed awaiting review labels Feb 24, 2026
@bedevere-app

bedevere-app Bot commented Feb 24, 2026

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

sharktide
sharktide reviewed Feb 24, 2026
View reviewed changes

@sharktide sharktide left a comment •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Bunch of syntax errors you need to fix as well.

I also agree with picnixz’s comments

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@VanshAgarwal24036
VanshAgarwal24036 marked this pull request as draft February 24, 2026 12:44
@bedevere-app bedevere-app Bot removed the awaiting changes label Feb 24, 2026
@VanshAgarwal24036
VanshAgarwal24036 force-pushed the gh-145142-dict-next-critical-section branch from d487864 to 05ba3f3 Compare February 24, 2026 15:57
@VanshAgarwal24036
VanshAgarwal24036 marked this pull request as ready for review February 24, 2026 16:37
@bedevere-app bedevere-app Bot added the awaiting review label Feb 24, 2026
VanshAgarwal24036 added 10 commits February 24, 2026 17:20
@VanshAgarwal24036
pythongh-145142: Make str.maketrans safe under free-threading
0745e41
@VanshAgarwal24036
Add new line at end of test file
3fdf54c
@VanshAgarwal24036
Update changes
9a75245
@VanshAgarwal24036
Add new line at end of news file
5071b9d
@VanshAgarwal24036
Remove unnecessary paranthesis in news file
b34fd09
@VanshAgarwal24036
Correct build error
044c347
@VanshAgarwal24036
Update
b7e9d1b
@VanshAgarwal24036
Add new function
bfc812a
@VanshAgarwal24036
Update helper fuction
f7c3c45
@VanshAgarwal24036
Update function
4e715b0
@VanshAgarwal24036
VanshAgarwal24036 force-pushed the gh-145142-dict-next-critical-section branch from 206f6b2 to 4e715b0 Compare February 24, 2026 17:34
@VanshAgarwal24036

VanshAgarwal24036 commented Feb 24, 2026

Copy link
Copy Markdown
Contributor Author

I have made the requested changes; please review again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot added awaiting change review and removed awaiting review labels Feb 24, 2026
@bedevere-app

bedevere-app Bot commented Feb 24, 2026

Copy link
Copy Markdown

Thanks for making the requested changes!

@picnixz: please review the changes made to this pull request.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app
bedevere-app Bot requested a review from picnixz February 24, 2026 17:41
@VanshAgarwal24036
VanshAgarwal24036 requested a review from colesbury February 24, 2026 17:41
@VanshAgarwal24036
VanshAgarwal24036 requested a review from sharktide February 24, 2026 17:41
colesbury
colesbury reviewed Feb 24, 2026
View reviewed changes
Comment thread Objects/unicodeobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@VanshAgarwal24036
Perform suggested changes
b60b67c
@VanshAgarwal24036
VanshAgarwal24036 requested a review from colesbury February 24, 2026 18:27
colesbury
colesbury approved these changes Feb 24, 2026
View reviewed changes

@colesbury colesbury left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM, thanks

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting change review labels Feb 24, 2026
picnixz
picnixz approved these changes Feb 27, 2026
View reviewed changes
@colesbury colesbury added the needs backport to 3.14 bugs and security fixes label Feb 27, 2026
colesbury added 2 commits February 27, 2026 10:41
@colesbury
Fix placement of clinic code
28af6d8
@colesbury
Merge branch 'main' into pythongh-145142-dict-next-critical-section
4994663
@colesbury
colesbury enabled auto-merge (squash) February 27, 2026 15:41
eendebakpt
eendebakpt reviewed Feb 27, 2026
View reviewed changes
Comment thread Objects/unicodeobject.c
}

static int
unicode_maketrans_from_dict(PyObject *x, PyObject *newdict)

@eendebakpt eendebakpt Feb 27, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@colesbury
colesbury merged commit a249795 into python:main Feb 27, 2026
47 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting merge label Feb 27, 2026
@miss-islington-app

miss-islington-app Bot commented Feb 27, 2026

Copy link
Copy Markdown

Thanks @VanshAgarwal24036 for the PR, and @colesbury for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Feb 27, 2026
@VanshAgarwal24036 @miss-islington
pythongh-145142: Make str.maketrans safe under free-threading (python…
0efb6a2
…gh-145157)

(cherry picked from commit a249795)

Co-authored-by: VanshAgarwal24036 <[email protected]>
@bedevere-app

bedevere-app Bot commented Feb 27, 2026

Copy link
Copy Markdown

GH-145320 is a backport of this pull request to the 3.14 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Feb 27, 2026
colesbury pushed a commit that referenced this pull request Feb 27, 2026
@miss-islington @VanshAgarwal24036
[3.14] gh-145142: Make str.maketrans safe under free-threading (gh-14…
d76c56e
…5157) (#145320)

Co-authored-by: VanshAgarwal24036 <[email protected]>
@VanshAgarwal24036
VanshAgarwal24036 deleted the gh-145142-dict-next-critical-section branch February 27, 2026 16:42
brijkapadia pushed a commit to brijkapadia/cpython that referenced this pull request Feb 28, 2026
@VanshAgarwal24036 @brijkapadia
pythongh-145142: Make str.maketrans safe under free-threading (python…
bbcb932
…gh-145157)
ljfp pushed a commit to ljfp/cpython that referenced this pull request Apr 25, 2026
@VanshAgarwal24036 @ljfp
pythongh-145142: Make str.maketrans safe under free-threading (python…
1f6c471
…gh-145157)
@nascheme nascheme mentioned this pull request Jul 14, 2026
Backport free-threading memory-safety fixes to 3.14 and 3.15 #153714
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@eendebakpt eendebakpt eendebakpt left review comments
@colesbury colesbury colesbury approved these changes
@picnixz picnixz picnixz approved these changes
@sharktide sharktide Awaiting requested review from sharktide

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@VanshAgarwal24036 @colesbury @eendebakpt @picnixz @sharktide
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.