mirror of
https://github.com/python/cpython.git
synced 2025-08-22 09:45:06 +00:00
Add PYTHONMALLOC env var
Issue #26516: * Add PYTHONMALLOC environment variable to set the Python memory allocators and/or install debug hooks. * PyMem_SetupDebugHooks() can now also be used on Python compiled in release mode. * The PYTHONMALLOCSTATS environment variable can now also be used on Python compiled in release mode. It now has no effect if set to an empty string. * In debug mode, debug hooks are now also installed on Python memory allocators when Python is configured without pymalloc.
This commit is contained in:
parent
c877658d1f
commit
34be807ca4
13 changed files with 383 additions and 90 deletions
|
@ -24,6 +24,9 @@ main(int argc, char **argv)
|
|||
int i, res;
|
||||
char *oldloc;
|
||||
|
||||
/* Force malloc() allocator to bootstrap Python */
|
||||
(void)_PyMem_SetupAllocators("malloc");
|
||||
|
||||
argv_copy = (wchar_t **)PyMem_RawMalloc(sizeof(wchar_t*) * (argc+1));
|
||||
argv_copy2 = (wchar_t **)PyMem_RawMalloc(sizeof(wchar_t*) * (argc+1));
|
||||
if (!argv_copy || !argv_copy2) {
|
||||
|
@ -62,7 +65,13 @@ main(int argc, char **argv)
|
|||
|
||||
setlocale(LC_ALL, oldloc);
|
||||
PyMem_RawFree(oldloc);
|
||||
|
||||
res = Py_Main(argc, argv_copy);
|
||||
|
||||
/* Force again malloc() allocator to release memory blocks allocated
|
||||
before Py_Main() */
|
||||
(void)_PyMem_SetupAllocators("malloc");
|
||||
|
||||
for (i = 0; i < argc; i++) {
|
||||
PyMem_RawFree(argv_copy2[i]);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue