Skip to main content

pyforge_ffi/
pylifecycle.rs

1use crate::pytypedefs::PyThreadState;
2
3use libc::wchar_t;
4use std::ffi::{c_char, c_int};
5
6extern_libpython! {
7    pub fn Py_Initialize();
8    pub fn Py_InitializeEx(arg1: c_int);
9    pub fn Py_Finalize();
10    pub fn Py_FinalizeEx() -> c_int;
11
12    pub fn Py_IsInitialized() -> c_int;
13
14    pub fn Py_NewInterpreter() -> *mut PyThreadState;
15    pub fn Py_EndInterpreter(arg1: *mut PyThreadState);
16
17    pub fn Py_AtExit(func: Option<extern "C" fn()>) -> c_int;
18
19    pub fn Py_Exit(arg1: c_int) -> !;
20
21    pub fn Py_Main(argc: c_int, argv: *mut *mut wchar_t) -> c_int;
22    pub fn Py_BytesMain(argc: c_int, argv: *mut *mut c_char) -> c_int;
23
24    #[cfg_attr(
25        Py_3_11,
26        deprecated(note = "Deprecated since Python 3.11. Use `PyConfig.program_name` instead.")
27    )]
28    pub fn Py_SetProgramName(arg1: *const wchar_t);
29    #[cfg_attr(
30        Py_3_13,
31        deprecated(note = "Deprecated since Python 3.13. Use `sys.executable` instead.")
32    )]
33    pub fn Py_GetProgramName() -> *mut wchar_t;
34
35    #[cfg_attr(
36        Py_3_11,
37        deprecated(note = "Deprecated since Python 3.11. Use `PyConfig.home` instead.")
38    )]
39    pub fn Py_SetPythonHome(arg1: *const wchar_t);
40    #[cfg_attr(
41        Py_3_13,
42        deprecated(
43            note = "Deprecated since Python 3.13. Use `PyConfig.home` or the value of the `PYTHONHOME` environment variable instead."
44        )
45    )]
46    pub fn Py_GetPythonHome() -> *mut wchar_t;
47    #[cfg_attr(
48        Py_3_13,
49        deprecated(note = "Deprecated since Python 3.13. Use `sys.executable` instead.")
50    )]
51    pub fn Py_GetProgramFullPath() -> *mut wchar_t;
52    #[cfg_attr(
53        Py_3_13,
54        deprecated(note = "Deprecated since Python 3.13. Use `sys.prefix` instead.")
55    )]
56    pub fn Py_GetPrefix() -> *mut wchar_t;
57    #[cfg_attr(
58        Py_3_13,
59        deprecated(note = "Deprecated since Python 3.13. Use `sys.exec_prefix` instead.")
60    )]
61    pub fn Py_GetExecPrefix() -> *mut wchar_t;
62    #[cfg_attr(
63        Py_3_13,
64        deprecated(note = "Deprecated since Python 3.13. Use `sys.path` instead.")
65    )]
66    pub fn Py_GetPath() -> *mut wchar_t;
67    #[cfg(not(Py_3_13))]
68    #[cfg_attr(
69        Py_3_11,
70        deprecated(note = "Deprecated since Python 3.11. Use `sys.path` instead.")
71    )]
72    pub fn Py_SetPath(arg1: *const wchar_t);
73
74    // skipped _Py_CheckPython3
75
76    pub fn Py_GetVersion() -> *const c_char;
77    pub fn Py_GetPlatform() -> *const c_char;
78    pub fn Py_GetCopyright() -> *const c_char;
79    pub fn Py_GetCompiler() -> *const c_char;
80    pub fn Py_GetBuildInfo() -> *const c_char;
81}
82
83type PyOS_sighandler_t = unsafe extern "C" fn(arg1: c_int);
84
85extern_libpython! {
86    pub fn PyOS_getsig(arg1: c_int) -> PyOS_sighandler_t;
87    pub fn PyOS_setsig(arg1: c_int, arg2: PyOS_sighandler_t) -> PyOS_sighandler_t;
88
89    #[cfg(Py_3_11)]
90    pub static Py_Version: std::ffi::c_ulong;
91
92    #[cfg(Py_3_13)]
93    pub fn Py_IsFinalizing() -> c_int;
94}