diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-03-19 15:09:27 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-19 15:09:27 (GMT) |
commit | dcf617152e1d4c4a5e7965733928858a9c0936ca (patch) | |
tree | 61c2ce7f9a4bcb8a1f48efb1a24b0f50d4029372 /Python/sysmodule.c | |
parent | f5f336a819a3d881bb217bf8f9b5cacba03a4e45 (diff) | |
download | cpython-dcf617152e1d4c4a5e7965733928858a9c0936ca.zip cpython-dcf617152e1d4c4a5e7965733928858a9c0936ca.tar.gz cpython-dcf617152e1d4c4a5e7965733928858a9c0936ca.tar.bz2 |
bpo-36236: Handle removed cwd at Python init (GH-12424)
At Python initialization, the current directory is no longer
prepended to sys.path if it has been removed.
Rename _PyPathConfig_ComputeArgv0() to
_PyPathConfig_ComputeSysPath0() to avoid confusion between argv[0]
and sys.path[0].
Diffstat (limited to 'Python/sysmodule.c')
-rw-r--r-- | Python/sysmodule.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c index b3330a01..4351a7f 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -2781,19 +2781,21 @@ PySys_SetArgvEx(int argc, wchar_t **argv, int updatepath) /* If argv[0] is not '-c' nor '-m', prepend argv[0] to sys.path. If argv[0] is a symlink, use the real path. */ const _PyWstrList argv_list = {.length = argc, .items = argv}; - PyObject *argv0 = _PyPathConfig_ComputeArgv0(&argv_list); - if (argv0 == NULL) { - Py_FatalError("can't compute path0 from argv"); - } + PyObject *path0 = NULL; + if (_PyPathConfig_ComputeSysPath0(&argv_list, &path0)) { + if (path0 == NULL) { + Py_FatalError("can't compute path0 from argv"); + } - PyObject *sys_path = _PySys_GetObjectId(&PyId_path); - if (sys_path != NULL) { - if (PyList_Insert(sys_path, 0, argv0) < 0) { - Py_DECREF(argv0); - Py_FatalError("can't prepend path0 to sys.path"); + PyObject *sys_path = _PySys_GetObjectId(&PyId_path); + if (sys_path != NULL) { + if (PyList_Insert(sys_path, 0, path0) < 0) { + Py_DECREF(path0); + Py_FatalError("can't prepend path0 to sys.path"); + } } + Py_DECREF(path0); } - Py_DECREF(argv0); } } |