mirror of
https://github.com/python/cpython.git
synced 2025-10-28 09:10:36 +00:00
gh-117953: Split Up _PyImport_LoadDynamicModuleWithSpec() (gh-118203)
Basically, I've turned most of _PyImport_LoadDynamicModuleWithSpec() into two new functions (_PyImport_GetModInitFunc() and _PyImport_RunModInitFunc()) and moved the rest of it out into _imp_create_dynamic_impl(). There shouldn't be any changes in behavior. This change makes some future changes simpler. This is particularly relevant to potentially calling each module init function in the main interpreter first. Thus the critical part of the PR is the addition of _PyImport_RunModInitFunc(), which is strictly focused on running the init func and validating the result. A later PR will take it a step farther by capturing error information rather than raising exceptions. FWIW, this change also helps readers by clarifying a bit more about what happens when an extension/builtin module is imported.
This commit is contained in:
parent
23d0371bb9
commit
44f57a952e
5 changed files with 193 additions and 145 deletions
|
|
@ -29,9 +29,6 @@ extern int _PyImport_FixupBuiltin(
|
|||
const char *name, /* UTF-8 encoded string */
|
||||
PyObject *modules
|
||||
);
|
||||
// We could probably drop this:
|
||||
extern int _PyImport_FixupExtensionObject(PyObject*, PyObject *,
|
||||
PyObject *, PyObject *);
|
||||
|
||||
// Export for many shared extensions, like '_json'
|
||||
PyAPI_FUNC(PyObject*) _PyImport_GetModuleAttr(PyObject *, PyObject *);
|
||||
|
|
@ -55,7 +52,7 @@ struct _import_runtime_state {
|
|||
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().
|
||||
This is initialized lazily in fix_up_extension() in import.c.
|
||||
Modules are added there and looked up in _imp.find_extension(). */
|
||||
_Py_hashtable_t *hashtable;
|
||||
} extensions;
|
||||
|
|
|
|||
|
|
@ -40,10 +40,17 @@ extern int _Py_ext_module_loader_info_init_from_spec(
|
|||
struct _Py_ext_module_loader_info *info,
|
||||
PyObject *spec);
|
||||
|
||||
extern PyObject *_PyImport_LoadDynamicModuleWithSpec(
|
||||
struct _Py_ext_module_loader_result {
|
||||
PyModuleDef *def;
|
||||
PyObject *module;
|
||||
};
|
||||
extern PyModInitFunction _PyImport_GetModInitFunc(
|
||||
struct _Py_ext_module_loader_info *info,
|
||||
PyObject *spec,
|
||||
FILE *fp);
|
||||
extern int _PyImport_RunModInitFunc(
|
||||
PyModInitFunction p0,
|
||||
struct _Py_ext_module_loader_info *info,
|
||||
struct _Py_ext_module_loader_result *p_res);
|
||||
|
||||
|
||||
/* Max length of module suffix searched for -- accommodates "module.slb" */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue