bpo-36710: Add tstate parameter in import.c (GH-14218)

* Add 'tstate' parameter to many internal import.c functions.
* _PyImportZip_Init() now gets 'tstate' parameter rather than
  'interp'.
* Add 'interp' parameter to _PyState_ClearModules() and rename it
  to _PyInterpreterState_ClearModules().
* Move private _PyImport_FindBuiltin() to the internal C API; add
  'tstate' parameter to it.
* Remove private _PyImport_AddModuleObject() from the C API:
  use public PyImport_AddModuleObject() instead.
* Remove private _PyImport_FindExtensionObjectEx() from the C API:
  use private _PyImport_FindExtensionObject() instead.
This commit is contained in:
Victor Stinner 2019-06-19 02:54:39 +02:00 committed by GitHub
parent 809ff1181c
commit 0a28f8d379
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 248 additions and 191 deletions

View file

@ -6,6 +6,7 @@
#undef Yield /* undefine macro conflicting with <winbase.h> */
#include "pycore_ceval.h"
#include "pycore_context.h"
#include "pycore_import.h" /* _PyImport_FindBuiltin */
#include "pycore_initconfig.h"
#include "pycore_fileutils.h"
#include "pycore_hamt.h"
@ -197,17 +198,17 @@ init_importlib(PyInterpreterState *interp, PyObject *sysmod)
}
static PyStatus
init_importlib_external(PyInterpreterState *interp)
init_importlib_external(PyThreadState *tstate)
{
PyObject *value;
value = PyObject_CallMethod(interp->importlib,
value = PyObject_CallMethod(tstate->interp->importlib,
"_install_external_importers", "");
if (value == NULL) {
PyErr_Print();
return _PyStatus_ERR("external importer setup failed");
}
Py_DECREF(value);
return _PyImportZip_Init(interp);
return _PyImportZip_Init(tstate);
}
/* Helper functions to better handle the legacy C locale
@ -924,7 +925,7 @@ pyinit_main(_PyRuntimeState *runtime, PyInterpreterState *interp)
return _PyStatus_ERR("can't finish initializing sys");
}
PyStatus status = init_importlib_external(interp);
PyStatus status = init_importlib_external(tstate);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
@ -1449,7 +1450,7 @@ new_interpreter(PyThreadState **tstate_p)
}
interp->modules = modules;
PyObject *sysmod = _PyImport_FindBuiltin("sys", modules);
PyObject *sysmod = _PyImport_FindBuiltin(tstate, "sys");
if (sysmod != NULL) {
interp->sysdict = PyModule_GetDict(sysmod);
if (interp->sysdict == NULL) {
@ -1465,7 +1466,7 @@ new_interpreter(PyThreadState **tstate_p)
goto handle_error;
}
PyObject *bimod = _PyImport_FindBuiltin("builtins", modules);
PyObject *bimod = _PyImport_FindBuiltin(tstate, "builtins");
if (bimod != NULL) {
interp->builtins = PyModule_GetDict(bimod);
if (interp->builtins == NULL)
@ -1497,7 +1498,7 @@ new_interpreter(PyThreadState **tstate_p)
return status;
}
status = init_importlib_external(interp);
status = init_importlib_external(tstate);
if (_PyStatus_EXCEPTION(status)) {
return status;
}