@@ -36,11 +36,112 @@ struct _import_runtime_state {
3636 const char * pkgcontext ;
3737};
3838
39+ struct _import_state {
40+ /* cached sys.modules dictionary */
41+ PyObject * modules ;
42+ /* This is the list of module objects for all legacy (single-phase init)
43+ extension modules ever loaded in this process (i.e. imported
44+ in this interpreter or in any other). Py_None stands in for
45+ modules that haven't actually been imported in this interpreter.
46+
47+ A module's index (PyModuleDef.m_base.m_index) is used to look up
48+ the corresponding module object for this interpreter, if any.
49+ (See PyState_FindModule().) When any extension module
50+ is initialized during import, its moduledef gets initialized by
51+ PyModuleDef_Init(), and the first time that happens for each
52+ PyModuleDef, its index gets set to the current value of
53+ a global counter (see _PyRuntimeState.imports.last_module_index).
54+ The entry for that index in this interpreter remains unset until
55+ the module is actually imported here. (Py_None is used as
56+ a placeholder.) Note that multi-phase init modules always get
57+ an index for which there will never be a module set.
58+
59+ This is initialized lazily in PyState_AddModule(), which is also
60+ where modules get added. */
61+ PyObject * modules_by_index ;
62+ /* importlib module._bootstrap */
63+ PyObject * importlib ;
64+ /* override for config->use_frozen_modules (for tests)
65+ (-1: "off", 1: "on", 0: no override) */
66+ int override_frozen_modules ;
67+ #ifdef HAVE_DLOPEN
68+ int dlopenflags ;
69+ #endif
70+ PyObject * import_func ;
71+ };
72+
73+ #ifdef HAVE_DLOPEN
74+ # include <dlfcn.h>
75+ # if HAVE_DECL_RTLD_NOW
76+ # define _Py_DLOPEN_FLAGS RTLD_NOW
77+ # else
78+ # define _Py_DLOPEN_FLAGS RTLD_LAZY
79+ # endif
80+ # define DLOPENFLAGS_INIT .dlopenflags = _Py_DLOPEN_FLAGS,
81+ #else
82+ # define _Py_DLOPEN_FLAGS 0
83+ # define DLOPENFLAGS_INIT
84+ #endif
85+
86+ #define IMPORTS_INIT \
87+ { \
88+ .override_frozen_modules = 0, \
89+ DLOPENFLAGS_INIT \
90+ }
91+
92+ extern void _PyImport_ClearCore (PyInterpreterState * interp );
93+
94+ extern Py_ssize_t _PyImport_GetNextModuleIndex (void );
95+ extern const char * _PyImport_ResolveNameWithPackageContext (const char * name );
96+ extern const char * _PyImport_SwapPackageContext (const char * newcontext );
97+
98+ extern int _PyImport_GetDLOpenFlags (PyInterpreterState * interp );
99+ extern void _PyImport_SetDLOpenFlags (PyInterpreterState * interp , int new_val );
100+
101+ extern PyObject * _PyImport_InitModules (PyInterpreterState * interp );
102+ extern PyObject * _PyImport_GetModules (PyInterpreterState * interp );
103+ extern void _PyImport_ClearModules (PyInterpreterState * interp );
104+
105+ extern void _PyImport_ClearModulesByIndex (PyInterpreterState * interp );
106+
107+ extern int _PyImport_InitDefaultImportFunc (PyInterpreterState * interp );
108+ extern int _PyImport_IsDefaultImportFunc (
109+ PyInterpreterState * interp ,
110+ PyObject * func );
111+
112+ extern PyObject * _PyImport_GetImportlibLoader (
113+ PyInterpreterState * interp ,
114+ const char * loader_name );
115+ extern PyObject * _PyImport_GetImportlibExternalLoader (
116+ PyInterpreterState * interp ,
117+ const char * loader_name );
118+ extern PyObject * _PyImport_BlessMyLoader (
119+ PyInterpreterState * interp ,
120+ PyObject * module_globals );
121+ extern PyObject * _PyImport_ImportlibModuleRepr (
122+ PyInterpreterState * interp ,
123+ PyObject * module );
124+
125+
126+ extern PyStatus _PyImport_Init (void );
127+ extern void _PyImport_Fini (void );
128+ extern void _PyImport_Fini2 (void );
129+
130+ extern PyStatus _PyImport_InitCore (
131+ PyThreadState * tstate ,
132+ PyObject * sysmod ,
133+ int importlib );
134+ extern PyStatus _PyImport_InitExternal (PyThreadState * tstate );
135+ extern void _PyImport_FiniCore (PyInterpreterState * interp );
136+ extern void _PyImport_FiniExternal (PyInterpreterState * interp );
137+
39138
40139#ifdef HAVE_FORK
41140extern PyStatus _PyImport_ReInitLock (void );
42141#endif
43- extern PyObject * _PyImport_BootstrapImp (PyThreadState * tstate );
142+
143+
144+ extern PyObject * _PyImport_GetBuiltinModuleNames (void );
44145
45146struct _module_alias {
46147 const char * name ; /* ASCII encoded string */
@@ -52,6 +153,9 @@ PyAPI_DATA(const struct _frozen *) _PyImport_FrozenStdlib;
52153PyAPI_DATA (const struct _frozen * ) _PyImport_FrozenTest ;
53154extern const struct _module_alias * _PyImport_FrozenAliases ;
54155
156+ // for testing
157+ PyAPI_FUNC (int ) _PyImport_ClearExtension (PyObject * name , PyObject * filename );
158+
55159#ifdef __cplusplus
56160}
57161#endif
0 commit comments