bpo-36142: PYTHONMALLOC overrides PYTHONDEV (GH-12191) · python/cpython@25d13f3 · GitHub
Skip to content

Commit 25d13f3

Browse files
authored
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.
1 parent 01e0f43 commit 25d13f3

3 files changed

Lines changed: 40 additions & 16 deletions

File tree

Lib/test/test_embed.py

Lines changed: 8 additions & 2 deletions

Programs/_testembed.c

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,8 @@ static int test_init_from_config(void)
442442
config.use_hash_seed = 1;
443443
config.hash_seed = 123;
444444

445-
putenv("PYTHONMALLOC=malloc");
446-
config.preconfig.allocator = "malloc_debug";
445+
putenv("PYTHONMALLOC=malloc_debug");
446+
config.preconfig.allocator = "malloc";
447447

448448
/* dev_mode=1 is tested in test_init_dev_mode() */
449449

@@ -570,7 +570,7 @@ static int test_init_from_config(void)
570570
static void test_init_env_putenvs(void)
571571
{
572572
putenv("PYTHONHASHSEED=42");
573-
putenv("PYTHONMALLOC=malloc_debug");
573+
putenv("PYTHONMALLOC=malloc");
574574
putenv("PYTHONTRACEMALLOC=2");
575575
putenv("PYTHONPROFILEIMPORTTIME=1");
576576
putenv("PYTHONMALLOCSTATS=1");
@@ -594,32 +594,45 @@ static void test_init_env_putenvs(void)
594594
}
595595

596596

597+
static int test_init_env(void)
598+
{
599+
/* Test initialization from environment variables */
600+
Py_IgnoreEnvironmentFlag = 0;
601+
test_init_env_putenvs();
602+
_testembed_Py_Initialize();
603+
dump_config();
604+
Py_Finalize();
605+
return 0;
606+
}
607+
608+
597609
static void test_init_env_dev_mode_putenvs(void)
598610
{
599611
test_init_env_putenvs();
600-
putenv("PYTHONMALLOC=malloc");
612+
putenv("PYTHONMALLOC=");
601613
putenv("PYTHONFAULTHANDLER=");
602614
putenv("PYTHONDEVMODE=1");
603615
}
604616

605617

606-
static int test_init_env(void)
618+
static int test_init_env_dev_mode(void)
607619
{
608620
/* Test initialization from environment variables */
609621
Py_IgnoreEnvironmentFlag = 0;
610-
test_init_env_putenvs();
622+
test_init_env_dev_mode_putenvs();
611623
_testembed_Py_Initialize();
612624
dump_config();
613625
Py_Finalize();
614626
return 0;
615627
}
616628

617629

618-
static int test_init_env_dev_mode(void)
630+
static int test_init_env_dev_mode_alloc(void)
619631
{
620632
/* Test initialization from environment variables */
621633
Py_IgnoreEnvironmentFlag = 0;
622634
test_init_env_dev_mode_putenvs();
635+
putenv("PYTHONMALLOC=malloc");
623636
_testembed_Py_Initialize();
624637
dump_config();
625638
Py_Finalize();
@@ -700,6 +713,7 @@ static struct TestCase TestCases[] = {
700713
{ "init_from_config", test_init_from_config },
701714
{ "init_env", test_init_env },
702715
{ "init_env_dev_mode", test_init_env_dev_mode },
716+
{ "init_env_dev_mode_alloc", test_init_env_dev_mode_alloc },
703717
{ "init_dev_mode", test_init_dev_mode },
704718
{ "init_isolated", test_init_isolated },
705719
{ NULL, NULL }

Python/preconfig.c

Lines changed: 11 additions & 7 deletions

0 commit comments

Comments
 (0)