diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2016-03-14 11:04:26 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2016-03-14 11:04:26 (GMT) |
commit | 34be807ca4dfecc5b0a9e577a48535e738dce32b (patch) | |
tree | 38e0e3860b3fabf2be4938330a1d0f37c5b169ab /Modules/main.c | |
parent | c877658d1ff5f93f3a2c7b5f0a7ac913b7374838 (diff) | |
download | cpython-34be807ca4dfecc5b0a9e577a48535e738dce32b.zip cpython-34be807ca4dfecc5b0a9e577a48535e738dce32b.tar.gz cpython-34be807ca4dfecc5b0a9e577a48535e738dce32b.tar.bz2 |
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.
Diffstat (limited to 'Modules/main.c')
-rw-r--r-- | Modules/main.c | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/Modules/main.c b/Modules/main.c index ee129a5..b6dcdd0 100644 --- a/Modules/main.c +++ b/Modules/main.c @@ -93,14 +93,15 @@ static const char usage_5[] = " The default module search path uses %s.\n" "PYTHONCASEOK : ignore case in 'import' statements (Windows).\n" "PYTHONIOENCODING: Encoding[:errors] used for stdin/stdout/stderr.\n" -"PYTHONFAULTHANDLER: dump the Python traceback on fatal errors.\n\ -"; -static const char usage_6[] = "\ -PYTHONHASHSEED: if this variable is set to 'random', a random value is used\n\ - to seed the hashes of str, bytes and datetime objects. It can also be\n\ - set to an integer in the range [0,4294967295] to get hash values with a\n\ - predictable seed.\n\ -"; +"PYTHONFAULTHANDLER: dump the Python traceback on fatal errors.\n"; +static const char usage_6[] = +"PYTHONHASHSEED: if this variable is set to 'random', a random value is used\n" +" to seed the hashes of str, bytes and datetime objects. It can also be\n" +" set to an integer in the range [0,4294967295] to get hash values with a\n" +" predictable seed.\n" +"PYTHONMALLOC: set the Python memory allocators and/or install debug hooks\n" +" on Python memory allocators. Use PYTHONMALLOC=debug to install debug\n" +" hooks.\n"; static int usage(int exitcode, const wchar_t* program) @@ -341,6 +342,7 @@ Py_Main(int argc, wchar_t **argv) int help = 0; int version = 0; int saw_unbuffered_flag = 0; + char *opt; PyCompilerFlags cf; PyObject *warning_option = NULL; PyObject *warning_options = NULL; @@ -365,6 +367,13 @@ Py_Main(int argc, wchar_t **argv) } } + opt = Py_GETENV("PYTHONMALLOC"); + if (_PyMem_SetupAllocators(opt) < 0) { + fprintf(stderr, + "Error in PYTHONMALLOC: unknown allocator \"%s\"!\n", opt); + exit(1); + } + Py_HashRandomizationFlag = 1; _PyRandom_Init(); |