blob: fa751692a6670a3f10ddf0ad7bc4ed4e2457f0f2 [file] [log] [blame]
Nick Coghland6009512014-11-20 21:39:37 +10001
2/* Interfaces to configure, query, create & destroy the Python runtime */
3
4#ifndef Py_PYLIFECYCLE_H
5#define Py_PYLIFECYCLE_H
6#ifdef __cplusplus
7extern "C" {
8#endif
9
Nick Coghland6009512014-11-20 21:39:37 +100010#ifndef Py_LIMITED_API
Victor Stinnerf7e5b562017-11-15 15:48:08 -080011typedef 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}
Victor Stinner46972b72017-11-24 22:55:40 +010033#define _Py_INIT_NO_MEMORY() _Py_INIT_USER_ERR("memory allocation failed")
Victor Stinnerf7e5b562017-11-15 15:48:08 -080034#define _Py_INIT_FAILED(err) \
35 (err.msg != NULL)
36
Victor Stinner0327bde2017-11-23 17:03:20 +010037#endif
38
39
40PyAPI_FUNC(void) Py_SetProgramName(wchar_t *);
41PyAPI_FUNC(wchar_t *) Py_GetProgramName(void);
42
43PyAPI_FUNC(void) Py_SetPythonHome(wchar_t *);
44PyAPI_FUNC(wchar_t *) Py_GetPythonHome(void);
Victor Stinner0327bde2017-11-23 17:03:20 +010045
46#ifndef Py_LIMITED_API
47/* Only used by applications that embed the interpreter and need to
48 * override the standard encoding determination mechanism
49 */
50PyAPI_FUNC(int) Py_SetStandardStreamEncoding(const char *encoding,
51 const char *errors);
52
Eric Snow1abcf672017-05-23 21:46:51 -070053/* PEP 432 Multi-phase initialization API (Private while provisional!) */
Victor Stinnerf7e5b562017-11-15 15:48:08 -080054PyAPI_FUNC(_PyInitError) _Py_InitializeCore(const _PyCoreConfig *);
Eric Snow1abcf672017-05-23 21:46:51 -070055PyAPI_FUNC(int) _Py_IsCoreInitialized(void);
Victor Stinner46972b72017-11-24 22:55:40 +010056
57PyAPI_FUNC(_PyInitError) _PyMainInterpreterConfig_Read(_PyMainInterpreterConfig *);
58PyAPI_FUNC(_PyInitError) _PyMainInterpreterConfig_ReadEnv(_PyMainInterpreterConfig *);
59PyAPI_FUNC(void) _PyMainInterpreterConfig_Clear(_PyMainInterpreterConfig *);
60
Victor Stinnerf7e5b562017-11-15 15:48:08 -080061PyAPI_FUNC(_PyInitError) _Py_InitializeMainInterpreter(const _PyMainInterpreterConfig *);
Nick Coghland6009512014-11-20 21:39:37 +100062#endif
63
Eric Snow1abcf672017-05-23 21:46:51 -070064/* Initialization and finalization */
Nick Coghland6009512014-11-20 21:39:37 +100065PyAPI_FUNC(void) Py_Initialize(void);
66PyAPI_FUNC(void) Py_InitializeEx(int);
67#ifndef Py_LIMITED_API
Victor Stinnerf7e5b562017-11-15 15:48:08 -080068PyAPI_FUNC(_PyInitError) _Py_InitializeEx_Private(int, int);
69PyAPI_FUNC(void) _Py_FatalInitError(_PyInitError err) _Py_NO_RETURN;
Nick Coghland6009512014-11-20 21:39:37 +100070#endif
71PyAPI_FUNC(void) Py_Finalize(void);
Martin Panterb4ce1fc2015-11-30 03:18:29 +000072PyAPI_FUNC(int) Py_FinalizeEx(void);
Nick Coghland6009512014-11-20 21:39:37 +100073PyAPI_FUNC(int) Py_IsInitialized(void);
Eric Snow1abcf672017-05-23 21:46:51 -070074
75/* Subinterpreter support */
Nick Coghland6009512014-11-20 21:39:37 +100076PyAPI_FUNC(PyThreadState *) Py_NewInterpreter(void);
77PyAPI_FUNC(void) Py_EndInterpreter(PyThreadState *);
78
79
80/* Py_PyAtExit is for the atexit module, Py_AtExit is for low-level
81 * exit functions.
82 */
83#ifndef Py_LIMITED_API
84PyAPI_FUNC(void) _Py_PyAtExit(void (*func)(void));
85#endif
86PyAPI_FUNC(int) Py_AtExit(void (*func)(void));
87
Victor Stinnerf7e5b562017-11-15 15:48:08 -080088PyAPI_FUNC(void) Py_Exit(int) _Py_NO_RETURN;
Nick Coghland6009512014-11-20 21:39:37 +100089
90/* Restore signals that the interpreter has called SIG_IGN on to SIG_DFL. */
91#ifndef Py_LIMITED_API
92PyAPI_FUNC(void) _Py_RestoreSignals(void);
93
94PyAPI_FUNC(int) Py_FdIsInteractive(FILE *, const char *);
95#endif
96
97/* Bootstrap __main__ (defined in Modules/main.c) */
98PyAPI_FUNC(int) Py_Main(int argc, wchar_t **argv);
99
100/* In getpath.c */
101PyAPI_FUNC(wchar_t *) Py_GetProgramFullPath(void);
102PyAPI_FUNC(wchar_t *) Py_GetPrefix(void);
103PyAPI_FUNC(wchar_t *) Py_GetExecPrefix(void);
104PyAPI_FUNC(wchar_t *) Py_GetPath(void);
Victor Stinnerd4341102017-11-23 00:12:09 +0100105#ifdef Py_BUILD_CORE
Victor Stinner9316ee42017-11-25 03:17:57 +0100106PyAPI_FUNC(_PyInitError) _PyPathConfig_Init(
107 const _PyMainInterpreterConfig *main_config);
Victor Stinnerd4341102017-11-23 00:12:09 +0100108#endif
Nick Coghland6009512014-11-20 21:39:37 +1000109PyAPI_FUNC(void) Py_SetPath(const wchar_t *);
110#ifdef MS_WINDOWS
Victor Stinner31a83932017-12-04 13:39:15 +0100111int _Py_CheckPython3(void);
Nick Coghland6009512014-11-20 21:39:37 +1000112#endif
113
114/* In their own files */
115PyAPI_FUNC(const char *) Py_GetVersion(void);
116PyAPI_FUNC(const char *) Py_GetPlatform(void);
117PyAPI_FUNC(const char *) Py_GetCopyright(void);
118PyAPI_FUNC(const char *) Py_GetCompiler(void);
119PyAPI_FUNC(const char *) Py_GetBuildInfo(void);
120#ifndef Py_LIMITED_API
Ned Deily5c4b0d02017-03-04 00:19:55 -0500121PyAPI_FUNC(const char *) _Py_gitidentifier(void);
122PyAPI_FUNC(const char *) _Py_gitversion(void);
Nick Coghland6009512014-11-20 21:39:37 +1000123#endif
124
125/* Internal -- various one-time initializations */
126#ifndef Py_LIMITED_API
127PyAPI_FUNC(PyObject *) _PyBuiltin_Init(void);
Victor Stinnerf7e5b562017-11-15 15:48:08 -0800128PyAPI_FUNC(_PyInitError) _PySys_BeginInit(PyObject **sysmod);
Eric Snow6b4be192017-05-22 21:36:03 -0700129PyAPI_FUNC(int) _PySys_EndInit(PyObject *sysdict);
Victor Stinnerf7e5b562017-11-15 15:48:08 -0800130PyAPI_FUNC(_PyInitError) _PyImport_Init(void);
Nick Coghland6009512014-11-20 21:39:37 +1000131PyAPI_FUNC(void) _PyExc_Init(PyObject * bltinmod);
Victor Stinnerf7e5b562017-11-15 15:48:08 -0800132PyAPI_FUNC(_PyInitError) _PyImportHooks_Init(void);
Nick Coghland6009512014-11-20 21:39:37 +1000133PyAPI_FUNC(int) _PyFrame_Init(void);
134PyAPI_FUNC(int) _PyFloat_Init(void);
135PyAPI_FUNC(int) PyByteArray_Init(void);
Victor Stinnerf7e5b562017-11-15 15:48:08 -0800136PyAPI_FUNC(_PyInitError) _Py_HashRandomization_Init(_PyCoreConfig *core_config);
Nick Coghland6009512014-11-20 21:39:37 +1000137#endif
138
139/* Various internal finalizers */
140#ifndef Py_LIMITED_API
141PyAPI_FUNC(void) _PyExc_Fini(void);
142PyAPI_FUNC(void) _PyImport_Fini(void);
143PyAPI_FUNC(void) PyMethod_Fini(void);
144PyAPI_FUNC(void) PyFrame_Fini(void);
145PyAPI_FUNC(void) PyCFunction_Fini(void);
146PyAPI_FUNC(void) PyDict_Fini(void);
147PyAPI_FUNC(void) PyTuple_Fini(void);
148PyAPI_FUNC(void) PyList_Fini(void);
149PyAPI_FUNC(void) PySet_Fini(void);
150PyAPI_FUNC(void) PyBytes_Fini(void);
151PyAPI_FUNC(void) PyByteArray_Fini(void);
152PyAPI_FUNC(void) PyFloat_Fini(void);
153PyAPI_FUNC(void) PyOS_FiniInterrupts(void);
154PyAPI_FUNC(void) _PyGC_DumpShutdownStats(void);
155PyAPI_FUNC(void) _PyGC_Fini(void);
156PyAPI_FUNC(void) PySlice_Fini(void);
157PyAPI_FUNC(void) _PyType_Fini(void);
Eric Snow6b4be192017-05-22 21:36:03 -0700158PyAPI_FUNC(void) _Py_HashRandomization_Fini(void);
Yury Selivanoveb636452016-09-08 22:01:51 -0700159PyAPI_FUNC(void) PyAsyncGen_Fini(void);
Nick Coghland6009512014-11-20 21:39:37 +1000160
Eric Snow2ebc5ce2017-09-07 23:51:28 -0600161PyAPI_FUNC(int) _Py_IsFinalizing(void);
Nick Coghland6009512014-11-20 21:39:37 +1000162#endif
163
164/* Signals */
165typedef void (*PyOS_sighandler_t)(int);
166PyAPI_FUNC(PyOS_sighandler_t) PyOS_getsig(int);
167PyAPI_FUNC(PyOS_sighandler_t) PyOS_setsig(int, PyOS_sighandler_t);
168
Serhiy Storchaka9fab79b2016-09-11 11:03:14 +0300169#ifndef Py_LIMITED_API
Nick Coghland6009512014-11-20 21:39:37 +1000170/* Random */
Victor Stinnere66987e2016-09-06 16:33:52 -0700171PyAPI_FUNC(int) _PyOS_URandom(void *buffer, Py_ssize_t size);
172PyAPI_FUNC(int) _PyOS_URandomNonblock(void *buffer, Py_ssize_t size);
Serhiy Storchaka9fab79b2016-09-11 11:03:14 +0300173#endif /* !Py_LIMITED_API */
Nick Coghland6009512014-11-20 21:39:37 +1000174
Erik Bray031c4bf2017-10-27 11:46:03 +0200175/* Legacy locale support */
176#ifndef Py_LIMITED_API
177PyAPI_FUNC(void) _Py_CoerceLegacyLocale(void);
178PyAPI_FUNC(int) _Py_LegacyLocaleDetected(void);
xdegaye1588be62017-11-12 12:45:59 +0100179PyAPI_FUNC(char *) _Py_SetLocaleFromEnv(int category);
Erik Bray031c4bf2017-10-27 11:46:03 +0200180#endif
181
Nick Coghland6009512014-11-20 21:39:37 +1000182#ifdef __cplusplus
183}
184#endif
185#endif /* !Py_PYLIFECYCLE_H */