mirror of
https://github.com/python/cpython.git
synced 2025-10-13 10:23:28 +00:00
[3.12] gh-109853: Fix sys.path[0] For Subinterpreters (gh-109994) (gh-110701)
This change makes sure sys.path[0] is set properly for subinterpreters. Before, it wasn't getting set at all.
This change does not address the broader concerns from gh-109853.
(cherry-picked from commit a040a32ea2
)
This commit is contained in:
parent
592a849fdf
commit
313554457e
7 changed files with 26702 additions and 26487 deletions
|
@ -1200,6 +1200,32 @@ init_interp_main(PyThreadState *tstate)
|
|||
#endif
|
||||
}
|
||||
|
||||
if (!is_main_interp) {
|
||||
// The main interpreter is handled in Py_Main(), for now.
|
||||
wchar_t *sys_path_0 = interp->runtime->sys_path_0;
|
||||
if (sys_path_0 != NULL) {
|
||||
PyObject *path0 = PyUnicode_FromWideChar(sys_path_0, -1);
|
||||
if (path0 == NULL) {
|
||||
return _PyStatus_ERR("can't initialize sys.path[0]");
|
||||
}
|
||||
PyObject *sysdict = interp->sysdict;
|
||||
if (sysdict == NULL) {
|
||||
Py_DECREF(path0);
|
||||
return _PyStatus_ERR("can't initialize sys.path[0]");
|
||||
}
|
||||
PyObject *sys_path = PyDict_GetItemWithError(sysdict, &_Py_ID(path));
|
||||
if (sys_path == NULL) {
|
||||
Py_DECREF(path0);
|
||||
return _PyStatus_ERR("can't initialize sys.path[0]");
|
||||
}
|
||||
int res = PyList_Insert(sys_path, 0, path0);
|
||||
Py_DECREF(path0);
|
||||
if (res) {
|
||||
return _PyStatus_ERR("can't initialize sys.path[0]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert(!_PyErr_Occurred(tstate));
|
||||
|
||||
return _PyStatus_OK();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue