Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 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 | |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 10 | #ifndef Py_LIMITED_API |
Victor Stinner | f7e5b56 | 2017-11-15 15:48:08 -0800 | [diff] [blame] | 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} |
Victor Stinner | 46972b7 | 2017-11-24 22:55:40 +0100 | [diff] [blame] | 33 | #define _Py_INIT_NO_MEMORY() _Py_INIT_USER_ERR("memory allocation failed") |
Victor Stinner | f7e5b56 | 2017-11-15 15:48:08 -0800 | [diff] [blame] | 34 | #define _Py_INIT_FAILED(err) \ |
| 35 | (err.msg != NULL) |
| 36 | |
Victor Stinner | 0327bde | 2017-11-23 17:03:20 +0100 | [diff] [blame] | 37 | #endif |
| 38 | |
| 39 | |
| 40 | PyAPI_FUNC(void) Py_SetProgramName(wchar_t *); |
| 41 | PyAPI_FUNC(wchar_t *) Py_GetProgramName(void); |
| 42 | |
| 43 | PyAPI_FUNC(void) Py_SetPythonHome(wchar_t *); |
| 44 | PyAPI_FUNC(wchar_t *) Py_GetPythonHome(void); |
Victor Stinner | 0327bde | 2017-11-23 17:03:20 +0100 | [diff] [blame] | 45 | |
| 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 | */ |
| 50 | PyAPI_FUNC(int) Py_SetStandardStreamEncoding(const char *encoding, |
| 51 | const char *errors); |
| 52 | |
Eric Snow | 1abcf67 | 2017-05-23 21:46:51 -0700 | [diff] [blame] | 53 | /* PEP 432 Multi-phase initialization API (Private while provisional!) */ |
Victor Stinner | f7e5b56 | 2017-11-15 15:48:08 -0800 | [diff] [blame] | 54 | PyAPI_FUNC(_PyInitError) _Py_InitializeCore(const _PyCoreConfig *); |
Eric Snow | 1abcf67 | 2017-05-23 21:46:51 -0700 | [diff] [blame] | 55 | PyAPI_FUNC(int) _Py_IsCoreInitialized(void); |
Victor Stinner | 46972b7 | 2017-11-24 22:55:40 +0100 | [diff] [blame] | 56 | |
| 57 | PyAPI_FUNC(_PyInitError) _PyMainInterpreterConfig_Read(_PyMainInterpreterConfig *); |
| 58 | PyAPI_FUNC(_PyInitError) _PyMainInterpreterConfig_ReadEnv(_PyMainInterpreterConfig *); |
| 59 | PyAPI_FUNC(void) _PyMainInterpreterConfig_Clear(_PyMainInterpreterConfig *); |
| 60 | |
Victor Stinner | f7e5b56 | 2017-11-15 15:48:08 -0800 | [diff] [blame] | 61 | PyAPI_FUNC(_PyInitError) _Py_InitializeMainInterpreter(const _PyMainInterpreterConfig *); |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 62 | #endif |
| 63 | |
Eric Snow | 1abcf67 | 2017-05-23 21:46:51 -0700 | [diff] [blame] | 64 | /* Initialization and finalization */ |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 65 | PyAPI_FUNC(void) Py_Initialize(void); |
| 66 | PyAPI_FUNC(void) Py_InitializeEx(int); |
| 67 | #ifndef Py_LIMITED_API |
Victor Stinner | f7e5b56 | 2017-11-15 15:48:08 -0800 | [diff] [blame] | 68 | PyAPI_FUNC(_PyInitError) _Py_InitializeEx_Private(int, int); |
| 69 | PyAPI_FUNC(void) _Py_FatalInitError(_PyInitError err) _Py_NO_RETURN; |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 70 | #endif |
| 71 | PyAPI_FUNC(void) Py_Finalize(void); |
Martin Panter | b4ce1fc | 2015-11-30 03:18:29 +0000 | [diff] [blame] | 72 | PyAPI_FUNC(int) Py_FinalizeEx(void); |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 73 | PyAPI_FUNC(int) Py_IsInitialized(void); |
Eric Snow | 1abcf67 | 2017-05-23 21:46:51 -0700 | [diff] [blame] | 74 | |
| 75 | /* Subinterpreter support */ |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 76 | PyAPI_FUNC(PyThreadState *) Py_NewInterpreter(void); |
| 77 | PyAPI_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 |
| 84 | PyAPI_FUNC(void) _Py_PyAtExit(void (*func)(void)); |
| 85 | #endif |
| 86 | PyAPI_FUNC(int) Py_AtExit(void (*func)(void)); |
| 87 | |
Victor Stinner | f7e5b56 | 2017-11-15 15:48:08 -0800 | [diff] [blame] | 88 | PyAPI_FUNC(void) Py_Exit(int) _Py_NO_RETURN; |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 89 | |
| 90 | /* Restore signals that the interpreter has called SIG_IGN on to SIG_DFL. */ |
| 91 | #ifndef Py_LIMITED_API |
| 92 | PyAPI_FUNC(void) _Py_RestoreSignals(void); |
| 93 | |
| 94 | PyAPI_FUNC(int) Py_FdIsInteractive(FILE *, const char *); |
| 95 | #endif |
| 96 | |
| 97 | /* Bootstrap __main__ (defined in Modules/main.c) */ |
| 98 | PyAPI_FUNC(int) Py_Main(int argc, wchar_t **argv); |
| 99 | |
| 100 | /* In getpath.c */ |
| 101 | PyAPI_FUNC(wchar_t *) Py_GetProgramFullPath(void); |
| 102 | PyAPI_FUNC(wchar_t *) Py_GetPrefix(void); |
| 103 | PyAPI_FUNC(wchar_t *) Py_GetExecPrefix(void); |
| 104 | PyAPI_FUNC(wchar_t *) Py_GetPath(void); |
Victor Stinner | d434110 | 2017-11-23 00:12:09 +0100 | [diff] [blame] | 105 | #ifdef Py_BUILD_CORE |
Victor Stinner | 9316ee4 | 2017-11-25 03:17:57 +0100 | [diff] [blame] | 106 | PyAPI_FUNC(_PyInitError) _PyPathConfig_Init( |
| 107 | const _PyMainInterpreterConfig *main_config); |
Victor Stinner | d434110 | 2017-11-23 00:12:09 +0100 | [diff] [blame] | 108 | #endif |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 109 | PyAPI_FUNC(void) Py_SetPath(const wchar_t *); |
| 110 | #ifdef MS_WINDOWS |
Victor Stinner | 31a8393 | 2017-12-04 13:39:15 +0100 | [diff] [blame] | 111 | int _Py_CheckPython3(void); |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 112 | #endif |
| 113 | |
| 114 | /* In their own files */ |
| 115 | PyAPI_FUNC(const char *) Py_GetVersion(void); |
| 116 | PyAPI_FUNC(const char *) Py_GetPlatform(void); |
| 117 | PyAPI_FUNC(const char *) Py_GetCopyright(void); |
| 118 | PyAPI_FUNC(const char *) Py_GetCompiler(void); |
| 119 | PyAPI_FUNC(const char *) Py_GetBuildInfo(void); |
| 120 | #ifndef Py_LIMITED_API |
Ned Deily | 5c4b0d0 | 2017-03-04 00:19:55 -0500 | [diff] [blame] | 121 | PyAPI_FUNC(const char *) _Py_gitidentifier(void); |
| 122 | PyAPI_FUNC(const char *) _Py_gitversion(void); |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 123 | #endif |
| 124 | |
| 125 | /* Internal -- various one-time initializations */ |
| 126 | #ifndef Py_LIMITED_API |
| 127 | PyAPI_FUNC(PyObject *) _PyBuiltin_Init(void); |
Victor Stinner | f7e5b56 | 2017-11-15 15:48:08 -0800 | [diff] [blame] | 128 | PyAPI_FUNC(_PyInitError) _PySys_BeginInit(PyObject **sysmod); |
Eric Snow | 6b4be19 | 2017-05-22 21:36:03 -0700 | [diff] [blame] | 129 | PyAPI_FUNC(int) _PySys_EndInit(PyObject *sysdict); |
Victor Stinner | f7e5b56 | 2017-11-15 15:48:08 -0800 | [diff] [blame] | 130 | PyAPI_FUNC(_PyInitError) _PyImport_Init(void); |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 131 | PyAPI_FUNC(void) _PyExc_Init(PyObject * bltinmod); |
Victor Stinner | f7e5b56 | 2017-11-15 15:48:08 -0800 | [diff] [blame] | 132 | PyAPI_FUNC(_PyInitError) _PyImportHooks_Init(void); |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 133 | PyAPI_FUNC(int) _PyFrame_Init(void); |
| 134 | PyAPI_FUNC(int) _PyFloat_Init(void); |
| 135 | PyAPI_FUNC(int) PyByteArray_Init(void); |
Victor Stinner | f7e5b56 | 2017-11-15 15:48:08 -0800 | [diff] [blame] | 136 | PyAPI_FUNC(_PyInitError) _Py_HashRandomization_Init(_PyCoreConfig *core_config); |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 137 | #endif |
| 138 | |
| 139 | /* Various internal finalizers */ |
| 140 | #ifndef Py_LIMITED_API |
| 141 | PyAPI_FUNC(void) _PyExc_Fini(void); |
| 142 | PyAPI_FUNC(void) _PyImport_Fini(void); |
| 143 | PyAPI_FUNC(void) PyMethod_Fini(void); |
| 144 | PyAPI_FUNC(void) PyFrame_Fini(void); |
| 145 | PyAPI_FUNC(void) PyCFunction_Fini(void); |
| 146 | PyAPI_FUNC(void) PyDict_Fini(void); |
| 147 | PyAPI_FUNC(void) PyTuple_Fini(void); |
| 148 | PyAPI_FUNC(void) PyList_Fini(void); |
| 149 | PyAPI_FUNC(void) PySet_Fini(void); |
| 150 | PyAPI_FUNC(void) PyBytes_Fini(void); |
| 151 | PyAPI_FUNC(void) PyByteArray_Fini(void); |
| 152 | PyAPI_FUNC(void) PyFloat_Fini(void); |
| 153 | PyAPI_FUNC(void) PyOS_FiniInterrupts(void); |
| 154 | PyAPI_FUNC(void) _PyGC_DumpShutdownStats(void); |
| 155 | PyAPI_FUNC(void) _PyGC_Fini(void); |
| 156 | PyAPI_FUNC(void) PySlice_Fini(void); |
| 157 | PyAPI_FUNC(void) _PyType_Fini(void); |
Eric Snow | 6b4be19 | 2017-05-22 21:36:03 -0700 | [diff] [blame] | 158 | PyAPI_FUNC(void) _Py_HashRandomization_Fini(void); |
Yury Selivanov | eb63645 | 2016-09-08 22:01:51 -0700 | [diff] [blame] | 159 | PyAPI_FUNC(void) PyAsyncGen_Fini(void); |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 160 | |
Eric Snow | 2ebc5ce | 2017-09-07 23:51:28 -0600 | [diff] [blame] | 161 | PyAPI_FUNC(int) _Py_IsFinalizing(void); |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 162 | #endif |
| 163 | |
| 164 | /* Signals */ |
| 165 | typedef void (*PyOS_sighandler_t)(int); |
| 166 | PyAPI_FUNC(PyOS_sighandler_t) PyOS_getsig(int); |
| 167 | PyAPI_FUNC(PyOS_sighandler_t) PyOS_setsig(int, PyOS_sighandler_t); |
| 168 | |
Serhiy Storchaka | 9fab79b | 2016-09-11 11:03:14 +0300 | [diff] [blame] | 169 | #ifndef Py_LIMITED_API |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 170 | /* Random */ |
Victor Stinner | e66987e | 2016-09-06 16:33:52 -0700 | [diff] [blame] | 171 | PyAPI_FUNC(int) _PyOS_URandom(void *buffer, Py_ssize_t size); |
| 172 | PyAPI_FUNC(int) _PyOS_URandomNonblock(void *buffer, Py_ssize_t size); |
Serhiy Storchaka | 9fab79b | 2016-09-11 11:03:14 +0300 | [diff] [blame] | 173 | #endif /* !Py_LIMITED_API */ |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 174 | |
Erik Bray | 031c4bf | 2017-10-27 11:46:03 +0200 | [diff] [blame] | 175 | /* Legacy locale support */ |
| 176 | #ifndef Py_LIMITED_API |
| 177 | PyAPI_FUNC(void) _Py_CoerceLegacyLocale(void); |
| 178 | PyAPI_FUNC(int) _Py_LegacyLocaleDetected(void); |
xdegaye | 1588be6 | 2017-11-12 12:45:59 +0100 | [diff] [blame] | 179 | PyAPI_FUNC(char *) _Py_SetLocaleFromEnv(int category); |
Erik Bray | 031c4bf | 2017-10-27 11:46:03 +0200 | [diff] [blame] | 180 | #endif |
| 181 | |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 182 | #ifdef __cplusplus |
| 183 | } |
| 184 | #endif |
| 185 | #endif /* !Py_PYLIFECYCLE_H */ |