diff options
-rw-r--r-- | Doc/data/refcounts.dat | 2 | ||||
-rw-r--r-- | Include/internal/pycore_pylifecycle.h | 1 | ||||
-rw-r--r-- | Python/import.c | 11 | ||||
-rw-r--r-- | Python/pylifecycle.c | 53 |
4 files changed, 24 insertions, 43 deletions
diff --git a/Doc/data/refcounts.dat b/Doc/data/refcounts.dat index cfed1bd..b55e972 100644 --- a/Doc/data/refcounts.dat +++ b/Doc/data/refcounts.dat @@ -3045,8 +3045,6 @@ Py_XINCREF:PyObject*:o:+1:if o is not NULL _PyImport_Fini:void::: -_PyImport_Init:void::: - _PyObject_New:PyObject*::+1: _PyObject_New:PyTypeObject*:type:0: diff --git a/Include/internal/pycore_pylifecycle.h b/Include/internal/pycore_pylifecycle.h index 73aa5ef..cd3be21 100644 --- a/Include/internal/pycore_pylifecycle.h +++ b/Include/internal/pycore_pylifecycle.h @@ -44,7 +44,6 @@ extern PyStatus _PySys_SetPreliminaryStderr(PyObject *sysdict); extern PyStatus _PySys_ReadPreinitWarnOptions(PyWideStringList *options); extern PyStatus _PySys_ReadPreinitXOptions(PyConfig *config); extern int _PySys_InitMain(PyThreadState *tstate); -extern PyStatus _PyImport_Init(PyThreadState *tstate); extern PyStatus _PyExc_Init(void); extern PyStatus _PyErr_Init(void); extern PyStatus _PyBuiltins_AddExceptions(PyObject * bltinmod); diff --git a/Python/import.c b/Python/import.c index 923c6d0..045b6d0 100644 --- a/Python/import.c +++ b/Python/import.c @@ -49,17 +49,6 @@ module _imp /* Initialize things */ PyStatus -_PyImport_Init(PyThreadState *tstate) -{ - PyInterpreterState *interp = tstate->interp; - interp->builtins_copy = PyDict_Copy(interp->builtins); - if (interp->builtins_copy == NULL) { - return _PyStatus_ERR("Can't backup builtins dict"); - } - return _PyStatus_OK(); -} - -PyStatus _PyImportHooks_Init(PyThreadState *tstate) { PyObject *v, *path_hooks = NULL; 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; |