diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-03-06 00:13:43 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-06 00:13:43 (GMT) |
commit | c656e25667c9acc0d13e5bb16d3df2938d0f614b (patch) | |
tree | 61e424b53e6f0b1f5a2d7637fedf47ab5e91962e /Python/pylifecycle.c | |
parent | 7d2ef3ef5042356aaeaf832ad4204b7dad2e1b8c (diff) | |
download | cpython-c656e25667c9acc0d13e5bb16d3df2938d0f614b.zip cpython-c656e25667c9acc0d13e5bb16d3df2938d0f614b.tar.gz cpython-c656e25667c9acc0d13e5bb16d3df2938d0f614b.tar.bz2 |
bpo-36142: Add _PyPreConfig_SetAllocator() (GH-12187)
* _PyPreConfig_Write() now reallocates the pre-configuration with the
new memory allocator.
* It is no longer needed to force the "default raw memory allocator"
to clear pre-configuration and core configuration. Simplify the
code.
* _PyPreConfig_Write() now does nothing if called after
Py_Initialize(): no longer check if the allocator is the same.
* Remove _PyMem_GetDebugAllocatorsName(): dev mode sets again
allocator to "debug".
Diffstat (limited to 'Python/pylifecycle.c')
-rw-r--r-- | Python/pylifecycle.c | 29 |
1 files changed, 6 insertions, 23 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index f72af86..522a427 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -716,21 +716,14 @@ _Py_InitializeCore_impl(PyInterpreterState **interp_p, static _PyInitError pyinit_preconfig(_PyPreConfig *preconfig, const _PyPreConfig *src_preconfig) { - _PyInitError err; - PyMemAllocatorEx old_alloc; - /* Set LC_CTYPE to the user preferred locale */ _Py_SetLocaleFromEnv(LC_CTYPE); - _PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc); - if (_PyPreConfig_Copy(preconfig, src_preconfig) >= 0) { - err = _PyPreConfig_Read(preconfig); + if (_PyPreConfig_Copy(preconfig, src_preconfig) < 0) { + return _Py_INIT_ERR("failed to copy pre config"); } - else { - err = _Py_INIT_ERR("failed to copy pre config"); - } - PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc); + _PyInitError err = _PyPreConfig_Read(preconfig); if (_Py_INIT_FAILED(err)) { return err; } @@ -743,21 +736,15 @@ static _PyInitError pyinit_coreconfig(_PyCoreConfig *config, const _PyCoreConfig *src_config, PyInterpreterState **interp_p) { - PyMemAllocatorEx old_alloc; - _PyInitError err; /* Set LC_CTYPE to the user preferred locale */ _Py_SetLocaleFromEnv(LC_CTYPE); - _PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc); - if (_PyCoreConfig_Copy(config, src_config) >= 0) { - err = _PyCoreConfig_Read(config, NULL); - } - else { - err = _Py_INIT_ERR("failed to copy core config"); + if (_PyCoreConfig_Copy(config, src_config) < 0) { + return _Py_INIT_ERR("failed to copy core config"); } - PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc); + _PyInitError err = _PyCoreConfig_Read(config, NULL); if (_Py_INIT_FAILED(err)) { return err; } @@ -792,7 +779,6 @@ _PyInitError _Py_InitializeCore(PyInterpreterState **interp_p, const _PyCoreConfig *src_config) { - PyMemAllocatorEx old_alloc; _PyInitError err; assert(src_config != NULL); @@ -807,10 +793,7 @@ _Py_InitializeCore(PyInterpreterState **interp_p, err = pyinit_coreconfig(&local_config, src_config, interp_p); done: - _PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc); _PyCoreConfig_Clear(&local_config); - PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc); - return err; } |