diff options
Diffstat (limited to 'Python')
-rw-r--r-- | Python/pylifecycle.c | 2 | ||||
-rw-r--r-- | Python/pystate.c | 26 |
2 files changed, 20 insertions, 8 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index b89cbc88d4..01f314e4bd 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -630,7 +630,7 @@ _Py_InitializeCore(const _PyCoreConfig *config) } if (_PyMem_SetupAllocators(core_config.allocator) < 0) { - return _Py_INIT_ERR("Unknown PYTHONMALLOC allocator"); + return _Py_INIT_USER_ERR("Unknown PYTHONMALLOC allocator"); } if (_PyRuntime.initialized) { diff --git a/Python/pystate.c b/Python/pystate.c index ecf921d0c2..0fb8ed0719 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -35,8 +35,8 @@ to avoid the expense of doing their own locking). extern "C" { #endif -_PyInitError -_PyRuntimeState_Init(_PyRuntimeState *runtime) +static _PyInitError +_PyRuntimeState_Init_impl(_PyRuntimeState *runtime) { memset(runtime, 0, sizeof(*runtime)); @@ -59,14 +59,26 @@ _PyRuntimeState_Init(_PyRuntimeState *runtime) return _Py_INIT_OK(); } +_PyInitError +_PyRuntimeState_Init(_PyRuntimeState *runtime) +{ + /* Force default allocator, since _PyRuntimeState_Fini() must + use the same allocator than this function. */ + PyMemAllocatorEx old_alloc; + _PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc); + + _PyInitError err = _PyRuntimeState_Init_impl(runtime); + + PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc); + return err; +} + void _PyRuntimeState_Fini(_PyRuntimeState *runtime) { - /* Use the same memory allocator than _PyRuntimeState_Init() */ - PyMemAllocatorEx old_alloc, raw_alloc; - PyMem_GetAllocator(PYMEM_DOMAIN_RAW, &old_alloc); - _PyMem_GetDefaultRawAllocator(&raw_alloc); - PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &raw_alloc); + /* Force the allocator used by _PyRuntimeState_Init(). */ + PyMemAllocatorEx old_alloc; + _PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc); if (runtime->interpreters.mutex != NULL) { PyThread_free_lock(runtime->interpreters.mutex); |