From c656e25667c9acc0d13e5bb16d3df2938d0f614b Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 6 Mar 2019 01:13:43 +0100 Subject: 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". --- Modules/main.c | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) (limited to 'Modules/main.c') diff --git a/Modules/main.c b/Modules/main.c index 9a2347e2b2..14055c8101 100644 --- a/Modules/main.c +++ b/Modules/main.c @@ -289,17 +289,9 @@ _PyMainInterpreterConfig_Read(_PyMainInterpreterConfig *main_config, static _PyInitError preconfig_read_write(_PyPreConfig *config, const _PyArgv *args) { - _PyInitError err; - - PyMemAllocatorEx old_alloc; - _PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc); - _PyPreConfig_GetGlobalConfig(config); - err = _PyPreConfig_ReadFromArgv(config, args); - - PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc); - + _PyInitError err = _PyPreConfig_ReadFromArgv(config, args); if (_Py_INIT_FAILED(err)) { return err; } @@ -312,17 +304,9 @@ static _PyInitError config_read_write(_PyCoreConfig *config, const _PyArgv *args, const _PyPreConfig *preconfig) { - _PyInitError err; - - PyMemAllocatorEx old_alloc; - _PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc); - _PyCoreConfig_GetGlobalConfig(config); - err = _PyCoreConfig_ReadFromArgv(config, args, preconfig); - - PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc); - + _PyInitError err = _PyCoreConfig_ReadFromArgv(config, args, preconfig); if (_Py_INIT_FAILED(err)) { return err; } @@ -355,7 +339,6 @@ static _PyInitError pymain_init(const _PyArgv *args, PyInterpreterState **interp_p) { _PyInitError err; - PyMemAllocatorEx old_alloc; err = _PyRuntime_Initialize(); if (_Py_INIT_FAILED(err)) { @@ -402,12 +385,8 @@ pymain_init(const _PyArgv *args, PyInterpreterState **interp_p) err = _Py_INIT_OK(); done: - _PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc); - _PyPreConfig_Clear(preconfig); _PyCoreConfig_Clear(config); - - PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc); return err; } -- cgit v1.2.1