diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-05-22 23:58:50 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-22 23:58:50 +0200 |
commit | 022be02dcfdfd9011415804bb4553a33fa7ec8f3 (patch) | |
tree | 6c4f3b4afed8475e6504786cb176044eade9ef02 /Programs | |
parent | bpo-36829: Add test.support.catch_unraisable_exception() (GH-13490) (diff) | |
download | cpython-022be02dcfdfd9011415804bb4553a33fa7ec8f3.tar.gz cpython-022be02dcfdfd9011415804bb4553a33fa7ec8f3.tar.bz2 cpython-022be02dcfdfd9011415804bb4553a33fa7ec8f3.zip |
bpo-36763: Add _PyPreConfig._config_init (GH-13481)
* _PyPreConfig_GetGlobalConfig() and _PyCoreConfig_GetGlobalConfig()
now do nothing if the configuration was not initialized with
_PyPreConfig_InitCompatConfig() and _PyCoreConfig_InitCompatConfig()
* Remove utf8_mode=-2 special case: use utf8_mode=-1 instead.
* Fix _PyPreConfig_InitPythonConfig():
* isolated = 0 instead of -1
* use_environment = 1 instead of -1
* Rename _PyConfig_INIT to _PyConfig_INIT_COMPAT
* Rename _PyPreConfig_Init() to _PyPreConfig_InitCompatConfig()
* Rename _PyCoreConfig_Init() to _PyCoreConfig_InitCompatConfig()
* PyInterpreterState_New() now uses _PyCoreConfig_InitPythonConfig()
as default configuration, but it's very quickly overriden anyway.
* _freeze_importlib.c uses _PyCoreConfig_SetString() to set
program_name.
* Cleanup preconfig_init_utf8_mode(): cmdline is always non-NULL.
Diffstat (limited to 'Programs')
-rw-r--r-- | Programs/_freeze_importlib.c | 22 | ||||
-rw-r--r-- | Programs/_testembed.c | 61 |
2 files changed, 70 insertions, 13 deletions
diff --git a/Programs/_freeze_importlib.c b/Programs/_freeze_importlib.c index 1a719e2f967..8cf44d33bc0 100644 --- a/Programs/_freeze_importlib.c +++ b/Programs/_freeze_importlib.c @@ -76,18 +76,30 @@ main(int argc, char *argv[]) } text[text_size] = '\0'; + _PyInitError err; _PyCoreConfig config; - _PyCoreConfig_InitIsolatedConfig(&config); + + err = _PyCoreConfig_InitIsolatedConfig(&config); + if (_PyInitError_Failed(err)) { + _PyCoreConfig_Clear(&config); + _Py_ExitInitError(err); + } config.site_import = 0; - config.program_name = L"./_freeze_importlib"; + + err = _PyCoreConfig_SetString(&config, &config.program_name, + L"./_freeze_importlib"); + if (_PyInitError_Failed(err)) { + _PyCoreConfig_Clear(&config); + _Py_ExitInitError(err); + } + /* Don't install importlib, since it could execute outdated bytecode. */ config._install_importlib = 0; config._init_main = 0; - _PyInitError err = _Py_InitializeFromConfig(&config); - /* No need to call _PyCoreConfig_Clear() since we didn't allocate any - memory: program_name is a constant string. */ + err = _Py_InitializeFromConfig(&config); + _PyCoreConfig_Clear(&config); if (_PyInitError_Failed(err)) { _Py_ExitInitError(err); } diff --git a/Programs/_testembed.c b/Programs/_testembed.c index bc549369393..a273930e10a 100644 --- a/Programs/_testembed.c +++ b/Programs/_testembed.c @@ -317,7 +317,7 @@ dump_config(void) } -static int test_init_default_config(void) +static int test_init_initialize_config(void) { _testembed_Py_Initialize(); dump_config(); @@ -326,6 +326,47 @@ static int test_init_default_config(void) } +static int check_init_compat_config(int preinit) +{ + _PyInitError err; + + if (preinit) { + _PyPreConfig preconfig; + _PyPreConfig_InitCompatConfig(&preconfig); + + err = _Py_PreInitialize(&preconfig); + if (_PyInitError_Failed(err)) { + _Py_ExitInitError(err); + } + } + + _PyCoreConfig config; + _PyCoreConfig_InitCompatConfig(&config); + config.program_name = L"./_testembed"; + + err = _Py_InitializeFromConfig(&config); + if (_PyInitError_Failed(err)) { + _Py_ExitInitError(err); + } + + dump_config(); + Py_Finalize(); + return 0; +} + + +static int test_preinit_compat_config(void) +{ + return check_init_compat_config(1); +} + + +static int test_init_compat_config(void) +{ + return check_init_compat_config(0); +} + + static int test_init_global_config(void) { /* FIXME: test Py_IgnoreEnvironmentFlag */ @@ -380,7 +421,7 @@ static int test_init_from_config(void) _PyInitError err; _PyPreConfig preconfig; - _PyPreConfig_Init(&preconfig); + _PyPreConfig_InitCompatConfig(&preconfig); putenv("PYTHONMALLOC=malloc_debug"); preconfig.allocator = PYMEM_ALLOCATOR_MALLOC; @@ -396,7 +437,7 @@ static int test_init_from_config(void) /* Test _Py_InitializeFromConfig() */ _PyCoreConfig config; - _PyCoreConfig_Init(&config); + _PyCoreConfig_InitCompatConfig(&config); config.install_signal_handlers = 0; /* FIXME: test use_environment */ @@ -676,7 +717,7 @@ static int test_preinit_isolated1(void) _PyInitError err; _PyPreConfig preconfig; - _PyPreConfig_Init(&preconfig); + _PyPreConfig_InitCompatConfig(&preconfig); preconfig.isolated = 1; err = _Py_PreInitialize(&preconfig); @@ -685,7 +726,7 @@ static int test_preinit_isolated1(void) } _PyCoreConfig config; - _PyCoreConfig_Init(&config); + _PyCoreConfig_InitCompatConfig(&config); config.program_name = L"./_testembed"; set_all_env_vars(); @@ -705,7 +746,7 @@ static int test_preinit_isolated2(void) _PyInitError err; _PyPreConfig preconfig; - _PyPreConfig_Init(&preconfig); + _PyPreConfig_InitCompatConfig(&preconfig); preconfig.isolated = 0; err = _Py_PreInitialize(&preconfig); @@ -715,7 +756,7 @@ static int test_preinit_isolated2(void) /* Test _PyCoreConfig.isolated=1 */ _PyCoreConfig config; - _PyCoreConfig_Init(&config); + _PyCoreConfig_InitCompatConfig(&config); Py_IsolatedFlag = 0; config.isolated = 1; @@ -885,12 +926,14 @@ static int check_preinit_isolated_config(int preinit) _PyCoreConfig config; err = _PyCoreConfig_InitIsolatedConfig(&config); if (_PyInitError_Failed(err)) { + _PyCoreConfig_Clear(&config); _Py_ExitInitError(err); } config.program_name = L"./_testembed"; err = _Py_InitializeFromConfig(&config); if (_PyInitError_Failed(err)) { + _PyCoreConfig_Clear(&config); _Py_ExitInitError(err); } @@ -1207,7 +1250,9 @@ static struct TestCase TestCases[] = { { "bpo20891", test_bpo20891 }, { "initialize_twice", test_initialize_twice }, { "initialize_pymain", test_initialize_pymain }, - { "init_default_config", test_init_default_config }, + { "init_initialize_config", test_init_initialize_config }, + { "preinit_compat_config", test_preinit_compat_config }, + { "init_compat_config", test_init_compat_config }, { "init_global_config", test_init_global_config }, { "init_from_config", test_init_from_config }, { "init_parse_argv", test_init_parse_argv }, |