Skip to content

Commit 8890b1f

Browse files
ericsnowcurrentlySonicField
authored andcommitted
pythongh-117953: Track Extra Details in Global Extensions Cache (pythongh-118532)
We have only been tracking each module's PyModuleDef. However, there are some problems with that. For example, in some cases we load single-phase init extension modules from def->m_base.m_init or def->m_base.m_copy, but if multiple modules share a def then we can end up with unexpected behavior. With this change, we track the following: * PyModuleDef (same as before) * for some modules, its init function or a copy of its __dict__, but specific to that module * whether it is a builtin/core module or a "dynamic" extension * the interpreter (ID) that owns the cached __dict__ (only if cached) This also makes it easier to remember the module's kind (e.g. single-phase init) and if loading it previously failed, which I'm doing separately.
1 parent 2670633 commit 8890b1f

File tree

3 files changed

+578
-138
lines changed

3 files changed

+578
-138
lines changed

Include/internal/pycore_importdl.h

+11-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ typedef enum ext_module_kind {
2222
_Py_ext_module_kind_INVALID = 3,
2323
} _Py_ext_module_kind;
2424

25+
typedef enum ext_module_origin {
26+
_Py_ext_module_origin_CORE = 1,
27+
_Py_ext_module_origin_BUILTIN = 2,
28+
_Py_ext_module_origin_DYNAMIC = 3,
29+
} _Py_ext_module_origin;
2530

2631
/* Input for loading an extension module. */
2732
struct _Py_ext_module_loader_info {
@@ -34,6 +39,7 @@ struct _Py_ext_module_loader_info {
3439
/* path is always a borrowed ref of name or filename,
3540
* depending on if it's builtin or not. */
3641
PyObject *path;
42+
_Py_ext_module_origin origin;
3743
const char *hook_prefix;
3844
const char *newcontext;
3945
};
@@ -42,7 +48,11 @@ extern void _Py_ext_module_loader_info_clear(
4248
extern int _Py_ext_module_loader_info_init(
4349
struct _Py_ext_module_loader_info *info,
4450
PyObject *name,
45-
PyObject *filename);
51+
PyObject *filename,
52+
_Py_ext_module_origin origin);
53+
extern int _Py_ext_module_loader_info_init_for_core(
54+
struct _Py_ext_module_loader_info *p_info,
55+
PyObject *name);
4656
extern int _Py_ext_module_loader_info_init_for_builtin(
4757
struct _Py_ext_module_loader_info *p_info,
4858
PyObject *name);

0 commit comments

Comments
 (0)