• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef Py_INTERNAL_IMPORTDL_H
2 #define Py_INTERNAL_IMPORTDL_H
3 
4 #include "patchlevel.h"           // PY_MAJOR_VERSION
5 
6 #ifdef __cplusplus
7 extern "C" {
8 #endif
9 
10 #ifndef Py_BUILD_CORE
11 #  error "this header requires Py_BUILD_CORE define"
12 #endif
13 
14 
15 extern const char *_PyImport_DynLoadFiletab[];
16 
17 
18 typedef enum ext_module_kind {
19     _Py_ext_module_kind_UNKNOWN = 0,
20     _Py_ext_module_kind_SINGLEPHASE = 1,
21     _Py_ext_module_kind_MULTIPHASE = 2,
22     _Py_ext_module_kind_INVALID = 3,
23 } _Py_ext_module_kind;
24 
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;
30 
31 /* Input for loading an extension module. */
32 struct _Py_ext_module_loader_info {
33     PyObject *filename;
34 #ifndef MS_WINDOWS
35     PyObject *filename_encoded;
36 #endif
37     PyObject *name;
38     PyObject *name_encoded;
39     /* path is always a borrowed ref of name or filename,
40      * depending on if it's builtin or not. */
41     PyObject *path;
42     _Py_ext_module_origin origin;
43     const char *hook_prefix;
44     const char *newcontext;
45 };
46 extern void _Py_ext_module_loader_info_clear(
47     struct _Py_ext_module_loader_info *info);
48 extern int _Py_ext_module_loader_info_init(
49     struct _Py_ext_module_loader_info *info,
50     PyObject *name,
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);
56 extern int _Py_ext_module_loader_info_init_for_builtin(
57     struct _Py_ext_module_loader_info *p_info,
58     PyObject *name);
59 #ifdef HAVE_DYNAMIC_LOADING
60 extern int _Py_ext_module_loader_info_init_from_spec(
61     struct _Py_ext_module_loader_info *info,
62     PyObject *spec);
63 #endif
64 
65 /* The result from running an extension module's init function. */
66 struct _Py_ext_module_loader_result {
67     PyModuleDef *def;
68     PyObject *module;
69     _Py_ext_module_kind kind;
70     struct _Py_ext_module_loader_result_error *err;
71     struct _Py_ext_module_loader_result_error {
72         enum _Py_ext_module_loader_result_error_kind {
73             _Py_ext_module_loader_result_EXCEPTION = 0,
74             _Py_ext_module_loader_result_ERR_MISSING = 1,
75             _Py_ext_module_loader_result_ERR_UNREPORTED_EXC = 2,
76             _Py_ext_module_loader_result_ERR_UNINITIALIZED = 3,
77             _Py_ext_module_loader_result_ERR_NONASCII_NOT_MULTIPHASE = 4,
78             _Py_ext_module_loader_result_ERR_NOT_MODULE = 5,
79             _Py_ext_module_loader_result_ERR_MISSING_DEF = 6,
80         } kind;
81         PyObject *exc;
82     } _err;
83 };
84 extern void _Py_ext_module_loader_result_clear(
85     struct _Py_ext_module_loader_result *res);
86 extern void _Py_ext_module_loader_result_apply_error(
87     struct _Py_ext_module_loader_result *res,
88     const char *name);
89 
90 /* The module init function. */
91 typedef PyObject *(*PyModInitFunction)(void);
92 #ifdef HAVE_DYNAMIC_LOADING
93 extern PyModInitFunction _PyImport_GetModInitFunc(
94     struct _Py_ext_module_loader_info *info,
95     FILE *fp);
96 #endif
97 extern int _PyImport_RunModInitFunc(
98     PyModInitFunction p0,
99     struct _Py_ext_module_loader_info *info,
100     struct _Py_ext_module_loader_result *p_res);
101 
102 
103 /* Max length of module suffix searched for -- accommodates "module.slb" */
104 #define MAXSUFFIXSIZE 12
105 
106 #ifdef MS_WINDOWS
107 #include <windows.h>
108 typedef FARPROC dl_funcptr;
109 
110 #ifdef _DEBUG
111 #  define PYD_DEBUG_SUFFIX "_d"
112 #else
113 #  define PYD_DEBUG_SUFFIX ""
114 #endif
115 
116 #ifdef Py_GIL_DISABLED
117 #  define PYD_THREADING_TAG "t"
118 #else
119 #  define PYD_THREADING_TAG ""
120 #endif
121 
122 #ifdef PYD_PLATFORM_TAG
123 #  define PYD_SOABI "cp" Py_STRINGIFY(PY_MAJOR_VERSION) Py_STRINGIFY(PY_MINOR_VERSION) PYD_THREADING_TAG "-" PYD_PLATFORM_TAG
124 #else
125 #  define PYD_SOABI "cp" Py_STRINGIFY(PY_MAJOR_VERSION) Py_STRINGIFY(PY_MINOR_VERSION) PYD_THREADING_TAG
126 #endif
127 
128 #define PYD_TAGGED_SUFFIX PYD_DEBUG_SUFFIX "." PYD_SOABI ".pyd"
129 #define PYD_UNTAGGED_SUFFIX PYD_DEBUG_SUFFIX ".pyd"
130 
131 #else
132 typedef void (*dl_funcptr)(void);
133 #endif
134 
135 
136 #ifdef __cplusplus
137 }
138 #endif
139 #endif /* !Py_INTERNAL_IMPORTDL_H */
140