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].
This commit is contained in:
Victor Stinner 2019-03-19 16:09:27 +01:00 committed by GitHub
parent f5f336a819
commit dcf617152e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 52 additions and 29 deletions

View file

@ -780,18 +780,20 @@ pymain_run_python(PyInterpreterState *interp, int *exitcode)
}
}
else if (!config->preconfig.isolated) {
PyObject *path0 = _PyPathConfig_ComputeArgv0(&config->argv);
if (path0 == NULL) {
err = _Py_INIT_NO_MEMORY();
goto done;
}
PyObject *path0 = NULL;
if (_PyPathConfig_ComputeSysPath0(&config->argv, &path0)) {
if (path0 == NULL) {
err = _Py_INIT_NO_MEMORY();
goto done;
}
if (pymain_sys_path_add_path0(interp, path0) < 0) {
if (pymain_sys_path_add_path0(interp, path0) < 0) {
Py_DECREF(path0);
err = _Py_INIT_EXIT(1);
goto done;
}
Py_DECREF(path0);
err = _Py_INIT_EXIT(1);
goto done;
}
Py_DECREF(path0);
}
PyCompilerFlags cf = {.cf_flags = 0, .cf_feature_version = PY_MINOR_VERSION};