aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python
diff options
context:
space:
mode:
Diffstat (limited to 'Python')
-rw-r--r--Python/initconfig.c3
-rw-r--r--Python/pylifecycle.c25
2 files changed, 28 insertions, 0 deletions
diff --git a/Python/initconfig.c b/Python/initconfig.c
index 089ede4623e..6b76b4dc681 100644
--- a/Python/initconfig.c
+++ b/Python/initconfig.c
@@ -97,6 +97,7 @@ static const PyConfigSpec PYCONFIG_SPEC[] = {
SPEC(pythonpath_env, WSTR_OPT),
SPEC(home, WSTR_OPT),
SPEC(platlibdir, WSTR),
+ SPEC(sys_path_0, WSTR_OPT),
SPEC(module_search_paths_set, UINT),
SPEC(module_search_paths, WSTR_LIST),
SPEC(stdlib_dir, WSTR_OPT),
@@ -770,6 +771,7 @@ PyConfig_Clear(PyConfig *config)
CLEAR(config->exec_prefix);
CLEAR(config->base_exec_prefix);
CLEAR(config->platlibdir);
+ CLEAR(config->sys_path_0);
CLEAR(config->filesystem_encoding);
CLEAR(config->filesystem_errors);
@@ -3051,6 +3053,7 @@ _Py_DumpPathConfig(PyThreadState *tstate)
PySys_WriteStderr(" import site = %i\n", config->site_import);
PySys_WriteStderr(" is in build tree = %i\n", config->_is_python_build);
DUMP_CONFIG("stdlib dir", stdlib_dir);
+ DUMP_CONFIG("sys.path[0]", sys_path_0);
#undef DUMP_CONFIG
#define DUMP_SYS(NAME) \
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index f3ed77e5162..c0323763f44 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -1209,6 +1209,31 @@ init_interp_main(PyThreadState *tstate)
}
}
+ if (!is_main_interp) {
+ // The main interpreter is handled in Py_Main(), for now.
+ if (config->sys_path_0 != NULL) {
+ PyObject *path0 = PyUnicode_FromWideChar(config->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();