diff options
author | Victor Stinner <vstinner@python.org> | 2019-11-22 18:24:49 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-22 18:24:49 (GMT) |
commit | 2582d46fbcf7bdf86b9cf4016850b8d155267ac6 (patch) | |
tree | 7ac19636e1def16e85485e159ec98a127abb12e2 /Python/pylifecycle.c | |
parent | 82c83bd907409c287a5bd0d0f4598f2c0538f34d (diff) | |
download | cpython-2582d46fbcf7bdf86b9cf4016850b8d155267ac6.zip cpython-2582d46fbcf7bdf86b9cf4016850b8d155267ac6.tar.gz cpython-2582d46fbcf7bdf86b9cf4016850b8d155267ac6.tar.bz2 |
bpo-38858: new_interpreter() reuses pycore_init_builtins() (GH-17351)
new_interpreter() now calls _PyBuiltin_Init() to create the builtins
module and calls _PyImport_FixupBuiltin(), rather than using
_PyImport_FindBuiltin(tstate, "builtins").
pycore_init_builtins() is now responsible to initialize
intepr->builtins_copy: inline _PyImport_Init() and remove this
function.
Diffstat (limited to 'Python/pylifecycle.c')
-rw-r--r-- | Python/pylifecycle.c | 53 |
1 files changed, 24 insertions, 29 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index e692d75..e63fb64 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -622,25 +622,36 @@ pycore_init_types(PyThreadState *tstate) static PyStatus pycore_init_builtins(PyThreadState *tstate) { - PyInterpreterState *interp = tstate->interp; - PyObject *bimod = _PyBuiltin_Init(tstate); if (bimod == NULL) { - return _PyStatus_ERR("can't initialize builtins modules"); + goto error; + } + + PyInterpreterState *interp = tstate->interp; + if (_PyImport_FixupBuiltin(bimod, "builtins", interp->modules) < 0) { + goto error; } - _PyImport_FixupBuiltin(bimod, "builtins", interp->modules); - interp->builtins = PyModule_GetDict(bimod); - if (interp->builtins == NULL) { - return _PyStatus_ERR("can't initialize builtins dict"); + PyObject *builtins_dict = PyModule_GetDict(bimod); + if (builtins_dict == NULL) { + goto error; } - Py_INCREF(interp->builtins); + Py_INCREF(builtins_dict); + interp->builtins = builtins_dict; PyStatus status = _PyBuiltins_AddExceptions(bimod); if (_PyStatus_EXCEPTION(status)) { return status; } + + interp->builtins_copy = PyDict_Copy(interp->builtins); + if (interp->builtins_copy == NULL) { + goto error; + } return _PyStatus_OK(); + +error: + return _PyStatus_ERR("can't initialize builtins module"); } @@ -649,12 +660,7 @@ pycore_init_import_warnings(PyThreadState *tstate, PyObject *sysmod) { const PyConfig *config = &tstate->interp->config; - PyStatus status = _PyImport_Init(tstate); - if (_PyStatus_EXCEPTION(status)) { - return status; - } - - status = _PyImportHooks_Init(tstate); + PyStatus status = _PyImportHooks_Init(tstate); if (_PyStatus_EXCEPTION(status)) { return status; } @@ -1558,23 +1564,12 @@ new_interpreter(PyThreadState **tstate_p) goto handle_exc; } - PyObject *bimod = _PyImport_FindBuiltin(tstate, "builtins"); - if (bimod != NULL) { - interp->builtins = PyModule_GetDict(bimod); - if (interp->builtins == NULL) - goto handle_exc; - Py_INCREF(interp->builtins); - } - else if (_PyErr_Occurred(tstate)) { - goto handle_exc; + status = pycore_init_builtins(tstate); + if (_PyStatus_EXCEPTION(status)) { + goto done; } - if (bimod != NULL && sysmod != NULL) { - status = _PyBuiltins_AddExceptions(bimod); - if (_PyStatus_EXCEPTION(status)) { - goto done; - } - + if (sysmod != NULL) { status = _PySys_SetPreliminaryStderr(interp->sysdict); if (_PyStatus_EXCEPTION(status)) { goto done; |