Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:18:08

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 #include "pycore_hashtable.h"     // _Py_hashtable_t
0009 #include "pycore_time.h"          // _PyTime_t
0010 
0011 
0012 struct _import_runtime_state {
0013     /* The builtin modules (defined in config.c). */
0014     struct _inittab *inittab;
0015     /* The most recent value assigned to a PyModuleDef.m_base.m_index.
0016        This is incremented each time PyModuleDef_Init() is called,
0017        which is just about every time an extension module is imported.
0018        See PyInterpreterState.modules_by_index for more info. */
0019     Py_ssize_t last_module_index;
0020     struct {
0021         /* A lock to guard the cache. */
0022         PyThread_type_lock mutex;
0023         /* The actual cache of (filename, name, PyModuleDef) for modules.
0024            Only legacy (single-phase init) extension modules are added
0025            and only if they support multiple initialization (m_size >- 0)
0026            or are imported in the main interpreter.
0027            This is initialized lazily in _PyImport_FixupExtensionObject().
0028            Modules are added there and looked up in _imp.find_extension(). */
0029         _Py_hashtable_t *hashtable;
0030     } extensions;
0031     /* Package context -- the full module name for package imports */
0032     const char * pkgcontext;
0033 };
0034 
0035 struct _import_state {
0036     /* cached sys.modules dictionary */
0037     PyObject *modules;
0038     /* This is the list of module objects for all legacy (single-phase init)
0039        extension modules ever loaded in this process (i.e. imported
0040        in this interpreter or in any other).  Py_None stands in for
0041        modules that haven't actually been imported in this interpreter.
0042 
0043        A module's index (PyModuleDef.m_base.m_index) is used to look up
0044        the corresponding module object for this interpreter, if any.
0045        (See PyState_FindModule().)  When any extension module
0046        is initialized during import, its moduledef gets initialized by
0047        PyModuleDef_Init(), and the first time that happens for each
0048        PyModuleDef, its index gets set to the current value of
0049        a global counter (see _PyRuntimeState.imports.last_module_index).
0050        The entry for that index in this interpreter remains unset until
0051        the module is actually imported here.  (Py_None is used as
0052        a placeholder.)  Note that multi-phase init modules always get
0053        an index for which there will never be a module set.
0054 
0055        This is initialized lazily in PyState_AddModule(), which is also
0056        where modules get added. */
0057     PyObject *modules_by_index;
0058     /* importlib module._bootstrap */
0059     PyObject *importlib;
0060     /* override for config->use_frozen_modules (for tests)
0061        (-1: "off", 1: "on", 0: no override) */
0062     int override_frozen_modules;
0063     int override_multi_interp_extensions_check;
0064 #ifdef HAVE_DLOPEN
0065     int dlopenflags;
0066 #endif
0067     PyObject *import_func;
0068     /* The global import lock. */
0069     struct {
0070         PyThread_type_lock mutex;
0071         unsigned long thread;
0072         int level;
0073     } lock;
0074     /* diagnostic info in PyImport_ImportModuleLevelObject() */
0075     struct {
0076         int import_level;
0077         _PyTime_t accumulated;
0078         int header;
0079     } find_and_load;
0080 };
0081 
0082 #ifdef HAVE_DLOPEN
0083 #  include <dlfcn.h>
0084 #  if HAVE_DECL_RTLD_NOW
0085 #    define _Py_DLOPEN_FLAGS RTLD_NOW
0086 #  else
0087 #    define _Py_DLOPEN_FLAGS RTLD_LAZY
0088 #  endif
0089 #  define DLOPENFLAGS_INIT .dlopenflags = _Py_DLOPEN_FLAGS,
0090 #else
0091 #  define _Py_DLOPEN_FLAGS 0
0092 #  define DLOPENFLAGS_INIT
0093 #endif
0094 
0095 #define IMPORTS_INIT \
0096     { \
0097         DLOPENFLAGS_INIT \
0098         .lock = { \
0099             .mutex = NULL, \
0100             .thread = PYTHREAD_INVALID_THREAD_ID, \
0101             .level = 0, \
0102         }, \
0103         .find_and_load = { \
0104             .header = 1, \
0105         }, \
0106     }
0107 
0108 extern void _PyImport_ClearCore(PyInterpreterState *interp);
0109 
0110 extern Py_ssize_t _PyImport_GetNextModuleIndex(void);
0111 extern const char * _PyImport_ResolveNameWithPackageContext(const char *name);
0112 extern const char * _PyImport_SwapPackageContext(const char *newcontext);
0113 
0114 extern int _PyImport_GetDLOpenFlags(PyInterpreterState *interp);
0115 extern void _PyImport_SetDLOpenFlags(PyInterpreterState *interp, int new_val);
0116 
0117 extern PyObject * _PyImport_InitModules(PyInterpreterState *interp);
0118 extern PyObject * _PyImport_GetModules(PyInterpreterState *interp);
0119 extern void _PyImport_ClearModules(PyInterpreterState *interp);
0120 
0121 extern void _PyImport_ClearModulesByIndex(PyInterpreterState *interp);
0122 
0123 extern int _PyImport_InitDefaultImportFunc(PyInterpreterState *interp);
0124 extern int _PyImport_IsDefaultImportFunc(
0125         PyInterpreterState *interp,
0126         PyObject *func);
0127 
0128 extern PyObject * _PyImport_GetImportlibLoader(
0129         PyInterpreterState *interp,
0130         const char *loader_name);
0131 extern PyObject * _PyImport_GetImportlibExternalLoader(
0132         PyInterpreterState *interp,
0133         const char *loader_name);
0134 extern PyObject * _PyImport_BlessMyLoader(
0135         PyInterpreterState *interp,
0136         PyObject *module_globals);
0137 extern PyObject * _PyImport_ImportlibModuleRepr(
0138         PyInterpreterState *interp,
0139         PyObject *module);
0140 
0141 
0142 extern PyStatus _PyImport_Init(void);
0143 extern void _PyImport_Fini(void);
0144 extern void _PyImport_Fini2(void);
0145 
0146 extern PyStatus _PyImport_InitCore(
0147         PyThreadState *tstate,
0148         PyObject *sysmod,
0149         int importlib);
0150 extern PyStatus _PyImport_InitExternal(PyThreadState *tstate);
0151 extern void _PyImport_FiniCore(PyInterpreterState *interp);
0152 extern void _PyImport_FiniExternal(PyInterpreterState *interp);
0153 
0154 
0155 #ifdef HAVE_FORK
0156 extern PyStatus _PyImport_ReInitLock(PyInterpreterState *interp);
0157 #endif
0158 
0159 
0160 extern PyObject* _PyImport_GetBuiltinModuleNames(void);
0161 
0162 struct _module_alias {
0163     const char *name;                 /* ASCII encoded string */
0164     const char *orig;                 /* ASCII encoded string */
0165 };
0166 
0167 PyAPI_DATA(const struct _frozen *) _PyImport_FrozenBootstrap;
0168 PyAPI_DATA(const struct _frozen *) _PyImport_FrozenStdlib;
0169 PyAPI_DATA(const struct _frozen *) _PyImport_FrozenTest;
0170 extern const struct _module_alias * _PyImport_FrozenAliases;
0171 
0172 PyAPI_FUNC(int) _PyImport_CheckSubinterpIncompatibleExtensionAllowed(
0173     const char *name);
0174 
0175 
0176 // for testing
0177 PyAPI_FUNC(int) _PyImport_ClearExtension(PyObject *name, PyObject *filename);
0178 
0179 #ifdef __cplusplus
0180 }
0181 #endif
0182 #endif /* !Py_INTERNAL_IMPORT_H */
0183 #endif /* !Py_LIMITED_API */