Skip to content

Conversation

@colesbury
Copy link
Contributor

@colesburycolesbury commented Nov 21, 2025

@colesbury
Copy link
ContributorAuthor

It ended up being easier to use Py_BEGIN_CRITICAL_SECTION than trying to use PyDict_SetDefaultRef:

It's tricky to correctly handle the case where there's an existing entry that fails the PyModule_Check(m) test with PyDict_SetDefaultRef.

Even though interp->modules is always a PyDictObject, a bunch of the code was changed a few years ago to use the abstract API, so I didn't want to mess with it. See:

Copy link
Contributor

@kumaraditya303kumaraditya303 left a comment

Choose a reason for hiding this comment

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

LGTM

@colesburycolesbury merged commit 2d50dd2 into python:mainNov 21, 2025
52 checks passed
@miss-islington-app
Copy link

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

@colesburycolesbury deleted the gh-137422-pyimport-addmoduleref branch November 21, 2025 18:30
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 21, 2025
…h-141822) (cherry picked from commit 2d50dd2) Co-authored-by: Sam Gross <colesbury@gmail.com>
@bedevere-app
Copy link

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

@bedevere-appbedevere-appbot removed the needs backport to 3.14 bugs and security fixes label Nov 21, 2025
colesbury added a commit that referenced this pull request Nov 21, 2025
) (gh-141830) (cherry picked from commit 2d50dd2) Co-authored-by: Sam Gross <colesbury@gmail.com>
StanFromIreland pushed a commit to StanFromIreland/cpython that referenced this pull request Dec 6, 2025
ashm-dev pushed a commit to ashm-dev/cpython that referenced this pull request Dec 8, 2025
Sign up for freeto 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

@colesbury@kumaraditya303