summaryrefslogtreecommitdiffstats
path: root/Python/import.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2021-02-19 14:10:45 (GMT)
committerGitHub <noreply@github.com>2021-02-19 14:10:45 (GMT)
commitbcb094b41f7fe4dd1686c50891d85632fcf0d481 (patch)
tree72ae3916ace264f291a89f288ff199a36ead54f4 /Python/import.c
parenta486054b24658fa623e030ddd4cc0cbfcac54ab0 (diff)
downloadcpython-bcb094b41f7fe4dd1686c50891d85632fcf0d481.zip
cpython-bcb094b41f7fe4dd1686c50891d85632fcf0d481.tar.gz
cpython-bcb094b41f7fe4dd1686c50891d85632fcf0d481.tar.bz2
bpo-43268: Pass interp rather than tstate to internal functions (GH-24580)
Pass the current interpreter (interp) rather than the current Python thread state (tstate) to internal functions which only use the interpreter. Modified functions: * _PyXXX_Fini() and _PyXXX_ClearFreeList() functions * _PyEval_SignalAsyncExc(), make_pending_calls() * _PySys_GetObject(), sys_set_object(), sys_set_object_id(), sys_set_object_str() * should_audit(), set_flags_from_config(), make_flags() * _PyAtExit_Call() * init_stdio_encoding() * etc.
Diffstat (limited to 'Python/import.c')
-rw-r--r--Python/import.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/Python/import.c b/Python/import.c
index 6189dcf..538db69 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -301,16 +301,16 @@ _PyImport_GetModuleId(struct _Py_Identifier *nameid)
int
_PyImport_SetModule(PyObject *name, PyObject *m)
{
- PyThreadState *tstate = _PyThreadState_GET();
- PyObject *modules = tstate->interp->modules;
+ PyInterpreterState *interp = _PyInterpreterState_GET();
+ PyObject *modules = interp->modules;
return PyObject_SetItem(modules, name, m);
}
int
_PyImport_SetModuleString(const char *name, PyObject *m)
{
- PyThreadState *tstate = _PyThreadState_GET();
- PyObject *modules = tstate->interp->modules;
+ PyInterpreterState *interp = _PyInterpreterState_GET();
+ PyObject *modules = interp->modules;
return PyMapping_SetItemString(modules, name, m);
}
@@ -342,9 +342,8 @@ import_get_module(PyThreadState *tstate, PyObject *name)
static int
-import_ensure_initialized(PyThreadState *tstate, PyObject *mod, PyObject *name)
+import_ensure_initialized(PyInterpreterState *interp, PyObject *mod, PyObject *name)
{
- PyInterpreterState *interp = tstate->interp;
PyObject *spec;
_Py_IDENTIFIER(_lock_unlock_module);
@@ -1530,7 +1529,7 @@ PyImport_GetModule(PyObject *name)
mod = import_get_module(tstate, name);
if (mod != NULL && mod != Py_None) {
- if (import_ensure_initialized(tstate, mod, name) < 0) {
+ if (import_ensure_initialized(tstate->interp, mod, name) < 0) {
Py_DECREF(mod);
remove_importlib_frames(tstate);
return NULL;
@@ -1594,7 +1593,7 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals,
}
if (mod != NULL && mod != Py_None) {
- if (import_ensure_initialized(tstate, mod, name) < 0) {
+ if (import_ensure_initialized(tstate->interp, mod, name) < 0) {
goto error;
}
}