8000 gh-132775: Add _PyImport_GetModulesRef() to the Internal C-API by ericsnowcurrently · Pull Request #132977 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-132775: Add _PyImport_GetModulesRef() to the Internal C-API #132977

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Include/internal/pycore_import.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ extern void _PyImport_SetDLOpenFlags(PyInterpreterState *interp, int new_val);

extern PyObject * _PyImport_InitModules(PyInterpreterState *interp);
extern PyObject * _PyImport_GetModules(PyInterpreterState *interp);
extern PyObject * _PyImport_GetModulesRef(PyInterpreterState *interp);
extern void _PyImport_ClearModules(PyInterpreterState *interp);

extern void _PyImport_ClearModulesByIndex(PyInterpreterState *interp);
Expand Down
14 changes: 14 additions & 0 deletions Python/import.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Loading
0