mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-1635741: Convert _imp to multi-phase init (GH-23378)
Convert the _imp extension module to the multi-phase initialization API (PEP 489). * Add _PyImport_BootstrapImp() which fix a bootstrap issue: import the _imp module before importlib is initialized. * Add create_builtin() sub-function, used by _imp_create_builtin(). * Initialize PyInterpreterState.import_func earlier, in pycore_init_builtins(). * Remove references to _PyImport_Cleanup(). This function has been renamed to finalize_modules() and moved to pylifecycle.c.
This commit is contained in:
parent
e0251787d8
commit
6223071421
4 changed files with 134 additions and 93 deletions
|
@ -8,6 +8,7 @@
|
|||
#include "pycore_ceval.h" // _PyEval_FiniGIL()
|
||||
#include "pycore_context.h" // _PyContext_Init()
|
||||
#include "pycore_fileutils.h" // _Py_ResetForceASCII()
|
||||
#include "pycore_import.h" // _PyImport_BootstrapImp()
|
||||
#include "pycore_initconfig.h" // _PyStatus_OK()
|
||||
#include "pycore_object.h" // _PyDebug_PrintTotalRefs()
|
||||
#include "pycore_pathconfig.h" // _PyConfig_WritePathConfig()
|
||||
|
@ -155,18 +156,11 @@ init_importlib(PyThreadState *tstate, PyObject *sysmod)
|
|||
}
|
||||
interp->importlib = Py_NewRef(importlib);
|
||||
|
||||
PyObject *import_func = _PyDict_GetItemStringWithError(interp->builtins,
|
||||
"__import__");
|
||||
if (import_func == NULL) {
|
||||
return -1;
|
||||
}
|
||||
interp->import_func = Py_NewRef(import_func);
|
||||
|
||||
// Import the _imp module
|
||||
if (verbose) {
|
||||
PySys_FormatStderr("import _imp # builtin\n");
|
||||
}
|
||||
PyObject *imp_mod = PyInit__imp();
|
||||
PyObject *imp_mod = _PyImport_BootstrapImp(tstate);
|
||||
if (imp_mod == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -741,6 +735,14 @@ pycore_init_builtins(PyThreadState *tstate)
|
|||
}
|
||||
Py_DECREF(bimod);
|
||||
|
||||
// Get the __import__ function
|
||||
PyObject *import_func = _PyDict_GetItemStringWithError(interp->builtins,
|
||||
"__import__");
|
||||
if (import_func == NULL) {
|
||||
goto error;
|
||||
}
|
||||
interp->import_func = Py_NewRef(import_func);
|
||||
|
||||
assert(!_PyErr_Occurred(tstate));
|
||||
|
||||
return _PyStatus_OK();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue