summaryrefslogtreecommitdiff
path: root/Modules/getpath.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2017-12-01 20:09:52 +0100
committerGitHub <noreply@github.com>2017-12-01 20:09:52 +0100
commitebac19dad6263141d5db0a2c923efe049dba99d2 (patch)
tree9dd0111510cfc339f2e88c24592d04bf11e0a17b /Modules/getpath.c
parent9ac3d8882712c9675c3d2f9f84af6b5729575cde (diff)
downloadcpython-git-ebac19dad6263141d5db0a2c923efe049dba99d2.tar.gz
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/getpath.c')
-rw-r--r--Modules/getpath.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/Modules/getpath.c b/Modules/getpath.c
index 183717d817..235badab23 100644
--- a/Modules/getpath.c
+++ b/Modules/getpath.c
@@ -625,11 +625,13 @@ calculate_program_full_path(const _PyMainInterpreterConfig *main_config,
else if(0 == _NSGetExecutablePath(execpath, &nsexeclength) &&
execpath[0] == SEP)
{
- size_t r = mbstowcs(program_full_path, execpath, MAXPATHLEN+1);
- if (r == (size_t)-1 || r > MAXPATHLEN) {
- /* Could not convert execpath, or it's too long. */
- program_full_path[0] = '\0';
+ size_t len;
+ wchar_t *path = Py_DecodeLocale(execpath, &len);
+ if (path == NULL) {
+ return DECODE_LOCALE_ERR("executable path", len);
}
+ wcsncpy(program_full_path, path, MAXPATHLEN);
+ PyMem_RawFree(path);
}
#endif /* __APPLE__ */
else if (calculate->path_env) {