Skip to content

Commit aa73965

Browse files
vstinnerlisroach
authored andcommitted
bpo-36763: Use PyConfig_Clear() (pythonGH-14445)
Stop using "static PyConfig", PyConfig must now always use dynamically allocated strings: use PyConfig_SetString(), PyConfig_SetArgv() and PyConfig_Clear().
1 parent 6f4928e commit aa73965

File tree

4 files changed

+151
-186
lines changed

4 files changed

+151
-186
lines changed

Lib/test/test_embed.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -695,10 +695,19 @@ def test_init_from_config(self):
695695

696696
'pycache_prefix': 'conf_pycache_prefix',
697697
'program_name': './conf_program_name',
698-
'argv': ['-c', 'arg2'],
698+
'argv': ['-c', 'arg2', ],
699699
'parse_argv': 1,
700-
'xoptions': ['xoption1=3', 'xoption2=', 'xoption3'],
701-
'warnoptions': ['error::ResourceWarning', 'default::BytesWarning'],
700+
'xoptions': [
701+
'config_xoption1=3',
702+
'config_xoption2=',
703+
'config_xoption3',
704+
'cmdline_xoption',
705+
],
706+
'warnoptions': [
707+
'config_warnoption',
708+
'cmdline_warnoption',
709+
'default::BytesWarning',
710+
],
702711
'run_command': 'pass\n',
703712

704713
'site_import': 0,

Modules/main.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pymain_init(const _PyArgv *args)
6262
PyConfig config;
6363
status = PyConfig_InitPythonConfig(&config);
6464
if (_PyStatus_EXCEPTION(status)) {
65-
return status;
65+
goto done;
6666
}
6767

6868
/* pass NULL as the config: config is read from command line arguments,
@@ -74,14 +74,18 @@ pymain_init(const _PyArgv *args)
7474
status = PyConfig_SetArgv(&config, args->argc, args->wchar_argv);
7575
}
7676
if (_PyStatus_EXCEPTION(status)) {
77-
return status;
77+
goto done;
7878
}
7979

8080
status = Py_InitializeFromConfig(&config);
8181
if (_PyStatus_EXCEPTION(status)) {
82-
return status;
82+
goto done;
8383
}
84-
return _PyStatus_OK();
84+
status = _PyStatus_OK();
85+
86+
done:
87+
PyConfig_Clear(&config);
88+
return status;
8589
}
8690

8791

Programs/_freeze_importlib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ main(int argc, char *argv[])
8888
config.site_import = 0;
8989

9090
status = PyConfig_SetString(&config, &config.program_name,
91-
L"./_freeze_importlib");
91+
L"./_freeze_importlib");
9292
if (PyStatus_Exception(status)) {
9393
PyConfig_Clear(&config);
9494
Py_ExitStatusException(status);

0 commit comments

Comments
 (0)