diff options
author | Victor Stinner <vstinner@python.org> | 2020-11-04 23:45:56 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-04 23:45:56 (GMT) |
commit | 048a35659aa8074afe7d7d054e7cea1f8ee6d366 (patch) | |
tree | e9a019387bbd73cdbfcdceb76af7d21e15bc30d0 /Programs | |
parent | 100964e0310d3a2040d0db976f7984d0507b2dbd (diff) | |
download | cpython-048a35659aa8074afe7d7d054e7cea1f8ee6d366.zip cpython-048a35659aa8074afe7d7d054e7cea1f8ee6d366.tar.gz cpython-048a35659aa8074afe7d7d054e7cea1f8ee6d366.tar.bz2 |
bpo-42260: Add _PyInterpreterState_SetConfig() (GH-23158)
* Inline _PyInterpreterState_SetConfig(): replace it with
_PyConfig_Copy().
* Add _PyErr_SetFromPyStatus()
* Add _PyInterpreterState_GetConfigCopy()
* Add a new _PyInterpreterState_SetConfig() function.
* Add an unit which gets, modifies, and sets the config.
Diffstat (limited to 'Programs')
-rw-r--r-- | Programs/_testembed.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/Programs/_testembed.c b/Programs/_testembed.c index 5aad16a..cb3a23a 100644 --- a/Programs/_testembed.c +++ b/Programs/_testembed.c @@ -1526,6 +1526,55 @@ static int test_init_warnoptions(void) } +static int tune_config(void) +{ + PyConfig config; + PyConfig_InitPythonConfig(&config); + if (_PyInterpreterState_GetConfigCopy(&config) < 0) { + PyConfig_Clear(&config); + PyErr_Print(); + return -1; + } + + config.bytes_warning = 2; + + if (_PyInterpreterState_SetConfig(&config) < 0) { + PyConfig_Clear(&config); + return -1; + } + PyConfig_Clear(&config); + return 0; +} + + +static int test_set_config(void) +{ + // Initialize core + PyConfig config; + PyConfig_InitIsolatedConfig(&config); + config_set_string(&config, &config.program_name, PROGRAM_NAME); + config._init_main = 0; + config.bytes_warning = 0; + init_from_config_clear(&config); + + // Tune the configuration using _PyInterpreterState_SetConfig() + if (tune_config() < 0) { + PyErr_Print(); + return 1; + } + + // Finish initialization: main part + PyStatus status = _Py_InitializeMain(); + if (PyStatus_Exception(status)) { + Py_ExitStatusException(status); + } + + dump_config(); + Py_Finalize(); + return 0; +} + + static void configure_init_main(PyConfig *config) { wchar_t* argv[] = { @@ -1693,6 +1742,7 @@ static struct TestCase TestCases[] = { {"test_init_setpath_config", test_init_setpath_config}, {"test_init_setpythonhome", test_init_setpythonhome}, {"test_init_warnoptions", test_init_warnoptions}, + {"test_init_set_config", test_set_config}, {"test_run_main", test_run_main}, {"test_get_argc_argv", test_get_argc_argv}, |