summaryrefslogtreecommitdiffstats
path: root/Modules/main.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2017-12-01 19:09:52 (GMT)
committerGitHub <noreply@github.com>2017-12-01 19:09:52 (GMT)
commitebac19dad6263141d5db0a2c923efe049dba99d2 (patch)
tree9dd0111510cfc339f2e88c24592d04bf11e0a17b /Modules/main.c
parent9ac3d8882712c9675c3d2f9f84af6b5729575cde (diff)
downloadcpython-ebac19dad6263141d5db0a2c923efe049dba99d2.zip
cpython-ebac19dad6263141d5db0a2c923efe049dba99d2.tar.gz
cpython-ebac19dad6263141d5db0a2c923efe049dba99d2.tar.bz2
bpo-32030: Don't call _PyPathConfig_Fini() in Py_FinalizeEx() (#4667)
Changes: * _PyPathConfig_Fini() cannot be called in Py_FinalizeEx(). Py_Initialize() and Py_Finalize() can be called multiple times, but it must not "forget" parameters set by Py_SetProgramName(), Py_SetPath() or Py_SetPythonHome(), whereas _PyPathConfig_Fini() clear all these parameters. * config_get_program_name() and calculate_program_full_path() now also decode paths using Py_DecodeLocale() to use the surrogateescape error handler, rather than decoding using mbstowcs() which is strict. * Change _Py_CheckPython3() prototype: () => (void) * Truncate a few lines which were too long
Diffstat (limited to 'Modules/main.c')
-rw-r--r--Modules/main.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/Modules/main.c b/Modules/main.c
index caec97f..4659c5d 100644
--- a/Modules/main.c
+++ b/Modules/main.c
@@ -888,15 +888,12 @@ config_get_program_name(_PyMainInterpreterConfig *config)
See Lib/plat-mac/bundlebuiler.py for details about the bootstrap
script. */
if ((p = Py_GETENV("PYTHONEXECUTABLE")) && *p != '\0') {
- wchar_t* buffer;
- size_t len = strlen(p) + 1;
-
- buffer = PyMem_RawMalloc(len * sizeof(wchar_t));
- if (buffer == NULL) {
- return _Py_INIT_NO_MEMORY();
+ size_t len;
+ wchar_t* program_name = Py_DecodeLocale(p, &len);
+ if (program_name == NULL) {
+ return SET_DECODE_ERROR("PYTHONEXECUTABLE environment "
+ "variable", len);
}
-
- mbstowcs(buffer, p, len);
pymain->config.program_name = buffer;
}
#ifdef WITH_NEXT_FRAMEWORK
@@ -907,11 +904,12 @@ config_get_program_name(_PyMainInterpreterConfig *config)
* the argv0 of the stub executable
*/
size_t len;
- wchar_t* wbuf = Py_DecodeLocale(pyvenv_launcher, &len);
- if (wbuf == NULL) {
- return SET_DECODE_ERROR("__PYVENV_LAUNCHER__", len);
+ wchar_t* program_name = Py_DecodeLocale(pyvenv_launcher, &len);
+ if (program_name == NULL) {
+ return SET_DECODE_ERROR("__PYVENV_LAUNCHER__ environment "
+ "variable", len);
}
- pymain->config.program_name = wbuf;
+ pymain->config.program_name = program_name;
}
}
#endif /* WITH_NEXT_FRAMEWORK */
@@ -1666,6 +1664,14 @@ pymain_impl(_PyMain *pymain)
other special meaning */
pymain->status = 120;
}
+
+ /* _PyPathConfig_Fini() cannot be called in Py_FinalizeEx().
+ Py_Initialize() and Py_Finalize() can be called multiple times, but it
+ must not "forget" parameters set by Py_SetProgramName(), Py_SetPath() or
+ Py_SetPythonHome(), whereas _PyPathConfig_Fini() clear all these
+ parameters. */
+ _PyPathConfig_Fini();
+
return 0;
}