Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Make _PyRuntime.imports.extensions a struct.
  • Loading branch information
ericsnowcurrently committed Mar 27, 2023
commit ff4eb3621768e59066c0d25144f9ac07ac63ab24
16 changes: 9 additions & 7 deletions Include/internal/pycore_import.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ struct _import_runtime_state {
which is just about every time an extension module is imported.
See PyInterpreterState.modules_by_index for more info. */
Py_ssize_t last_module_index;
/* A dict mapping (filename, name) to PyModuleDef for modules.
Only legacy (single-phase init) extension modules are added
and only if they support multiple initialization (m_size >- 0)
or are imported in the main interpreter.
This is initialized lazily in _PyImport_FixupExtensionObject().
Modules are added there and looked up in _imp.find_extension(). */
PyObject *extensions;
struct {
/* A dict mapping (filename, name) to PyModuleDef for modules.
Only legacy (single-phase init) extension modules are added
and only if they support multiple initialization (m_size >- 0)
or are imported in the main interpreter.
This is initialized lazily in _PyImport_FixupExtensionObject().
Modules are added there and looked up in _imp.find_extension(). */
PyObject *dict;
} extensions;
/* Package context -- the full module name for package imports */
const char * pkgcontext;
};
Expand Down
10 changes: 5 additions & 5 deletions Python/import.c
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ gets even messier.
static PyModuleDef *
_extensions_cache_get(PyObject *filename, PyObject *name)
{
PyObject *extensions = EXTENSIONS;
PyObject *extensions = EXTENSIONS.dict;
if (extensions == NULL) {
return NULL;
}
Expand All @@ -897,13 +897,13 @@ _extensions_cache_get(PyObject *filename, PyObject *name)
static int
_extensions_cache_set(PyObject *filename, PyObject *name, PyModuleDef *def)
{
PyObject *extensions = EXTENSIONS;
PyObject *extensions = EXTENSIONS.dict;
if (extensions == NULL) {
extensions = PyDict_New();
if (extensions == NULL) {
return -1;
}
EXTENSIONS = extensions;
EXTENSIONS.dict = extensions;
}
PyObject *key = PyTuple_Pack(2, filename, name);
if (key == NULL) {
Expand All @@ -920,7 +920,7 @@ _extensions_cache_set(PyObject *filename, PyObject *name, PyModuleDef *def)
static int
_extensions_cache_delete(PyObject *filename, PyObject *name)
{
PyObject *extensions = EXTENSIONS;
PyObject *extensions = EXTENSIONS.dict;
if (extensions == NULL) {
return 0;
}
Expand All @@ -942,7 +942,7 @@ _extensions_cache_delete(PyObject *filename, PyObject *name)
static void
_extensions_cache_clear_all(void)
{
Py_CLEAR(EXTENSIONS);
Py_CLEAR(EXTENSIONS.dict);
}


Expand Down