summaryrefslogtreecommitdiffstats
path: root/Python/preconfig.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2019-03-06 11:51:53 (GMT)
committerGitHub <noreply@github.com>2019-03-06 11:51:53 (GMT)
commit25d13f37aa6743282d0b8b4df687ff89999964b2 (patch)
tree88b7e7e0834b9c9d1ca13220d83bc6eb845137ea /Python/preconfig.c
parent01e0f439f5009f37b95ab516e91906fcc7fcb8c3 (diff)
downloadcpython-25d13f37aa6743282d0b8b4df687ff89999964b2.zip
cpython-25d13f37aa6743282d0b8b4df687ff89999964b2.tar.gz
cpython-25d13f37aa6743282d0b8b4df687ff89999964b2.tar.bz2
bpo-36142: PYTHONMALLOC overrides PYTHONDEV (GH-12191)
bpo-34247, bpo-36142: The PYTHONMALLOC environment variable has the priority over PYTHONDEV env var and "-X dev" command line option. For example, PYTHONMALLOC=malloc PYTHONDEVMODE=1 sets the memory allocators to "malloc" (and not to "debug"). Add an unit test.
Diffstat (limited to 'Python/preconfig.c')
-rw-r--r--Python/preconfig.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/Python/preconfig.c b/Python/preconfig.c
index 45093d2..50d66b1 100644
--- a/Python/preconfig.c
+++ b/Python/preconfig.c
@@ -445,14 +445,11 @@ preconfig_read(_PyPreConfig *config, const _PyPreCmdline *cmdline)
}
/* allocator */
- if (config->dev_mode && config->allocator == NULL) {
- config->allocator = _PyMem_RawStrdup("debug");
- if (config->allocator == NULL) {
- return _Py_INIT_NO_MEMORY();
- }
- }
-
if (config->allocator == NULL) {
+ /* bpo-34247. The PYTHONMALLOC environment variable has the priority
+ over PYTHONDEV env var and "-X dev" command line option.
+ For example, PYTHONMALLOC=malloc PYTHONDEVMODE=1 sets the memory
+ allocators to "malloc" (and not to "debug"). */
const char *allocator = _PyPreConfig_GetEnv(config, "PYTHONMALLOC");
if (allocator) {
config->allocator = _PyMem_RawStrdup(allocator);
@@ -462,6 +459,13 @@ preconfig_read(_PyPreConfig *config, const _PyPreCmdline *cmdline)
}
}
+ if (config->dev_mode && config->allocator == NULL) {
+ config->allocator = _PyMem_RawStrdup("debug");
+ if (config->allocator == NULL) {
+ return _Py_INIT_NO_MEMORY();
+ }
+ }
+
assert(config->coerce_c_locale >= 0);
assert(config->utf8_mode >= 0);
assert(config->isolated >= 0);