• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /* Interfaces to configure, query, create & destroy the Python runtime */
3 
4 #ifndef Py_PYLIFECYCLE_H
5 #define Py_PYLIFECYCLE_H
6 #ifdef __cplusplus
7 extern "C" {
8 #endif
9 
10 #ifndef Py_LIMITED_API
11 typedef struct {
12     const char *prefix;
13     const char *msg;
14     int user_err;
15 } _PyInitError;
16 
17 /* Almost all errors causing Python initialization to fail */
18 #ifdef _MSC_VER
19    /* Visual Studio 2015 doesn't implement C99 __func__ in C */
20 #  define _Py_INIT_GET_FUNC() __FUNCTION__
21 #else
22 #  define _Py_INIT_GET_FUNC() __func__
23 #endif
24 
25 #define _Py_INIT_OK() \
26     (_PyInitError){.prefix = NULL, .msg = NULL, .user_err = 0}
27 #define _Py_INIT_ERR(MSG) \
28     (_PyInitError){.prefix = _Py_INIT_GET_FUNC(), .msg = (MSG), .user_err = 0}
29 /* Error that can be fixed by the user like invalid input parameter.
30    Don't abort() the process on such error. */
31 #define _Py_INIT_USER_ERR(MSG) \
32     (_PyInitError){.prefix = _Py_INIT_GET_FUNC(), .msg = (MSG), .user_err = 1}
33 #define _Py_INIT_NO_MEMORY() _Py_INIT_USER_ERR("memory allocation failed")
34 #define _Py_INIT_FAILED(err) \
35     (err.msg != NULL)
36 
37 #endif
38 
39 
40 PyAPI_FUNC(void) Py_SetProgramName(const wchar_t *);
41 PyAPI_FUNC(wchar_t *) Py_GetProgramName(void);
42 
43 PyAPI_FUNC(void) Py_SetPythonHome(const wchar_t *);
44 PyAPI_FUNC(wchar_t *) Py_GetPythonHome(void);
45 
46 #ifndef Py_LIMITED_API
47 PyAPI_FUNC(void) _Py_SetProgramFullPath(const wchar_t *);
48 
49 /* Only used by applications that embed the interpreter and need to
50  * override the standard encoding determination mechanism
51  */
52 PyAPI_FUNC(int) Py_SetStandardStreamEncoding(const char *encoding,
53                                              const char *errors);
54 
55 /* PEP 432 Multi-phase initialization API (Private while provisional!) */
56 PyAPI_FUNC(_PyInitError) _Py_InitializeCore(
57     PyInterpreterState **interp_p,
58     const _PyCoreConfig *config);
59 PyAPI_FUNC(int) _Py_IsCoreInitialized(void);
60 PyAPI_FUNC(_PyInitError) _Py_InitializeFromConfig(
61     const _PyCoreConfig *config);
62 #ifdef Py_BUILD_CORE
63 PyAPI_FUNC(void) _Py_Initialize_ReadEnvVarsNoAlloc(void);
64 #endif
65 
66 PyAPI_FUNC(PyObject *) _Py_GetGlobalVariablesAsDict(void);
67 
68 PyAPI_FUNC(_PyInitError) _PyCoreConfig_Read(_PyCoreConfig *);
69 PyAPI_FUNC(void) _PyCoreConfig_Clear(_PyCoreConfig *);
70 PyAPI_FUNC(int) _PyCoreConfig_Copy(
71     _PyCoreConfig *config,
72     const _PyCoreConfig *config2);
73 PyAPI_FUNC(PyObject *) _PyCoreConfig_AsDict(const _PyCoreConfig *config);
74 PyAPI_FUNC(void) _PyCoreConfig_SetGlobalConfig(
75     const _PyCoreConfig *config);
76 
77 
78 PyAPI_FUNC(_PyInitError) _PyMainInterpreterConfig_Read(
79     _PyMainInterpreterConfig *config,
80     const _PyCoreConfig *core_config);
81 PyAPI_FUNC(void) _PyMainInterpreterConfig_Clear(_PyMainInterpreterConfig *);
82 PyAPI_FUNC(int) _PyMainInterpreterConfig_Copy(
83     _PyMainInterpreterConfig *config,
84     const _PyMainInterpreterConfig *config2);
85 /* Used by _testcapi.get_main_config() */
86 PyAPI_FUNC(PyObject*) _PyMainInterpreterConfig_AsDict(
87     const _PyMainInterpreterConfig *config);
88 
89 PyAPI_FUNC(_PyInitError) _Py_InitializeMainInterpreter(
90         PyInterpreterState *interp,
91         const _PyMainInterpreterConfig *config);
92 #endif   /* !defined(Py_LIMITED_API) */
93 
94 
95 /* Initialization and finalization */
96 PyAPI_FUNC(void) Py_Initialize(void);
97 PyAPI_FUNC(void) Py_InitializeEx(int);
98 #ifndef Py_LIMITED_API
99 PyAPI_FUNC(void) _Py_FatalInitError(_PyInitError err) _Py_NO_RETURN;
100 #endif
101 PyAPI_FUNC(void) Py_Finalize(void);
102 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03060000
103 PyAPI_FUNC(int) Py_FinalizeEx(void);
104 #endif
105 PyAPI_FUNC(int) Py_IsInitialized(void);
106 
107 /* Subinterpreter support */
108 PyAPI_FUNC(PyThreadState *) Py_NewInterpreter(void);
109 PyAPI_FUNC(void) Py_EndInterpreter(PyThreadState *);
110 
111 
112 /* Py_PyAtExit is for the atexit module, Py_AtExit is for low-level
113  * exit functions.
114  */
115 #ifndef Py_LIMITED_API
116 PyAPI_FUNC(void) _Py_PyAtExit(void (*func)(PyObject *), PyObject *);
117 #endif
118 PyAPI_FUNC(int) Py_AtExit(void (*func)(void));
119 
120 PyAPI_FUNC(void) Py_Exit(int) _Py_NO_RETURN;
121 
122 /* Restore signals that the interpreter has called SIG_IGN on to SIG_DFL. */
123 #ifndef Py_LIMITED_API
124 PyAPI_FUNC(void) _Py_RestoreSignals(void);
125 
126 PyAPI_FUNC(int) Py_FdIsInteractive(FILE *, const char *);
127 #endif
128 
129 /* Bootstrap __main__ (defined in Modules/main.c) */
130 PyAPI_FUNC(int) Py_Main(int argc, wchar_t **argv);
131 #ifdef Py_BUILD_CORE
132 PyAPI_FUNC(int) _Py_UnixMain(int argc, char **argv);
133 #endif
134 
135 /* In getpath.c */
136 PyAPI_FUNC(wchar_t *) Py_GetProgramFullPath(void);
137 PyAPI_FUNC(wchar_t *) Py_GetPrefix(void);
138 PyAPI_FUNC(wchar_t *) Py_GetExecPrefix(void);
139 PyAPI_FUNC(wchar_t *) Py_GetPath(void);
140 #ifdef Py_BUILD_CORE
141 PyAPI_FUNC(_PyInitError) _PyPathConfig_Init(const _PyCoreConfig *core_config);
142 PyAPI_FUNC(PyObject*) _PyPathConfig_ComputeArgv0(int argc, wchar_t **argv);
143 PyAPI_FUNC(int) _Py_FindEnvConfigValue(
144     FILE *env_file,
145     const wchar_t *key,
146     wchar_t *value,
147     size_t value_size);
148 #endif
149 PyAPI_FUNC(void)      Py_SetPath(const wchar_t *);
150 #ifdef MS_WINDOWS
151 int _Py_CheckPython3(void);
152 #endif
153 
154 /* In their own files */
155 PyAPI_FUNC(const char *) Py_GetVersion(void);
156 PyAPI_FUNC(const char *) Py_GetPlatform(void);
157 PyAPI_FUNC(const char *) Py_GetCopyright(void);
158 PyAPI_FUNC(const char *) Py_GetCompiler(void);
159 PyAPI_FUNC(const char *) Py_GetBuildInfo(void);
160 #ifndef Py_LIMITED_API
161 PyAPI_FUNC(const char *) _Py_gitidentifier(void);
162 PyAPI_FUNC(const char *) _Py_gitversion(void);
163 #endif
164 
165 /* Internal -- various one-time initializations */
166 #ifndef Py_LIMITED_API
167 PyAPI_FUNC(PyObject *) _PyBuiltin_Init(void);
168 PyAPI_FUNC(_PyInitError) _PySys_BeginInit(PyObject **sysmod);
169 PyAPI_FUNC(int) _PySys_EndInit(PyObject *sysdict, _PyMainInterpreterConfig *config);
170 PyAPI_FUNC(_PyInitError) _PyImport_Init(PyInterpreterState *interp);
171 PyAPI_FUNC(void) _PyExc_Init(PyObject * bltinmod);
172 PyAPI_FUNC(_PyInitError) _PyImportHooks_Init(void);
173 PyAPI_FUNC(int) _PyFrame_Init(void);
174 PyAPI_FUNC(int) _PyFloat_Init(void);
175 PyAPI_FUNC(int) PyByteArray_Init(void);
176 PyAPI_FUNC(_PyInitError) _Py_HashRandomization_Init(const _PyCoreConfig *);
177 #endif
178 #ifdef Py_BUILD_CORE
179 PyAPI_FUNC(int) _Py_ReadHashSeed(
180     const char *seed_text,
181     int *use_hash_seed,
182     unsigned long *hash_seed);
183 #endif
184 
185 /* Various internal finalizers */
186 
187 #ifdef Py_BUILD_CORE
188 PyAPI_FUNC(void) _PyExc_Fini(void);
189 PyAPI_FUNC(void) _PyImport_Fini(void);
190 PyAPI_FUNC(void) _PyImport_Fini2(void);
191 PyAPI_FUNC(void) _PyGC_DumpShutdownStats(void);
192 PyAPI_FUNC(void) _PyGC_Fini(void);
193 PyAPI_FUNC(void) _PyType_Fini(void);
194 PyAPI_FUNC(void) _Py_HashRandomization_Fini(void);
195 #endif   /* Py_BUILD_CORE */
196 
197 #ifndef Py_LIMITED_API
198 PyAPI_FUNC(void) PyMethod_Fini(void);
199 PyAPI_FUNC(void) PyFrame_Fini(void);
200 PyAPI_FUNC(void) PyCFunction_Fini(void);
201 PyAPI_FUNC(void) PyDict_Fini(void);
202 PyAPI_FUNC(void) PyTuple_Fini(void);
203 PyAPI_FUNC(void) PyList_Fini(void);
204 PyAPI_FUNC(void) PySet_Fini(void);
205 PyAPI_FUNC(void) PyBytes_Fini(void);
206 PyAPI_FUNC(void) PyByteArray_Fini(void);
207 PyAPI_FUNC(void) PyFloat_Fini(void);
208 PyAPI_FUNC(void) PyOS_FiniInterrupts(void);
209 PyAPI_FUNC(void) PySlice_Fini(void);
210 PyAPI_FUNC(void) PyAsyncGen_Fini(void);
211 
212 PyAPI_FUNC(int) _Py_IsFinalizing(void);
213 #endif   /* !Py_LIMITED_API */
214 
215 /* Signals */
216 typedef void (*PyOS_sighandler_t)(int);
217 PyAPI_FUNC(PyOS_sighandler_t) PyOS_getsig(int);
218 PyAPI_FUNC(PyOS_sighandler_t) PyOS_setsig(int, PyOS_sighandler_t);
219 
220 #ifndef Py_LIMITED_API
221 /* Random */
222 PyAPI_FUNC(int) _PyOS_URandom(void *buffer, Py_ssize_t size);
223 PyAPI_FUNC(int) _PyOS_URandomNonblock(void *buffer, Py_ssize_t size);
224 #endif /* !Py_LIMITED_API */
225 
226 /* Legacy locale support */
227 #ifndef Py_LIMITED_API
228 PyAPI_FUNC(void) _Py_CoerceLegacyLocale(const _PyCoreConfig *config);
229 PyAPI_FUNC(int) _Py_LegacyLocaleDetected(void);
230 PyAPI_FUNC(char *) _Py_SetLocaleFromEnv(int category);
231 #endif
232 
233 #ifdef __cplusplus
234 }
235 #endif
236 #endif /* !Py_PYLIFECYCLE_H */
237