File indexing completed on 2025-11-19 09:50:47
0001 #ifndef Py_LIMITED_API
0002 #ifndef Py_INTERNAL_IMPORT_H
0003 #define Py_INTERNAL_IMPORT_H
0004 #ifdef __cplusplus
0005 extern "C" {
0006 #endif
0007
0008 #ifndef Py_BUILD_CORE
0009 # error "this header requires Py_BUILD_CORE define"
0010 #endif
0011
0012 #include "pycore_lock.h" // PyMutex
0013 #include "pycore_hashtable.h" // _Py_hashtable_t
0014
0015 extern int _PyImport_IsInitialized(PyInterpreterState *);
0016
0017
0018 PyAPI_FUNC(int) _PyImport_SetModule(PyObject *name, PyObject *module);
0019
0020 extern int _PyImport_SetModuleString(const char *name, PyObject* module);
0021
0022 extern void _PyImport_AcquireLock(PyInterpreterState *interp);
0023 extern void _PyImport_ReleaseLock(PyInterpreterState *interp);
0024 extern void _PyImport_ReInitLock(PyInterpreterState *interp);
0025
0026
0027 extern int _PyImport_FixupBuiltin(
0028 PyThreadState *tstate,
0029 PyObject *mod,
0030 const char *name,
0031 PyObject *modules
0032 );
0033
0034
0035 PyAPI_FUNC(PyObject*) _PyImport_GetModuleAttr(PyObject *, PyObject *);
0036
0037
0038 PyAPI_FUNC(PyObject*) _PyImport_GetModuleAttrString(const char *, const char *);
0039
0040
0041 struct _import_runtime_state {
0042
0043 struct _inittab *inittab;
0044
0045
0046
0047
0048 Py_ssize_t last_module_index;
0049 struct {
0050
0051 PyMutex mutex;
0052
0053
0054
0055
0056
0057
0058 _Py_hashtable_t *hashtable;
0059 } extensions;
0060
0061 const char * pkgcontext;
0062 };
0063
0064 struct _import_state {
0065
0066 PyObject *modules;
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086 PyObject *modules_by_index;
0087
0088 PyObject *importlib;
0089
0090
0091 int override_frozen_modules;
0092 int override_multi_interp_extensions_check;
0093 #ifdef HAVE_DLOPEN
0094 int dlopenflags;
0095 #endif
0096 PyObject *import_func;
0097
0098 _PyRecursiveMutex lock;
0099
0100 struct {
0101 int import_level;
0102 PyTime_t accumulated;
0103 int header;
0104 } find_and_load;
0105 };
0106
0107 #ifdef HAVE_DLOPEN
0108 # include <dlfcn.h> // RTLD_NOW, RTLD_LAZY
0109 # if HAVE_DECL_RTLD_NOW
0110 # define _Py_DLOPEN_FLAGS RTLD_NOW
0111 # else
0112 # define _Py_DLOPEN_FLAGS RTLD_LAZY
0113 # endif
0114 # define DLOPENFLAGS_INIT .dlopenflags = _Py_DLOPEN_FLAGS,
0115 #else
0116 # define _Py_DLOPEN_FLAGS 0
0117 # define DLOPENFLAGS_INIT
0118 #endif
0119
0120 #define IMPORTS_INIT \
0121 { \
0122 DLOPENFLAGS_INIT \
0123 .find_and_load = { \
0124 .header = 1, \
0125 }, \
0126 }
0127
0128 extern void _PyImport_ClearCore(PyInterpreterState *interp);
0129
0130 extern Py_ssize_t _PyImport_GetNextModuleIndex(void);
0131 extern const char * _PyImport_ResolveNameWithPackageContext(const char *name);
0132 extern const char * _PyImport_SwapPackageContext(const char *newcontext);
0133
0134 extern int _PyImport_GetDLOpenFlags(PyInterpreterState *interp);
0135 extern void _PyImport_SetDLOpenFlags(PyInterpreterState *interp, int new_val);
0136
0137 extern PyObject * _PyImport_InitModules(PyInterpreterState *interp);
0138 extern PyObject * _PyImport_GetModules(PyInterpreterState *interp);
0139 extern void _PyImport_ClearModules(PyInterpreterState *interp);
0140
0141 extern void _PyImport_ClearModulesByIndex(PyInterpreterState *interp);
0142
0143 extern int _PyImport_InitDefaultImportFunc(PyInterpreterState *interp);
0144 extern int _PyImport_IsDefaultImportFunc(
0145 PyInterpreterState *interp,
0146 PyObject *func);
0147
0148 extern PyObject * _PyImport_GetImportlibLoader(
0149 PyInterpreterState *interp,
0150 const char *loader_name);
0151 extern PyObject * _PyImport_GetImportlibExternalLoader(
0152 PyInterpreterState *interp,
0153 const char *loader_name);
0154 extern PyObject * _PyImport_BlessMyLoader(
0155 PyInterpreterState *interp,
0156 PyObject *module_globals);
0157 extern PyObject * _PyImport_ImportlibModuleRepr(
0158 PyInterpreterState *interp,
0159 PyObject *module);
0160
0161
0162 extern PyStatus _PyImport_Init(void);
0163 extern void _PyImport_Fini(void);
0164 extern void _PyImport_Fini2(void);
0165
0166 extern PyStatus _PyImport_InitCore(
0167 PyThreadState *tstate,
0168 PyObject *sysmod,
0169 int importlib);
0170 extern PyStatus _PyImport_InitExternal(PyThreadState *tstate);
0171 extern void _PyImport_FiniCore(PyInterpreterState *interp);
0172 extern void _PyImport_FiniExternal(PyInterpreterState *interp);
0173
0174
0175 extern PyObject* _PyImport_GetBuiltinModuleNames(void);
0176
0177 struct _module_alias {
0178 const char *name;
0179 const char *orig;
0180 };
0181
0182
0183 PyAPI_DATA(const struct _frozen*) _PyImport_FrozenBootstrap;
0184 PyAPI_DATA(const struct _frozen*) _PyImport_FrozenStdlib;
0185 PyAPI_DATA(const struct _frozen*) _PyImport_FrozenTest;
0186
0187 extern const struct _module_alias * _PyImport_FrozenAliases;
0188
0189 extern int _PyImport_CheckSubinterpIncompatibleExtensionAllowed(
0190 const char *name);
0191
0192
0193
0194 PyAPI_FUNC(int) _PyImport_ClearExtension(PyObject *name, PyObject *filename);
0195
0196 #ifdef Py_GIL_DISABLED
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206 extern int _PyImport_CheckGILForModule(PyObject *module, PyObject *module_name);
0207 #endif
0208
0209 #ifdef __cplusplus
0210 }
0211 #endif
0212 #endif
0213 #endif