Replace PyUnstable_InterpreterState_GetMainModule() with _Py_GetMainM… · python/cpython@ed0d690 · GitHub
Skip to content

Commit ed0d690

Browse files
Replace PyUnstable_InterpreterState_GetMainModule() with _Py_GetMainModule() and _Py_CheckMainModule().
1 parent 8a4d4f3 commit ed0d690

5 files changed

Lines changed: 38 additions & 20 deletions

File tree

Doc/c-api/init.rst

Lines changed: 0 additions & 10 deletions

Include/cpython/pystate.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
PyAPI_FUNC(int) _PyInterpreterState_RequiresIDRef(PyInterpreterState *);
99
PyAPI_FUNC(void) _PyInterpreterState_RequireIDRef(PyInterpreterState *, int);
1010

11-
PyAPI_FUNC(PyObject *) PyUnstable_InterpreterState_GetMainModule(PyInterpreterState *);
12-
1311
/* State unique per thread */
1412

1513
/* Py_tracefunc return -1 when raising an exception, or 0 for success. */

Include/internal/pycore_pystate.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,9 @@ PyAPI_FUNC(const PyConfig*) _Py_GetConfig(void);
283283
// See also PyInterpreterState_Get() and _PyInterpreterState_GET().
284284
extern PyInterpreterState* _PyGILState_GetInterpreterStateUnsafe(void);
285285

286+
extern PyObject * _Py_GetMainModule(PyThreadState *);
287+
extern int _Py_CheckMainModule(PyObject *module);
288+
286289
#ifndef NDEBUG
287290
/* Modern equivalent of assert(PyGILState_Check()) */
288291
static inline void

Python/crossinterp.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,6 +1728,7 @@ _PyXI_Enter(_PyXI_session *session,
17281728

17291729
// Switch to the requested interpreter (if necessary).
17301730
_enter_session(session, interp);
1731+
PyThreadState *session_tstate = session->init_tstate;
17311732
_PyXI_errcode errcode = _PyXI_ERR_UNCAUGHT_EXCEPTION;
17321733

17331734
// Ensure this thread owns __main__.
@@ -1741,8 +1742,8 @@ _PyXI_Enter(_PyXI_session *session,
17411742
session->running = 1;
17421743

17431744
// Cache __main__.__dict__.
1744-
PyObject *main_mod = PyUnstable_InterpreterState_GetMainModule(interp);
1745-
if (main_mod == NULL) {
1745+
PyObject *main_mod = _Py_GetMainModule(session_tstate);
1746+
if (_Py_CheckMainModule(main_mod) < 0) {
17461747
errcode = _PyXI_ERR_MAIN_NS_FAILURE;
17471748
goto error;
17481749
}

Python/pystate.c

Lines changed: 32 additions & 6 deletions

0 commit comments

Comments
 (0)