aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python/crossinterp.c
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2025-04-28 12:46:22 -0600
committerGitHub <noreply@github.com>2025-04-28 12:46:22 -0600
commitfe462f5a9122e1c2641b5369cbb88c4a5e822816 (patch)
tree2ab97dcc3c793827bc1e620fa8d65d07a3df837a /Python/crossinterp.c
parentc17238251fdf72861dfadcd581c77332b639bcb0 (diff)
downloadcpython-fe462f5a9122e1c2641b5369cbb88c4a5e822816.tar.gz
cpython-fe462f5a9122e1c2641b5369cbb88c4a5e822816.zip
gh-132775: Drop PyUnstable_InterpreterState_GetMainModule() (gh-132978)
We replace it with _Py_GetMainModule(), and add _Py_CheckMainModule(), but both in the internal-only C-API. We also add _PyImport_GetModulesRef(), which is the equivalent of _PyImport_GetModules(), but which increfs before the lock is released. This is used by a later change related to pickle and handling __main__.
Diffstat (limited to 'Python/crossinterp.c')
-rw-r--r--Python/crossinterp.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/Python/crossinterp.c b/Python/crossinterp.c
index 8ba88c4b057..a1dd6b5901d 100644
--- a/Python/crossinterp.c
+++ b/Python/crossinterp.c
@@ -1738,6 +1738,7 @@ _PyXI_Enter(_PyXI_session *session,
// Switch to the requested interpreter (if necessary).
_enter_session(session, interp);
+ PyThreadState *session_tstate = session->init_tstate;
_PyXI_errcode errcode = _PyXI_ERR_UNCAUGHT_EXCEPTION;
// Ensure this thread owns __main__.
@@ -1751,8 +1752,8 @@ _PyXI_Enter(_PyXI_session *session,
session->running = 1;
// Cache __main__.__dict__.
- PyObject *main_mod = PyUnstable_InterpreterState_GetMainModule(interp);
- if (main_mod == NULL) {
+ PyObject *main_mod = _Py_GetMainModule(session_tstate);
+ if (_Py_CheckMainModule(main_mod) < 0) {
errcode = _PyXI_ERR_MAIN_NS_FAILURE;
goto error;
}