summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2017-12-15 01:05:29 (GMT)
committerGitHub <noreply@github.com>2017-12-15 01:05:29 (GMT)
commit41264f1cd4d6066b2797ff07cae465c1e06ff3b2 (patch)
tree79949fe2a6d0a5cbe6bc33851c6b8e86e8340e2d /Python
parentda273412c4374de07a500e7f23f89a6bb7527398 (diff)
downloadcpython-41264f1cd4d6066b2797ff07cae465c1e06ff3b2.zip
cpython-41264f1cd4d6066b2797ff07cae465c1e06ff3b2.tar.gz
cpython-41264f1cd4d6066b2797ff07cae465c1e06ff3b2.tar.bz2
bpo-32030: Add _PyMainInterpreterConfig.executable (#4876)
* Add new fields to _PyMainInterpreterConfig: * executable * prefix * base_prefix * exec_prefix * base_exec_prefix * _PySys_EndInit() now sets sys attributes from _PyMainInterpreterConfig
Diffstat (limited to 'Python')
-rw-r--r--Python/pylifecycle.c32
-rw-r--r--Python/sysmodule.c43
2 files changed, 32 insertions, 43 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index 830f89d..8c62607 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -830,28 +830,7 @@ _Py_InitializeMainInterpreter(const _PyMainInterpreterConfig *config)
return _Py_INIT_ERR("can't initialize time");
}
- /* Set sys attributes */
- assert(interp->config.module_search_path != NULL);
- if (PySys_SetObject("path", interp->config.module_search_path) != 0) {
- return _Py_INIT_ERR("can't assign sys.path");
- }
- if (interp->config.argv != NULL) {
- if (PySys_SetObject("argv", interp->config.argv) != 0) {
- return _Py_INIT_ERR("can't assign sys.argv");
- }
- }
- if (interp->config.warnoptions != NULL) {
- if (PySys_SetObject("warnoptions", interp->config.warnoptions)) {
- return _Py_INIT_ERR("can't assign sys.warnoptions");
- }
- }
- if (interp->config.xoptions != NULL) {
- if (PySys_SetObject("_xoptions", interp->config.xoptions)) {
- return _Py_INIT_ERR("can't assign sys._xoptions");
- }
- }
-
- if (_PySys_EndInit(interp->sysdict) < 0) {
+ if (_PySys_EndInit(interp->sysdict, &interp->config) < 0) {
return _Py_INIT_ERR("can't finish initializing sys");
}
@@ -1314,12 +1293,6 @@ new_interpreter(PyThreadState **tstate_p)
return _Py_INIT_ERR("failed to copy main interpreter config");
}
- err = _PyPathConfig_Init(&interp->core_config);
- if (_Py_INIT_FAILED(err)) {
- return err;
- }
- wchar_t *sys_path = Py_GetPath();
-
/* XXX The following is lax in error checking */
PyObject *modules = PyDict_New();
if (modules == NULL) {
@@ -1334,8 +1307,7 @@ new_interpreter(PyThreadState **tstate_p)
goto handle_error;
Py_INCREF(interp->sysdict);
PyDict_SetItemString(interp->sysdict, "modules", modules);
- PySys_SetPath(sys_path);
- _PySys_EndInit(interp->sysdict);
+ _PySys_EndInit(interp->sysdict, &interp->config);
}
bimod = _PyImport_FindBuiltin("builtins", modules);
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index b33a316..24098b9 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -2212,7 +2212,6 @@ err_occurred:
}
#undef SET_SYS_FROM_STRING
-#undef SET_SYS_FROM_STRING_BORROW
/* Updating the sys namespace, returning integer error codes */
#define SET_SYS_FROM_STRING_INT_RESULT(key, value) \
@@ -2228,10 +2227,35 @@ err_occurred:
} while (0)
int
-_PySys_EndInit(PyObject *sysdict)
+_PySys_EndInit(PyObject *sysdict, _PyMainInterpreterConfig *config)
{
int res;
+ /* _PyMainInterpreterConfig_Read() must set all these variables */
+ assert(config->module_search_path != NULL);
+ assert(config->executable != NULL);
+ assert(config->prefix != NULL);
+ assert(config->base_prefix != NULL);
+ assert(config->exec_prefix != NULL);
+ assert(config->base_exec_prefix != NULL);
+
+ SET_SYS_FROM_STRING_BORROW("path", config->module_search_path);
+ SET_SYS_FROM_STRING_BORROW("executable", config->executable);
+ SET_SYS_FROM_STRING_BORROW("prefix", config->prefix);
+ SET_SYS_FROM_STRING_BORROW("base_prefix", config->base_prefix);
+ SET_SYS_FROM_STRING_BORROW("exec_prefix", config->exec_prefix);
+ SET_SYS_FROM_STRING_BORROW("base_exec_prefix", config->base_exec_prefix);
+
+ if (config->argv != NULL) {
+ SET_SYS_FROM_STRING_BORROW("argv", config->argv);
+ }
+ if (config->warnoptions != NULL) {
+ SET_SYS_FROM_STRING_BORROW("warnoptions", config->warnoptions);
+ }
+ if (config->xoptions != NULL) {
+ SET_SYS_FROM_STRING_BORROW("_xoptions", config->xoptions);
+ }
+
/* Set flags to their final values */
SET_SYS_FROM_STRING_INT_RESULT("flags", make_flags());
/* prevent user from creating new instances */
@@ -2247,17 +2271,6 @@ _PySys_EndInit(PyObject *sysdict)
SET_SYS_FROM_STRING_INT_RESULT("dont_write_bytecode",
PyBool_FromLong(Py_DontWriteBytecodeFlag));
- SET_SYS_FROM_STRING_INT_RESULT("executable",
- PyUnicode_FromWideChar(
- Py_GetProgramFullPath(), -1));
- SET_SYS_FROM_STRING_INT_RESULT("prefix",
- PyUnicode_FromWideChar(Py_GetPrefix(), -1));
- SET_SYS_FROM_STRING_INT_RESULT("exec_prefix",
- PyUnicode_FromWideChar(Py_GetExecPrefix(), -1));
- SET_SYS_FROM_STRING_INT_RESULT("base_prefix",
- PyUnicode_FromWideChar(Py_GetPrefix(), -1));
- SET_SYS_FROM_STRING_INT_RESULT("base_exec_prefix",
- PyUnicode_FromWideChar(Py_GetExecPrefix(), -1));
if (get_warnoptions() == NULL)
return -1;
@@ -2268,8 +2281,12 @@ _PySys_EndInit(PyObject *sysdict)
if (PyErr_Occurred())
return -1;
return 0;
+
+err_occurred:
+ return -1;
}
+#undef SET_SYS_FROM_STRING_BORROW
#undef SET_SYS_FROM_STRING_INT_RESULT
static PyObject *