mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
bpo-36301: Add _PyRuntime.pre_initialized (GH-12457)
* Add _PyRuntime.pre_initialized: set to 1 when Python is pre-initialized * Add _Py_PreInitialize() and _Py_PreInitializeFromPreConfig(). * _PyCoreConfig_Read() now calls _Py_PreInitialize(). * Move _PyPreConfig_GetGlobalConfig() and _PyCoreConfig_GetGlobalConfig() calls from main.c to preconfig.c and coreconfig.c.
This commit is contained in:
parent
0d765e3849
commit
f29084d611
6 changed files with 77 additions and 27 deletions
|
@ -714,19 +714,57 @@ _Py_InitializeCore_impl(PyInterpreterState **interp_p,
|
|||
}
|
||||
|
||||
|
||||
static _PyInitError
|
||||
pyinit_preconfig(_PyPreConfig *preconfig, const _PyPreConfig *src_preconfig)
|
||||
_PyInitError
|
||||
_Py_PreInitializeFromPreConfig(_PyPreConfig *config)
|
||||
{
|
||||
if (_PyPreConfig_Copy(preconfig, src_preconfig) < 0) {
|
||||
return _Py_INIT_ERR("failed to copy pre config");
|
||||
if (config != NULL) {
|
||||
_PyInitError err = _PyPreConfig_Write(config);
|
||||
if (_Py_INIT_FAILED(err)) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
_PyInitError err = _PyPreConfig_Read(preconfig);
|
||||
_PyRuntime.pre_initialized = 1;
|
||||
return _Py_INIT_OK();
|
||||
}
|
||||
|
||||
|
||||
static _PyInitError
|
||||
pyinit_preconfig(_PyPreConfig *config, const _PyPreConfig *src_config)
|
||||
{
|
||||
_PyInitError err;
|
||||
|
||||
err = _PyRuntime_Initialize();
|
||||
if (_Py_INIT_FAILED(err)) {
|
||||
return err;
|
||||
}
|
||||
|
||||
return _PyPreConfig_Write(preconfig);
|
||||
if (_PyPreConfig_Copy(config, src_config) < 0) {
|
||||
return _Py_INIT_ERR("failed to copy pre config");
|
||||
}
|
||||
|
||||
err = _PyPreConfig_Read(config);
|
||||
if (_Py_INIT_FAILED(err)) {
|
||||
return err;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue