summaryrefslogtreecommitdiffstats
path: root/Python/import.c
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2025-04-28 18:46:22 (GMT)
committerGitHub <noreply@github.com>2025-04-28 18:46:22 (GMT)
commitfe462f5a9122e1c2641b5369cbb88c4a5e822816 (patch)
tree2ab97dcc3c793827bc1e620fa8d65d07a3df837a /Python/import.c
parentc17238251fdf72861dfadcd581c77332b639bcb0 (diff)
downloadcpython-fe462f5a9122e1c2641b5369cbb88c4a5e822816.zip
cpython-fe462f5a9122e1c2641b5369cbb88c4a5e822816.tar.gz
cpython-fe462f5a9122e1c2641b5369cbb88c4a5e822816.tar.bz2
gh-132775: Drop PyUnstable_InterpreterState_GetMainModule() (gh-132978)
We replace it with _Py_GetMainModule(), and add _Py_CheckMainModule(), but both in the internal-only C-API. We also add _PyImport_GetModulesRef(), which is the equivalent of _PyImport_GetModules(), but which increfs before the lock is released. This is used by a later change related to pickle and handling __main__.
Diffstat (limited to 'Python/import.c')
-rw-r--r--Python/import.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/Python/import.c b/Python/import.c
index 8742b6e..a671a08 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -153,6 +153,20 @@ _PyImport_GetModules(PyInterpreterState *interp)
return MODULES(interp);
}
+PyObject *
+_PyImport_GetModulesRef(PyInterpreterState *interp)
+{
+ _PyImport_AcquireLock(interp);
+ PyObject *modules = MODULES(interp);
+ if (modules == NULL) {
+ /* The interpreter hasn't been initialized yet. */
+ modules = Py_None;
+ }
+ Py_INCREF(modules);
+ _PyImport_ReleaseLock(interp);
+ return modules;
+}
+
void
_PyImport_ClearModules(PyInterpreterState *interp)
{