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 | |
| 10 | PyAPI_FUNC(void) Py_SetProgramName(wchar_t *); |
| 11 | PyAPI_FUNC(wchar_t *) Py_GetProgramName(void); |
| 12 | |
| 13 | PyAPI_FUNC(void) Py_SetPythonHome(wchar_t *); |
| 14 | PyAPI_FUNC(wchar_t *) Py_GetPythonHome(void); |
| 15 | |
| 16 | #ifndef Py_LIMITED_API |
| 17 | /* Only used by applications that embed the interpreter and need to |
| 18 | * override the standard encoding determination mechanism |
| 19 | */ |
| 20 | PyAPI_FUNC(int) Py_SetStandardStreamEncoding(const char *encoding, |
| 21 | const char *errors); |
Eric Snow | 1abcf67 | 2017-05-23 21:46:51 -0700 | [diff] [blame] | 22 | |
Victor Stinner | f7e5b56 | 2017-11-15 15:48:08 -0800 | [diff] [blame] | 23 | typedef struct { |
| 24 | const char *prefix; |
| 25 | const char *msg; |
| 26 | int user_err; |
| 27 | } _PyInitError; |
| 28 | |
| 29 | /* Almost all errors causing Python initialization to fail */ |
| 30 | #ifdef _MSC_VER |
| 31 | /* Visual Studio 2015 doesn't implement C99 __func__ in C */ |
| 32 | # define _Py_INIT_GET_FUNC() __FUNCTION__ |
| 33 | #else |
| 34 | # define _Py_INIT_GET_FUNC() __func__ |
| 35 | #endif |
| 36 | |
| 37 | #define _Py_INIT_OK() \ |
| 38 | (_PyInitError){.prefix = NULL, .msg = NULL, .user_err = 0} |
| 39 | #define _Py_INIT_ERR(MSG) \ |
| 40 | (_PyInitError){.prefix = _Py_INIT_GET_FUNC(), .msg = (MSG), .user_err = 0} |
| 41 | /* Error that can be fixed by the user like invalid input parameter. |
| 42 | Don't abort() the process on such error. */ |
| 43 | #define _Py_INIT_USER_ERR(MSG) \ |
| 44 | (_PyInitError){.prefix = _Py_INIT_GET_FUNC(), .msg = (MSG), .user_err = 1} |
| 45 | #define _Py_INIT_FAILED(err) \ |
| 46 | (err.msg != NULL) |
| 47 | |
Eric Snow | 1abcf67 | 2017-05-23 21:46:51 -0700 | [diff] [blame] | 48 | /* PEP 432 Multi-phase initialization API (Private while provisional!) */ |
Victor Stinner | f7e5b56 | 2017-11-15 15:48:08 -0800 | [diff] [blame] | 49 | PyAPI_FUNC(_PyInitError) _Py_InitializeCore(const _PyCoreConfig *); |
Eric Snow | 1abcf67 | 2017-05-23 21:46:51 -0700 | [diff] [blame] | 50 | PyAPI_FUNC(int) _Py_IsCoreInitialized(void); |
Victor Stinner | f7e5b56 | 2017-11-15 15:48:08 -0800 | [diff] [blame] | 51 | PyAPI_FUNC(_PyInitError) _Py_ReadMainInterpreterConfig(_PyMainInterpreterConfig *); |
| 52 | PyAPI_FUNC(_PyInitError) _Py_InitializeMainInterpreter(const _PyMainInterpreterConfig *); |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 53 | #endif |
| 54 | |
Eric Snow | 1abcf67 | 2017-05-23 21:46:51 -0700 | [diff] [blame] | 55 | /* Initialization and finalization */ |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 56 | PyAPI_FUNC(void) Py_Initialize(void); |
| 57 | PyAPI_FUNC(void) Py_InitializeEx(int); |
| 58 | #ifndef Py_LIMITED_API |
Victor Stinner | f7e5b56 | 2017-11-15 15:48:08 -0800 | [diff] [blame] | 59 | PyAPI_FUNC(_PyInitError) _Py_InitializeEx_Private(int, int); |
| 60 | PyAPI_FUNC(void) _Py_FatalInitError(_PyInitError err) _Py_NO_RETURN; |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 61 | #endif |
| 62 | PyAPI_FUNC(void) Py_Finalize(void); |
Martin Panter | b4ce1fc | 2015-11-30 03:18:29 +0000 | [diff] [blame] | 63 | PyAPI_FUNC(int) Py_FinalizeEx(void); |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 64 | PyAPI_FUNC(int) Py_IsInitialized(void); |
Eric Snow | 1abcf67 | 2017-05-23 21:46:51 -0700 | [diff] [blame] | 65 | |
| 66 | /* Subinterpreter support */ |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 67 | PyAPI_FUNC(PyThreadState *) Py_NewInterpreter(void); |
| 68 | PyAPI_FUNC(void) Py_EndInterpreter(PyThreadState *); |
| 69 | |
| 70 | |
| 71 | /* Py_PyAtExit is for the atexit module, Py_AtExit is for low-level |
| 72 | * exit functions. |
| 73 | */ |
| 74 | #ifndef Py_LIMITED_API |
| 75 | PyAPI_FUNC(void) _Py_PyAtExit(void (*func)(void)); |
| 76 | #endif |
| 77 | PyAPI_FUNC(int) Py_AtExit(void (*func)(void)); |
| 78 | |
Victor Stinner | f7e5b56 | 2017-11-15 15:48:08 -0800 | [diff] [blame] | 79 | PyAPI_FUNC(void) Py_Exit(int) _Py_NO_RETURN; |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 80 | |
| 81 | /* Restore signals that the interpreter has called SIG_IGN on to SIG_DFL. */ |
| 82 | #ifndef Py_LIMITED_API |
| 83 | PyAPI_FUNC(void) _Py_RestoreSignals(void); |
| 84 | |
| 85 | PyAPI_FUNC(int) Py_FdIsInteractive(FILE *, const char *); |
| 86 | #endif |
| 87 | |
| 88 | /* Bootstrap __main__ (defined in Modules/main.c) */ |
| 89 | PyAPI_FUNC(int) Py_Main(int argc, wchar_t **argv); |
| 90 | |
| 91 | /* In getpath.c */ |
| 92 | PyAPI_FUNC(wchar_t *) Py_GetProgramFullPath(void); |
| 93 | PyAPI_FUNC(wchar_t *) Py_GetPrefix(void); |
| 94 | PyAPI_FUNC(wchar_t *) Py_GetExecPrefix(void); |
| 95 | PyAPI_FUNC(wchar_t *) Py_GetPath(void); |
| 96 | PyAPI_FUNC(void) Py_SetPath(const wchar_t *); |
| 97 | #ifdef MS_WINDOWS |
| 98 | int _Py_CheckPython3(); |
| 99 | #endif |
| 100 | |
| 101 | /* In their own files */ |
| 102 | PyAPI_FUNC(const char *) Py_GetVersion(void); |
| 103 | PyAPI_FUNC(const char *) Py_GetPlatform(void); |
| 104 | PyAPI_FUNC(const char *) Py_GetCopyright(void); |
| 105 | PyAPI_FUNC(const char *) Py_GetCompiler(void); |
| 106 | PyAPI_FUNC(const char *) Py_GetBuildInfo(void); |
| 107 | #ifndef Py_LIMITED_API |
Ned Deily | 5c4b0d0 | 2017-03-04 00:19:55 -0500 | [diff] [blame] | 108 | PyAPI_FUNC(const char *) _Py_gitidentifier(void); |
| 109 | PyAPI_FUNC(const char *) _Py_gitversion(void); |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 110 | #endif |
| 111 | |
| 112 | /* Internal -- various one-time initializations */ |
| 113 | #ifndef Py_LIMITED_API |
| 114 | PyAPI_FUNC(PyObject *) _PyBuiltin_Init(void); |
Victor Stinner | f7e5b56 | 2017-11-15 15:48:08 -0800 | [diff] [blame] | 115 | PyAPI_FUNC(_PyInitError) _PySys_BeginInit(PyObject **sysmod); |
Eric Snow | 6b4be19 | 2017-05-22 21:36:03 -0700 | [diff] [blame] | 116 | PyAPI_FUNC(int) _PySys_EndInit(PyObject *sysdict); |
Victor Stinner | f7e5b56 | 2017-11-15 15:48:08 -0800 | [diff] [blame] | 117 | PyAPI_FUNC(_PyInitError) _PyImport_Init(void); |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 118 | PyAPI_FUNC(void) _PyExc_Init(PyObject * bltinmod); |
Victor Stinner | f7e5b56 | 2017-11-15 15:48:08 -0800 | [diff] [blame] | 119 | PyAPI_FUNC(_PyInitError) _PyImportHooks_Init(void); |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 120 | PyAPI_FUNC(int) _PyFrame_Init(void); |
| 121 | PyAPI_FUNC(int) _PyFloat_Init(void); |
| 122 | PyAPI_FUNC(int) PyByteArray_Init(void); |
Victor Stinner | f7e5b56 | 2017-11-15 15:48:08 -0800 | [diff] [blame] | 123 | PyAPI_FUNC(_PyInitError) _Py_HashRandomization_Init(_PyCoreConfig *core_config); |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 124 | #endif |
| 125 | |
| 126 | /* Various internal finalizers */ |
| 127 | #ifndef Py_LIMITED_API |
| 128 | PyAPI_FUNC(void) _PyExc_Fini(void); |
| 129 | PyAPI_FUNC(void) _PyImport_Fini(void); |
| 130 | PyAPI_FUNC(void) PyMethod_Fini(void); |
| 131 | PyAPI_FUNC(void) PyFrame_Fini(void); |
| 132 | PyAPI_FUNC(void) PyCFunction_Fini(void); |
| 133 | PyAPI_FUNC(void) PyDict_Fini(void); |
| 134 | PyAPI_FUNC(void) PyTuple_Fini(void); |
| 135 | PyAPI_FUNC(void) PyList_Fini(void); |
| 136 | PyAPI_FUNC(void) PySet_Fini(void); |
| 137 | PyAPI_FUNC(void) PyBytes_Fini(void); |
| 138 | PyAPI_FUNC(void) PyByteArray_Fini(void); |
| 139 | PyAPI_FUNC(void) PyFloat_Fini(void); |
| 140 | PyAPI_FUNC(void) PyOS_FiniInterrupts(void); |
| 141 | PyAPI_FUNC(void) _PyGC_DumpShutdownStats(void); |
| 142 | PyAPI_FUNC(void) _PyGC_Fini(void); |
| 143 | PyAPI_FUNC(void) PySlice_Fini(void); |
| 144 | PyAPI_FUNC(void) _PyType_Fini(void); |
Eric Snow | 6b4be19 | 2017-05-22 21:36:03 -0700 | [diff] [blame] | 145 | PyAPI_FUNC(void) _Py_HashRandomization_Fini(void); |
Yury Selivanov | eb63645 | 2016-09-08 22:01:51 -0700 | [diff] [blame] | 146 | PyAPI_FUNC(void) PyAsyncGen_Fini(void); |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 147 | |
Eric Snow | 2ebc5ce | 2017-09-07 23:51:28 -0600 | [diff] [blame] | 148 | PyAPI_FUNC(int) _Py_IsFinalizing(void); |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 149 | #endif |
| 150 | |
| 151 | /* Signals */ |
| 152 | typedef void (*PyOS_sighandler_t)(int); |
| 153 | PyAPI_FUNC(PyOS_sighandler_t) PyOS_getsig(int); |
| 154 | PyAPI_FUNC(PyOS_sighandler_t) PyOS_setsig(int, PyOS_sighandler_t); |
| 155 | |
Serhiy Storchaka | 9fab79b | 2016-09-11 11:03:14 +0300 | [diff] [blame] | 156 | #ifndef Py_LIMITED_API |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 157 | /* Random */ |
Victor Stinner | e66987e | 2016-09-06 16:33:52 -0700 | [diff] [blame] | 158 | PyAPI_FUNC(int) _PyOS_URandom(void *buffer, Py_ssize_t size); |
| 159 | PyAPI_FUNC(int) _PyOS_URandomNonblock(void *buffer, Py_ssize_t size); |
Serhiy Storchaka | 9fab79b | 2016-09-11 11:03:14 +0300 | [diff] [blame] | 160 | #endif /* !Py_LIMITED_API */ |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 161 | |
Erik Bray | 031c4bf | 2017-10-27 11:46:03 +0200 | [diff] [blame] | 162 | /* Legacy locale support */ |
| 163 | #ifndef Py_LIMITED_API |
| 164 | PyAPI_FUNC(void) _Py_CoerceLegacyLocale(void); |
| 165 | PyAPI_FUNC(int) _Py_LegacyLocaleDetected(void); |
xdegaye | 1588be6 | 2017-11-12 12:45:59 +0100 | [diff] [blame] | 166 | PyAPI_FUNC(char *) _Py_SetLocaleFromEnv(int category); |
Erik Bray | 031c4bf | 2017-10-27 11:46:03 +0200 | [diff] [blame] | 167 | #endif |
| 168 | |
Nick Coghlan | d600951 | 2014-11-20 21:39:37 +1000 | [diff] [blame] | 169 | #ifdef __cplusplus |
| 170 | } |
| 171 | #endif |
| 172 | #endif /* !Py_PYLIFECYCLE_H */ |