diff options
Diffstat (limited to 'Python/pylifecycle.c')
-rw-r--r-- | Python/pylifecycle.c | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index df9570b..994a94f 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -714,19 +714,57 @@ _Py_InitializeCore_impl(PyInterpreterState **interp_p, } +_PyInitError +_Py_PreInitializeFromPreConfig(_PyPreConfig *config) +{ + if (config != NULL) { + _PyInitError err = _PyPreConfig_Write(config); + if (_Py_INIT_FAILED(err)) { + return err; + } + } + + _PyRuntime.pre_initialized = 1; + return _Py_INIT_OK(); +} + + static _PyInitError -pyinit_preconfig(_PyPreConfig *preconfig, const _PyPreConfig *src_preconfig) +pyinit_preconfig(_PyPreConfig *config, const _PyPreConfig *src_config) { - if (_PyPreConfig_Copy(preconfig, src_preconfig) < 0) { + _PyInitError err; + + err = _PyRuntime_Initialize(); + if (_Py_INIT_FAILED(err)) { + return err; + } + + if (_PyPreConfig_Copy(config, src_config) < 0) { return _Py_INIT_ERR("failed to copy pre config"); } - _PyInitError err = _PyPreConfig_Read(preconfig); + err = _PyPreConfig_Read(config); if (_Py_INIT_FAILED(err)) { return err; } - return _PyPreConfig_Write(preconfig); + return _Py_PreInitializeFromPreConfig(config); +} + + +_PyInitError +_Py_PreInitialize(void) +{ + _PyInitError err = _PyRuntime_Initialize(); + if (_Py_INIT_FAILED(err)) { + return err; + } + + if (_PyRuntime.pre_initialized) { + return _Py_INIT_OK(); + } + + return _Py_PreInitializeFromPreConfig(NULL); } |