mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
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__.
This commit is contained in:
parent
c17238251f
commit
fe462f5a91
7 changed files with 53 additions and 20 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue