mirror of
https://github.com/python/cpython.git
synced 2025-08-02 16:13:13 +00:00
bpo-32030: Rework memory allocators (#4625)
* Fix _PyMem_SetupAllocators("debug"): always restore allocators to the defaults, rather than only caling _PyMem_SetupDebugHooks(). * Add _PyMem_SetDefaultAllocator() helper to set the "default" allocator. * Add _PyMem_GetAllocatorsName(): get the name of the allocators * main() now uses debug hooks on memory allocators if Py_DEBUG is defined, rather than calling directly malloc() * Document default memory allocators in C API documentation * _Py_InitializeCore() now fails with a fatal user error if PYTHONMALLOC value is an unknown memory allocator, instead of failing with a fatal internal error. * Add new tests on the PYTHONMALLOC environment variable * Add support.with_pymalloc() * Add the _testcapi.WITH_PYMALLOC constant and expose it as support.with_pymalloc(). * sysconfig.get_config_var('WITH_PYMALLOC') doesn't work on Windows, so replace it with support.with_pymalloc(). * pythoninfo: add _testcapi collector for pymem
This commit is contained in:
parent
c15bb49d71
commit
5d39e04290
14 changed files with 405 additions and 171 deletions
|
@ -475,11 +475,9 @@ pymain_free_impl(_PyMain *pymain)
|
|||
static void
|
||||
pymain_free(_PyMain *pymain)
|
||||
{
|
||||
/* Force malloc() memory allocator */
|
||||
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 pymain_parse_cmdline_envvars() */
|
||||
PyMemAllocatorEx old_alloc;
|
||||
_PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
|
||||
|
||||
pymain_free_impl(pymain);
|
||||
|
||||
|
@ -1561,17 +1559,14 @@ pymain_parse_cmdline_envvars_impl(_PyMain *pymain)
|
|||
static int
|
||||
pymain_parse_cmdline_envvars(_PyMain *pymain)
|
||||
{
|
||||
/* Force malloc() memory allocator */
|
||||
PyMemAllocatorEx old_alloc, raw_alloc;
|
||||
PyMem_GetAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
|
||||
_PyMem_GetDefaultRawAllocator(&raw_alloc);
|
||||
PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &raw_alloc);
|
||||
/* Force default allocator, since pymain_free() must use the same allocator
|
||||
than this function. */
|
||||
PyMemAllocatorEx old_alloc;
|
||||
_PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
|
||||
|
||||
int res = pymain_parse_cmdline_envvars_impl(pymain);
|
||||
|
||||
/* Restore the old memory allocator */
|
||||
PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue