bpo-36142: Add _PyPreConfig.allocator (GH-12181)

* Move 'allocator' and 'dev_mode' fields from _PyCoreConfig
  to _PyPreConfig.
* Fix InitConfigTests of test_embed: dev_mode sets allocator to
  "debug", add a new tests for env vars with dev mode enabled.
This commit is contained in:
Victor Stinner 2019-03-05 17:37:44 +01:00 committed by GitHub
parent 359a2f3dab
commit b35be4b333
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 129 additions and 53 deletions

View file

@ -437,7 +437,7 @@ static int test_init_from_config(void)
config.hash_seed = 123;
putenv("PYTHONMALLOC=malloc");
config.allocator = "malloc_debug";
config.preconfig.allocator = "malloc_debug";
/* dev_mode=1 is tested in test_init_dev_mode() */
@ -577,7 +577,6 @@ static void test_init_env_putenvs(void)
putenv("PYTHONPYCACHEPREFIX=env_pycache_prefix");
putenv("PYTHONNOUSERSITE=1");
putenv("PYTHONFAULTHANDLER=1");
putenv("PYTHONDEVMODE=1");
putenv("PYTHONIOENCODING=iso8859-1:replace");
/* FIXME: test PYTHONWARNINGS */
/* FIXME: test PYTHONEXECUTABLE */
@ -589,6 +588,15 @@ static void test_init_env_putenvs(void)
}
static void test_init_env_dev_mode_putenvs(void)
{
test_init_env_putenvs();
putenv("PYTHONMALLOC=malloc");
putenv("PYTHONFAULTHANDLER=");
putenv("PYTHONDEVMODE=1");
}
static int test_init_env(void)
{
/* Test initialization from environment variables */
@ -601,6 +609,18 @@ static int test_init_env(void)
}
static int test_init_env_dev_mode(void)
{
/* Test initialization from environment variables */
Py_IgnoreEnvironmentFlag = 0;
test_init_env_dev_mode_putenvs();
_testembed_Py_Initialize();
dump_config();
Py_Finalize();
return 0;
}
static int test_init_isolated(void)
{
/* Test _PyCoreConfig.isolated=1 */
@ -615,7 +635,7 @@ static int test_init_isolated(void)
/* Use path starting with "./" avoids a search along the PATH */
config.program_name = L"./_testembed";
test_init_env_putenvs();
test_init_env_dev_mode_putenvs();
_PyInitError err = _Py_InitializeFromConfig(&config);
if (_Py_INIT_FAILED(err)) {
_Py_ExitInitError(err);
@ -631,7 +651,7 @@ static int test_init_dev_mode(void)
_PyCoreConfig config = _PyCoreConfig_INIT;
putenv("PYTHONFAULTHANDLER=");
putenv("PYTHONMALLOC=");
config.dev_mode = 1;
config.preconfig.dev_mode = 1;
config.program_name = L"./_testembed";
_PyInitError err = _Py_InitializeFromConfig(&config);
if (_Py_INIT_FAILED(err)) {
@ -673,6 +693,7 @@ static struct TestCase TestCases[] = {
{ "init_global_config", test_init_global_config },
{ "init_from_config", test_init_from_config },
{ "init_env", test_init_env },
{ "init_env_dev_mode", test_init_env_dev_mode },
{ "init_dev_mode", test_init_dev_mode },
{ "init_isolated", test_init_isolated },
{ NULL, NULL }