1 #ifndef Py_CPYTHON_PYLIFECYCLE_H 2 # error "this header file must not be included directly" 3 #endif 4 5 /* Py_FrozenMain is kept out of the Limited API until documented and present 6 in all builds of Python */ 7 PyAPI_FUNC(int) Py_FrozenMain(int argc, char **argv); 8 9 /* PEP 432 Multi-phase initialization API (Private while provisional!) */ 10 11 PyAPI_FUNC(PyStatus) Py_PreInitialize( 12 const PyPreConfig *src_config); 13 PyAPI_FUNC(PyStatus) Py_PreInitializeFromBytesArgs( 14 const PyPreConfig *src_config, 15 Py_ssize_t argc, 16 char **argv); 17 PyAPI_FUNC(PyStatus) Py_PreInitializeFromArgs( 18 const PyPreConfig *src_config, 19 Py_ssize_t argc, 20 wchar_t **argv); 21 22 23 /* Initialization and finalization */ 24 25 PyAPI_FUNC(PyStatus) Py_InitializeFromConfig( 26 const PyConfig *config); 27 28 // Python 3.8 provisional API (PEP 587) 29 PyAPI_FUNC(PyStatus) _Py_InitializeMain(void); 30 31 PyAPI_FUNC(int) Py_RunMain(void); 32 33 34 PyAPI_FUNC(void) _Py_NO_RETURN Py_ExitStatusException(PyStatus err); 35 36 PyAPI_FUNC(int) Py_FdIsInteractive(FILE *, const char *); 37 38 /* --- PyInterpreterConfig ------------------------------------ */ 39 40 #define PyInterpreterConfig_DEFAULT_GIL (0) 41 #define PyInterpreterConfig_SHARED_GIL (1) 42 #define PyInterpreterConfig_OWN_GIL (2) 43 44 typedef struct { 45 // XXX "allow_object_sharing"? "own_objects"? 46 int use_main_obmalloc; 47 int allow_fork; 48 int allow_exec; 49 int allow_threads; 50 int allow_daemon_threads; 51 int check_multi_interp_extensions; 52 int gil; 53 } PyInterpreterConfig; 54 55 #define _PyInterpreterConfig_INIT \ 56 { \ 57 .use_main_obmalloc = 0, \ 58 .allow_fork = 0, \ 59 .allow_exec = 0, \ 60 .allow_threads = 1, \ 61 .allow_daemon_threads = 0, \ 62 .check_multi_interp_extensions = 1, \ 63 .gil = PyInterpreterConfig_OWN_GIL, \ 64 } 65 66 // gh-117649: The free-threaded build does not currently support single-phase 67 // init extensions in subinterpreters. For now, we ensure that 68 // `check_multi_interp_extensions` is always `1`, even in the legacy config. 69 #ifdef Py_GIL_DISABLED 70 # define _PyInterpreterConfig_LEGACY_CHECK_MULTI_INTERP_EXTENSIONS 1 71 #else 72 # define _PyInterpreterConfig_LEGACY_CHECK_MULTI_INTERP_EXTENSIONS 0 73 #endif 74 75 #define _PyInterpreterConfig_LEGACY_INIT \ 76 { \ 77 .use_main_obmalloc = 1, \ 78 .allow_fork = 1, \ 79 .allow_exec = 1, \ 80 .allow_threads = 1, \ 81 .allow_daemon_threads = 1, \ 82 .check_multi_interp_extensions = _PyInterpreterConfig_LEGACY_CHECK_MULTI_INTERP_EXTENSIONS, \ 83 .gil = PyInterpreterConfig_SHARED_GIL, \ 84 } 85 86 PyAPI_FUNC(PyStatus) Py_NewInterpreterFromConfig( 87 PyThreadState **tstate_p, 88 const PyInterpreterConfig *config); 89 90 typedef void (*atexit_datacallbackfunc)(void *); 91 PyAPI_FUNC(int) PyUnstable_AtExit( 92 PyInterpreterState *, atexit_datacallbackfunc, void *); 93