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 | |
Serhiy Storchaka | 4ae06c5 | 2017-12-12 13:55:04 +0200 | [diff] [blame] | 40 | PyAPI_FUNC(void) Py_SetProgramName(const wchar_t *); |
Victor Stinner | 0327bde | 2017-11-23 17:03:20 +0100 | [diff] [blame] | 41 | PyAPI_FUNC(wchar_t *) Py_GetProgramName(void); |
| 42 | |
Serhiy Storchaka | 4ae06c5 | 2017-12-12 13:55:04 +0200 | [diff] [blame] | 43 | PyAPI_FUNC(void) Py_SetPythonHome(const wchar_t *); |
Victor Stinner | 0327bde | 2017-11-23 17:03:20 +0100 | [diff] [blame] | 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 | |
Victor Stinner | f2626ce | 2018-07-21 03:54:20 +0200 | [diff] [blame^] | 57 | PyAPI_FUNC(_PyInitError) _PyCoreConfig_Read( |
| 58 | _PyCoreConfig *config, |
| 59 | int *isolated, |
| 60 | int *no_site_import); |
Victor Stinner | b5fd9ad | 2017-12-14 02:20:52 +0100 | [diff] [blame] | 61 | PyAPI_FUNC(void) _PyCoreConfig_Clear(_PyCoreConfig *); |
Victor Stinner | da27341 | 2017-12-15 01:46:02 +0100 | [diff] [blame] | 62 | PyAPI_FUNC(int) _PyCoreConfig_Copy( |
| 63 | _PyCoreConfig *config, |
| 64 | const _PyCoreConfig *config2); |
Victor Stinner | f2626ce | 2018-07-21 03:54:20 +0200 | [diff] [blame^] | 65 | PyAPI_FUNC(_PyInitError) _PyCoreConfig_InitPathConfig( |
| 66 | _PyCoreConfig *config, |
| 67 | int *isolated, |
| 68 | int *no_site_import); |
Victor Stinner | b1147e4 | 2018-07-21 02:06:16 +0200 | [diff] [blame] | 69 | PyAPI_FUNC(_PyInitError) _PyCoreConfig_SetPathConfig( |
| 70 | const _PyCoreConfig *config); |
Victor Stinner | b5fd9ad | 2017-12-14 02:20:52 +0100 | [diff] [blame] | 71 | |
Victor Stinner | c4bca95 | 2017-12-19 23:48:17 +0100 | [diff] [blame] | 72 | PyAPI_FUNC(_PyInitError) _PyMainInterpreterConfig_Read( |
| 73 | _PyMainInterpreterConfig *config, |
| 74 | const _PyCoreConfig *core_config); |
Victor Stinner | 46972b7 | 2017-11-24 22:55:40 +0100 | [diff] [blame] | 75 | PyAPI_FUNC(void) _PyMainInterpreterConfig_Clear(_PyMainInterpreterConfig *); |
Victor Stinner | da27341 | 2017-12-15 01:46:02 +0100 | [diff] [blame] | 76 | PyAPI_FUNC(int) _PyMainInterpreterConfig_Copy( |
| 77 | _PyMainInterpreterConfig *config, |
| 78 | const _PyMainInterpreterConfig *config2); |
Victor Stinner | 46972b7 | 2017-11-24 22:55:40 +0100 | [diff] [blame] | 79 | |
Victor Stinner | f7e5b56 | 2017-11-15 15:48:08 -0800 | [diff] [blame] | 80 | PyAPI_FUNC(_PyInitError) _Py_InitializeMainInterpreter(const _PyMainInterpreterConfig *); |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 81 | #endif |
| 82 | |
Eric Snow | 1abcf67 | 2017-05-23 21:46:51 -0700 | [diff] [blame] | 83 | /* Initialization and finalization */ |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 84 | PyAPI_FUNC(void) Py_Initialize(void); |
| 85 | PyAPI_FUNC(void) Py_InitializeEx(int); |
| 86 | #ifndef Py_LIMITED_API |
Victor Stinner | f7e5b56 | 2017-11-15 15:48:08 -0800 | [diff] [blame] | 87 | PyAPI_FUNC(_PyInitError) _Py_InitializeEx_Private(int, int); |
| 88 | PyAPI_FUNC(void) _Py_FatalInitError(_PyInitError err) _Py_NO_RETURN; |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 89 | #endif |
| 90 | PyAPI_FUNC(void) Py_Finalize(void); |
Martin Panter | b4ce1fc | 2015-11-30 03:18:29 +0000 | [diff] [blame] | 91 | PyAPI_FUNC(int) Py_FinalizeEx(void); |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 92 | PyAPI_FUNC(int) Py_IsInitialized(void); |
Eric Snow | 1abcf67 | 2017-05-23 21:46:51 -0700 | [diff] [blame] | 93 | |
| 94 | /* Subinterpreter support */ |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 95 | PyAPI_FUNC(PyThreadState *) Py_NewInterpreter(void); |
| 96 | PyAPI_FUNC(void) Py_EndInterpreter(PyThreadState *); |
| 97 | |
| 98 | |
| 99 | /* Py_PyAtExit is for the atexit module, Py_AtExit is for low-level |
| 100 | * exit functions. |
| 101 | */ |
| 102 | #ifndef Py_LIMITED_API |
Marcel Plch | 776407f | 2017-12-20 11:17:58 +0100 | [diff] [blame] | 103 | PyAPI_FUNC(void) _Py_PyAtExit(void (*func)(PyObject *), PyObject *); |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 104 | #endif |
| 105 | PyAPI_FUNC(int) Py_AtExit(void (*func)(void)); |
| 106 | |
Victor Stinner | f7e5b56 | 2017-11-15 15:48:08 -0800 | [diff] [blame] | 107 | PyAPI_FUNC(void) Py_Exit(int) _Py_NO_RETURN; |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 108 | |
| 109 | /* Restore signals that the interpreter has called SIG_IGN on to SIG_DFL. */ |
| 110 | #ifndef Py_LIMITED_API |
| 111 | PyAPI_FUNC(void) _Py_RestoreSignals(void); |
| 112 | |
| 113 | PyAPI_FUNC(int) Py_FdIsInteractive(FILE *, const char *); |
| 114 | #endif |
| 115 | |
| 116 | /* Bootstrap __main__ (defined in Modules/main.c) */ |
| 117 | PyAPI_FUNC(int) Py_Main(int argc, wchar_t **argv); |
Victor Stinner | 9454060 | 2017-12-16 04:54:22 +0100 | [diff] [blame] | 118 | #ifdef Py_BUILD_CORE |
| 119 | PyAPI_FUNC(int) _Py_UnixMain(int argc, char **argv); |
| 120 | #endif |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 121 | |
| 122 | /* In getpath.c */ |
| 123 | PyAPI_FUNC(wchar_t *) Py_GetProgramFullPath(void); |
| 124 | PyAPI_FUNC(wchar_t *) Py_GetPrefix(void); |
| 125 | PyAPI_FUNC(wchar_t *) Py_GetExecPrefix(void); |
| 126 | PyAPI_FUNC(wchar_t *) Py_GetPath(void); |
Victor Stinner | d434110 | 2017-11-23 00:12:09 +0100 | [diff] [blame] | 127 | #ifdef Py_BUILD_CORE |
Victor Stinner | b1147e4 | 2018-07-21 02:06:16 +0200 | [diff] [blame] | 128 | struct _PyPathConfig; |
| 129 | typedef struct _PyPathConfig _PyPathConfig; |
| 130 | |
| 131 | PyAPI_FUNC(_PyInitError) _PyPathConfig_SetGlobal( |
| 132 | const _PyPathConfig *config); |
Victor Stinner | 11a247d | 2017-12-13 21:05:57 +0100 | [diff] [blame] | 133 | PyAPI_FUNC(PyObject*) _PyPathConfig_ComputeArgv0(int argc, wchar_t **argv); |
Victor Stinner | 9bee329 | 2017-12-21 16:49:13 +0100 | [diff] [blame] | 134 | PyAPI_FUNC(int) _Py_FindEnvConfigValue( |
| 135 | FILE *env_file, |
| 136 | const wchar_t *key, |
| 137 | wchar_t *value, |
| 138 | size_t value_size); |
Victor Stinner | d434110 | 2017-11-23 00:12:09 +0100 | [diff] [blame] | 139 | #endif |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 140 | PyAPI_FUNC(void) Py_SetPath(const wchar_t *); |
| 141 | #ifdef MS_WINDOWS |
Victor Stinner | 31a8393 | 2017-12-04 13:39:15 +0100 | [diff] [blame] | 142 | int _Py_CheckPython3(void); |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 143 | #endif |
| 144 | |
| 145 | /* In their own files */ |
| 146 | PyAPI_FUNC(const char *) Py_GetVersion(void); |
| 147 | PyAPI_FUNC(const char *) Py_GetPlatform(void); |
| 148 | PyAPI_FUNC(const char *) Py_GetCopyright(void); |
| 149 | PyAPI_FUNC(const char *) Py_GetCompiler(void); |
| 150 | PyAPI_FUNC(const char *) Py_GetBuildInfo(void); |
| 151 | #ifndef Py_LIMITED_API |
Ned Deily | 5c4b0d0 | 2017-03-04 00:19:55 -0500 | [diff] [blame] | 152 | PyAPI_FUNC(const char *) _Py_gitidentifier(void); |
| 153 | PyAPI_FUNC(const char *) _Py_gitversion(void); |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 154 | #endif |
| 155 | |
| 156 | /* Internal -- various one-time initializations */ |
| 157 | #ifndef Py_LIMITED_API |
| 158 | PyAPI_FUNC(PyObject *) _PyBuiltin_Init(void); |
Victor Stinner | f7e5b56 | 2017-11-15 15:48:08 -0800 | [diff] [blame] | 159 | PyAPI_FUNC(_PyInitError) _PySys_BeginInit(PyObject **sysmod); |
Victor Stinner | 41264f1 | 2017-12-15 02:05:29 +0100 | [diff] [blame] | 160 | PyAPI_FUNC(int) _PySys_EndInit(PyObject *sysdict, _PyMainInterpreterConfig *config); |
Victor Stinner | 672b6ba | 2017-12-06 17:25:50 +0100 | [diff] [blame] | 161 | PyAPI_FUNC(_PyInitError) _PyImport_Init(PyInterpreterState *interp); |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 162 | PyAPI_FUNC(void) _PyExc_Init(PyObject * bltinmod); |
Victor Stinner | f7e5b56 | 2017-11-15 15:48:08 -0800 | [diff] [blame] | 163 | PyAPI_FUNC(_PyInitError) _PyImportHooks_Init(void); |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 164 | PyAPI_FUNC(int) _PyFloat_Init(void); |
| 165 | PyAPI_FUNC(int) PyByteArray_Init(void); |
Victor Stinner | 358e5e1 | 2017-12-15 00:51:22 +0100 | [diff] [blame] | 166 | PyAPI_FUNC(_PyInitError) _Py_HashRandomization_Init(const _PyCoreConfig *); |
| 167 | #endif |
| 168 | #ifdef Py_BUILD_CORE |
| 169 | PyAPI_FUNC(int) _Py_ReadHashSeed( |
| 170 | const char *seed_text, |
| 171 | int *use_hash_seed, |
| 172 | unsigned long *hash_seed); |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 173 | #endif |
| 174 | |
| 175 | /* Various internal finalizers */ |
Victor Stinner | 92a3c6f | 2017-12-06 18:12:59 +0100 | [diff] [blame] | 176 | |
| 177 | #ifdef Py_BUILD_CORE |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 178 | PyAPI_FUNC(void) _PyExc_Fini(void); |
| 179 | PyAPI_FUNC(void) _PyImport_Fini(void); |
Victor Stinner | 92a3c6f | 2017-12-06 18:12:59 +0100 | [diff] [blame] | 180 | PyAPI_FUNC(void) _PyImport_Fini2(void); |
| 181 | PyAPI_FUNC(void) _PyGC_DumpShutdownStats(void); |
| 182 | PyAPI_FUNC(void) _PyGC_Fini(void); |
| 183 | PyAPI_FUNC(void) _PyType_Fini(void); |
| 184 | PyAPI_FUNC(void) _Py_HashRandomization_Fini(void); |
| 185 | #endif /* Py_BUILD_CORE */ |
| 186 | |
| 187 | #ifndef Py_LIMITED_API |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 188 | PyAPI_FUNC(void) PyMethod_Fini(void); |
| 189 | PyAPI_FUNC(void) PyFrame_Fini(void); |
| 190 | PyAPI_FUNC(void) PyCFunction_Fini(void); |
| 191 | PyAPI_FUNC(void) PyDict_Fini(void); |
| 192 | PyAPI_FUNC(void) PyTuple_Fini(void); |
| 193 | PyAPI_FUNC(void) PyList_Fini(void); |
| 194 | PyAPI_FUNC(void) PySet_Fini(void); |
| 195 | PyAPI_FUNC(void) PyBytes_Fini(void); |
| 196 | PyAPI_FUNC(void) PyByteArray_Fini(void); |
| 197 | PyAPI_FUNC(void) PyFloat_Fini(void); |
| 198 | PyAPI_FUNC(void) PyOS_FiniInterrupts(void); |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 199 | PyAPI_FUNC(void) PySlice_Fini(void); |
Yury Selivanov | eb63645 | 2016-09-08 22:01:51 -0700 | [diff] [blame] | 200 | PyAPI_FUNC(void) PyAsyncGen_Fini(void); |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 201 | |
Eric Snow | 2ebc5ce | 2017-09-07 23:51:28 -0600 | [diff] [blame] | 202 | PyAPI_FUNC(int) _Py_IsFinalizing(void); |
Victor Stinner | 92a3c6f | 2017-12-06 18:12:59 +0100 | [diff] [blame] | 203 | #endif /* !Py_LIMITED_API */ |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 204 | |
| 205 | /* Signals */ |
| 206 | typedef void (*PyOS_sighandler_t)(int); |
| 207 | PyAPI_FUNC(PyOS_sighandler_t) PyOS_getsig(int); |
| 208 | PyAPI_FUNC(PyOS_sighandler_t) PyOS_setsig(int, PyOS_sighandler_t); |
| 209 | |
Serhiy Storchaka | 9fab79b | 2016-09-11 11:03:14 +0300 | [diff] [blame] | 210 | #ifndef Py_LIMITED_API |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 211 | /* Random */ |
Victor Stinner | e66987e | 2016-09-06 16:33:52 -0700 | [diff] [blame] | 212 | PyAPI_FUNC(int) _PyOS_URandom(void *buffer, Py_ssize_t size); |
| 213 | PyAPI_FUNC(int) _PyOS_URandomNonblock(void *buffer, Py_ssize_t size); |
Serhiy Storchaka | 9fab79b | 2016-09-11 11:03:14 +0300 | [diff] [blame] | 214 | #endif /* !Py_LIMITED_API */ |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 215 | |
Erik Bray | 031c4bf | 2017-10-27 11:46:03 +0200 | [diff] [blame] | 216 | /* Legacy locale support */ |
| 217 | #ifndef Py_LIMITED_API |
Victor Stinner | 9454060 | 2017-12-16 04:54:22 +0100 | [diff] [blame] | 218 | PyAPI_FUNC(void) _Py_CoerceLegacyLocale(const _PyCoreConfig *config); |
Erik Bray | 031c4bf | 2017-10-27 11:46:03 +0200 | [diff] [blame] | 219 | PyAPI_FUNC(int) _Py_LegacyLocaleDetected(void); |
xdegaye | 1588be6 | 2017-11-12 12:45:59 +0100 | [diff] [blame] | 220 | PyAPI_FUNC(char *) _Py_SetLocaleFromEnv(int category); |
Erik Bray | 031c4bf | 2017-10-27 11:46:03 +0200 | [diff] [blame] | 221 | #endif |
| 222 | |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 223 | #ifdef __cplusplus |
| 224 | } |
| 225 | #endif |
| 226 | #endif /* !Py_PYLIFECYCLE_H */ |