Skip to content

Conversation

@colesbury
Copy link
Contributor

@colesbury colesbury commented Nov 21, 2025

@colesbury
Copy link
Contributor Author

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

@kumaraditya303 kumaraditya303 left a comment

Choose a reason for hiding this comment

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

LGTM

@colesbury colesbury merged commit 2d50dd2 into python:main Nov 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.
🐍🍒⛏🤖

@colesbury colesbury 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

bedevere-app bot commented Nov 21, 2025

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

@bedevere-app bedevere-app bot 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>
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