Skip to content

Commit 4312522

Browse files
authored
bpo-36710: Add runtime variable to Py_InitializeEx() (GH-12939)
Py_InitializeEx() now uses a runtime variable passed to subfunctions, rather than working directly on the global variable _PyRuntime. Add 'runtime' parameter to _PyCoreConfig_Write(), _PySys_Create(), _PySys_InitMain(), _PyGILState_Init(), emit_stderr_warning_for_legacy_locale() and other subfunctions.
1 parent 8e91c24 commit 4312522

File tree

6 files changed

+104
-71
lines changed

6 files changed

+104
-71
lines changed

‎Include/internal/pycore_coreconfig.h‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ extern "C" {
88
# error "this header requires Py_BUILD_CORE define"
99
#endif
1010

11+
#include "pycore_pystate.h" /* _PyRuntimeState */
12+
1113

1214
/* --- _PyWstrList ------------------------------------------------ */
1315

@@ -108,7 +110,8 @@ PyAPI_FUNC(_PyInitError) _PyCoreConfig_SetPathConfig(
108110
const _PyCoreConfig *config);
109111
PyAPI_FUNC(_PyInitError) _PyCoreConfig_Read(_PyCoreConfig *config,
110112
const _PyArgv *args);
111-
PyAPI_FUNC(void) _PyCoreConfig_Write(const _PyCoreConfig *config);
113+
PyAPI_FUNC(void) _PyCoreConfig_Write(const _PyCoreConfig *config,
114+
_PyRuntimeState *runtime);
112115

113116

114117
/* --- Function used for testing ---------------------------------- */

‎Include/internal/pycore_pylifecycle.h‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,13 @@ extern _PyInitError _PyFaulthandler_Init(int enable);
3434
extern int _PyTraceMalloc_Init(int enable);
3535
extern PyObject * _PyBuiltin_Init(void);
3636
extern _PyInitError _PySys_Create(
37+
_PyRuntimeState *runtime,
3738
PyInterpreterState *interp,
3839
PyObject **sysmod_p);
3940
extern _PyInitError _PySys_SetPreliminaryStderr(PyObject *sysdict);
40-
extern int _PySys_InitMain(PyInterpreterState *interp);
41+
extern int _PySys_InitMain(
42+
_PyRuntimeState *runtime,
43+
PyInterpreterState *interp);
4144
extern _PyInitError _PyImport_Init(PyInterpreterState *interp);
4245
extern _PyInitError _PyExc_Init(void);
4346
extern _PyInitError _PyBuiltins_AddExceptions(PyObject * bltinmod);
@@ -74,7 +77,10 @@ extern void _PyFaulthandler_Fini(void);
7477
extern void _PyHash_Fini(void);
7578
extern int _PyTraceMalloc_Fini(void);
7679

77-
extern void _PyGILState_Init(PyInterpreterState *, PyThreadState *);
80+
extern void _PyGILState_Init(
81+
_PyRuntimeState *runtime,
82+
PyInterpreterState *interp,
83+
PyThreadState *tstate);
7884
extern void _PyGILState_Fini(_PyRuntimeState *runtime);
7985

8086
PyAPI_FUNC(void) _PyGC_DumpShutdownStats(void);

‎Python/coreconfig.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,13 +1605,13 @@ config_init_stdio(const _PyCoreConfig *config)
16051605
- set Py_xxx global configuration variables
16061606
- initialize C standard streams (stdin, stdout, stderr) */
16071607
void
1608-
_PyCoreConfig_Write(const _PyCoreConfig *config)
1608+
_PyCoreConfig_Write(const _PyCoreConfig *config, _PyRuntimeState *runtime)
16091609
{
16101610
_PyCoreConfig_SetGlobalConfig(config);
16111611
config_init_stdio(config);
16121612

16131613
/* Write the new pre-configuration into _PyRuntime */
1614-
_PyPreConfig *preconfig = &_PyRuntime.preconfig;
1614+
_PyPreConfig *preconfig = &runtime->preconfig;
16151615
preconfig->isolated = config->isolated;
16161616
preconfig->use_environment = config->use_environment;
16171617
preconfig->dev_mode = config->dev_mode;

0 commit comments

Comments
 (0)