mirror of
https://github.com/python/cpython.git
synced 2025-09-02 23:18:25 +00:00
bpo-42260: Main init modify sys.flags in-place (GH-23150)
When Py_Initialize() is called twice, the second call now updates more sys attributes for the configuration, rather than only sys.argv. * Rename _PySys_InitMain() to _PySys_UpdateConfig(). * _PySys_UpdateConfig() now modifies sys.flags in-place, instead of creating a new flags object. * Remove old commented sys.flags flags (unbuffered and skip_first). * Add private _PySys_GetObject() function. * When Py_Initialize(), Py_InitializeFromConfig() and
This commit is contained in:
parent
58ca33b467
commit
af1d64d9f7
4 changed files with 90 additions and 75 deletions
|
@ -949,19 +949,10 @@ done:
|
|||
configuration. Example of bpo-34008: Py_Main() called after
|
||||
Py_Initialize(). */
|
||||
static PyStatus
|
||||
_Py_ReconfigureMainInterpreter(PyThreadState *tstate)
|
||||
pyinit_main_reconfigure(PyThreadState *tstate)
|
||||
{
|
||||
const PyConfig *config = _PyInterpreterState_GetConfig(tstate->interp);
|
||||
|
||||
PyObject *argv = _PyWideStringList_AsList(&config->argv);
|
||||
if (argv == NULL) {
|
||||
return _PyStatus_NO_MEMORY(); \
|
||||
}
|
||||
|
||||
int res = PyDict_SetItemString(tstate->interp->sysdict, "argv", argv);
|
||||
Py_DECREF(argv);
|
||||
if (res < 0) {
|
||||
return _PyStatus_ERR("fail to set sys.argv");
|
||||
if (_PySys_UpdateConfig(tstate) < 0) {
|
||||
return _PyStatus_ERR("fail to update sys for the new conf");
|
||||
}
|
||||
return _PyStatus_OK();
|
||||
}
|
||||
|
@ -995,7 +986,7 @@ init_interp_main(PyThreadState *tstate)
|
|||
}
|
||||
}
|
||||
|
||||
if (_PySys_InitMain(tstate) < 0) {
|
||||
if (_PySys_UpdateConfig(tstate) < 0) {
|
||||
return _PyStatus_ERR("can't finish initializing sys");
|
||||
}
|
||||
|
||||
|
@ -1100,7 +1091,7 @@ pyinit_main(PyThreadState *tstate)
|
|||
}
|
||||
|
||||
if (interp->runtime->initialized) {
|
||||
return _Py_ReconfigureMainInterpreter(tstate);
|
||||
return pyinit_main_reconfigure(tstate);
|
||||
}
|
||||
|
||||
PyStatus status = init_interp_main(tstate);
|
||||
|
@ -1111,19 +1102,6 @@ pyinit_main(PyThreadState *tstate)
|
|||
}
|
||||
|
||||
|
||||
PyStatus
|
||||
_Py_InitializeMain(void)
|
||||
{
|
||||
PyStatus status = _PyRuntime_Initialize();
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
_PyRuntimeState *runtime = &_PyRuntime;
|
||||
PyThreadState *tstate = _PyRuntimeState_GetThreadState(runtime);
|
||||
return pyinit_main(tstate);
|
||||
}
|
||||
|
||||
|
||||
PyStatus
|
||||
Py_InitializeFromConfig(const PyConfig *config)
|
||||
{
|
||||
|
@ -1191,6 +1169,19 @@ Py_Initialize(void)
|
|||
}
|
||||
|
||||
|
||||
PyStatus
|
||||
_Py_InitializeMain(void)
|
||||
{
|
||||
PyStatus status = _PyRuntime_Initialize();
|
||||
if (_PyStatus_EXCEPTION(status)) {
|
||||
return status;
|
||||
}
|
||||
_PyRuntimeState *runtime = &_PyRuntime;
|
||||
PyThreadState *tstate = _PyRuntimeState_GetThreadState(runtime);
|
||||
return pyinit_main(tstate);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
finalize_modules_delete_special(PyThreadState *tstate, int verbose)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue