bpo-32030: Add _PyMainInterpreterConfig.warnoptions (#4855)

Add warnoptions and xoptions fields to _PyMainInterpreterConfig.
This commit is contained in:
Victor Stinner 2017-12-14 12:05:26 +01:00 committed by GitHub
parent 53f7a7c281
commit 374c6e178a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 105 additions and 48 deletions

View file

@ -830,6 +830,8 @@ _PyMainInterpreterConfig_Clear(_PyMainInterpreterConfig *config)
{
Py_CLEAR(config->argv);
Py_CLEAR(config->module_search_path);
Py_CLEAR(config->warnoptions);
Py_CLEAR(config->xoptions);
}
@ -883,10 +885,26 @@ _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)
return _Py_INIT_ERR("can't finish initializing sys");
@ -945,13 +963,6 @@ _Py_InitializeMainInterpreter(const _PyMainInterpreterConfig *config)
return err;
}
}
if (interp->config.argv != NULL) {
if (PySys_SetObject("argv", interp->config.argv) != 0) {
return _Py_INIT_ERR("can't assign sys.argv");
}
}
return _Py_INIT_OK();
}