Commit 67310023 authored by Victor Stinner's avatar Victor Stinner Committed by GitHub

bpo-36763: Use PyConfig_Clear() (GH-14445)

Stop using "static PyConfig", PyConfig must now always use
dynamically allocated strings: use PyConfig_SetString(),
PyConfig_SetArgv() and PyConfig_Clear().
parent e6b64b75
...@@ -695,10 +695,19 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): ...@@ -695,10 +695,19 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
'pycache_prefix': 'conf_pycache_prefix', 'pycache_prefix': 'conf_pycache_prefix',
'program_name': './conf_program_name', 'program_name': './conf_program_name',
'argv': ['-c', 'arg2'], 'argv': ['-c', 'arg2', ],
'parse_argv': 1, 'parse_argv': 1,
'xoptions': ['xoption1=3', 'xoption2=', 'xoption3'], 'xoptions': [
'warnoptions': ['error::ResourceWarning', 'default::BytesWarning'], 'config_xoption1=3',
'config_xoption2=',
'config_xoption3',
'cmdline_xoption',
],
'warnoptions': [
'config_warnoption',
'cmdline_warnoption',
'default::BytesWarning',
],
'run_command': 'pass\n', 'run_command': 'pass\n',
'site_import': 0, 'site_import': 0,
......
...@@ -62,7 +62,7 @@ pymain_init(const _PyArgv *args) ...@@ -62,7 +62,7 @@ pymain_init(const _PyArgv *args)
PyConfig config; PyConfig config;
status = PyConfig_InitPythonConfig(&config); status = PyConfig_InitPythonConfig(&config);
if (_PyStatus_EXCEPTION(status)) { if (_PyStatus_EXCEPTION(status)) {
return status; goto done;
} }
/* pass NULL as the config: config is read from command line arguments, /* pass NULL as the config: config is read from command line arguments,
...@@ -74,14 +74,18 @@ pymain_init(const _PyArgv *args) ...@@ -74,14 +74,18 @@ pymain_init(const _PyArgv *args)
status = PyConfig_SetArgv(&config, args->argc, args->wchar_argv); status = PyConfig_SetArgv(&config, args->argc, args->wchar_argv);
} }
if (_PyStatus_EXCEPTION(status)) { if (_PyStatus_EXCEPTION(status)) {
return status; goto done;
} }
status = Py_InitializeFromConfig(&config); status = Py_InitializeFromConfig(&config);
if (_PyStatus_EXCEPTION(status)) { if (_PyStatus_EXCEPTION(status)) {
return status; goto done;
} }
return _PyStatus_OK(); status = _PyStatus_OK();
done:
PyConfig_Clear(&config);
return status;
} }
......
...@@ -88,7 +88,7 @@ main(int argc, char *argv[]) ...@@ -88,7 +88,7 @@ main(int argc, char *argv[])
config.site_import = 0; config.site_import = 0;
status = PyConfig_SetString(&config, &config.program_name, status = PyConfig_SetString(&config, &config.program_name,
L"./_freeze_importlib"); L"./_freeze_importlib");
if (PyStatus_Exception(status)) { if (PyStatus_Exception(status)) {
PyConfig_Clear(&config); PyConfig_Clear(&config);
Py_ExitStatusException(status); Py_ExitStatusException(status);
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment