python3_sys/
pythonrun.rs

1use core::ptr;
2#[allow(unused_imports)]
3use libc::{c_char, c_int, c_ulong, wchar_t, FILE};
4
5use crate::object::*;
6#[cfg(not(Py_LIMITED_API))]
7#[cfg(not(Py_3_10))]
8use crate::pyarena::PyArena;
9use crate::pystate::PyThreadState;
10
11#[cfg_attr(windows, link(name = "pythonXY"))]
12extern "C" {
13    // TODO: these moved to pylifecycle.h
14    #[cfg(Py_3_4)]
15    pub fn Py_SetStandardStreamEncoding(encoding: *const c_char, errors: *const c_char) -> c_int;
16    pub fn Py_SetProgramName(arg1: *const wchar_t) -> ();
17    pub fn Py_GetProgramName() -> *mut wchar_t;
18    pub fn Py_SetPythonHome(arg1: *const wchar_t) -> ();
19    pub fn Py_GetPythonHome() -> *mut wchar_t;
20    pub fn Py_Initialize() -> ();
21    pub fn Py_InitializeEx(arg1: c_int) -> ();
22    pub fn Py_Finalize() -> ();
23    #[cfg(Py_3_6)]
24    pub fn Py_FinalizeEx() -> c_int;
25    pub fn Py_IsInitialized() -> c_int;
26    pub fn Py_NewInterpreter() -> *mut PyThreadState;
27    pub fn Py_EndInterpreter(arg1: *mut PyThreadState) -> ();
28}
29
30// Note: PyCompilerFlags was moved to compile.h in Python 3.7;
31// We still have our version in pythonrun.rs
32#[repr(C)]
33#[derive(Copy, Clone)]
34#[cfg(not(Py_LIMITED_API))]
35pub struct PyCompilerFlags {
36    pub cf_flags: c_int,
37    #[cfg(Py_3_8)]
38    pub cf_feature_version: c_int,
39}
40
41#[cfg(all(not(Py_LIMITED_API), not(Py_3_10)))]
42#[repr(C)]
43pub struct _mod {
44    _private: [u8; 0],
45}
46
47#[cfg(not(Py_LIMITED_API))]
48#[cfg_attr(windows, link(name = "pythonXY"))]
49extern "C" {
50    pub fn PyRun_SimpleStringFlags(arg1: *const c_char, arg2: *mut PyCompilerFlags) -> c_int;
51    pub fn PyRun_AnyFileFlags(
52        arg1: *mut FILE,
53        arg2: *const c_char,
54        arg3: *mut PyCompilerFlags,
55    ) -> c_int;
56    pub fn PyRun_AnyFileExFlags(
57        fp: *mut FILE,
58        filename: *const c_char,
59        closeit: c_int,
60        flags: *mut PyCompilerFlags,
61    ) -> c_int;
62    pub fn PyRun_SimpleFileExFlags(
63        fp: *mut FILE,
64        filename: *const c_char,
65        closeit: c_int,
66        flags: *mut PyCompilerFlags,
67    ) -> c_int;
68    pub fn PyRun_InteractiveOneFlags(
69        fp: *mut FILE,
70        filename: *const c_char,
71        flags: *mut PyCompilerFlags,
72    ) -> c_int;
73    #[cfg(Py_3_4)]
74    pub fn PyRun_InteractiveOneObject(
75        fp: *mut FILE,
76        filename: *mut PyObject,
77        flags: *mut PyCompilerFlags,
78    ) -> c_int;
79    pub fn PyRun_InteractiveLoopFlags(
80        fp: *mut FILE,
81        filename: *const c_char,
82        flags: *mut PyCompilerFlags,
83    ) -> c_int;
84    #[cfg(not(Py_3_10))]
85    pub fn PyParser_ASTFromString(
86        s: *const c_char,
87        filename: *const c_char,
88        start: c_int,
89        flags: *mut PyCompilerFlags,
90        arena: *mut PyArena,
91    ) -> *mut _mod;
92    #[cfg(all(Py_3_4, not(Py_3_10)))]
93    pub fn PyParser_ASTFromStringObject(
94        s: *const c_char,
95        filename: *mut PyObject,
96        start: c_int,
97        flags: *mut PyCompilerFlags,
98        arena: *mut PyArena,
99    ) -> *mut _mod;
100    #[cfg(not(Py_3_10))]
101    pub fn PyParser_ASTFromFile(
102        fp: *mut FILE,
103        filename: *const c_char,
104        enc: *const c_char,
105        start: c_int,
106        ps1: *const c_char,
107        ps2: *const c_char,
108        flags: *mut PyCompilerFlags,
109        errcode: *mut c_int,
110        arena: *mut PyArena,
111    ) -> *mut _mod;
112    #[cfg(all(Py_3_4, not(Py_3_10)))]
113    pub fn PyParser_ASTFromFileObject(
114        fp: *mut FILE,
115        filename: *mut PyObject,
116        enc: *const c_char,
117        start: c_int,
118        ps1: *const c_char,
119        ps2: *const c_char,
120        flags: *mut PyCompilerFlags,
121        errcode: *mut c_int,
122        arena: *mut PyArena,
123    ) -> *mut _mod;
124}
125
126#[repr(C)]
127#[cfg(not(Py_3_10))]
128pub struct symtable {
129    _private: [u8; 0],
130}
131
132#[repr(C)]
133#[cfg(not(Py_3_10))]
134pub struct _node {
135    _private: [u8; 0],
136}
137
138#[inline]
139#[cfg(not(Py_3_10))]
140#[deprecated(since = "0.5.2", note = "Deprecated since Python 3.9")]
141pub unsafe fn PyParser_SimpleParseString(s: *const c_char, b: c_int) -> *mut _node {
142    #[allow(deprecated)]
143    PyParser_SimpleParseStringFlags(s, b, 0)
144}
145
146#[cfg(not(Py_LIMITED_API))]
147#[cfg(not(Py_3_10))]
148#[inline]
149#[deprecated(since = "0.5.2", note = "Deprecated since Python 3.9")]
150pub unsafe fn PyParser_SimpleParseFile(fp: *mut FILE, s: *const c_char, b: c_int) -> *mut _node {
151    #[allow(deprecated)]
152    PyParser_SimpleParseFileFlags(fp, s, b, 0)
153}
154
155#[cfg_attr(windows, link(name = "pythonXY"))]
156extern "C" {
157    #[deprecated(since = "0.5.2", note = "Deprecated since Python 3.9")]
158    #[cfg(not(Py_3_10))]
159    pub fn PyParser_SimpleParseStringFlags(
160        arg1: *const c_char,
161        arg2: c_int,
162        arg3: c_int,
163    ) -> *mut _node;
164    #[deprecated(since = "0.5.2", note = "Deprecated since Python 3.9")]
165    #[cfg(not(Py_3_10))]
166    pub fn PyParser_SimpleParseStringFlagsFilename(
167        arg1: *const c_char,
168        arg2: *const c_char,
169        arg3: c_int,
170        arg4: c_int,
171    ) -> *mut _node;
172    #[cfg(not(Py_LIMITED_API))]
173    #[deprecated(since = "0.5.2", note = "Deprecated since Python 3.9")]
174    #[cfg(not(Py_3_10))]
175    pub fn PyParser_SimpleParseFileFlags(
176        arg1: *mut FILE,
177        arg2: *const c_char,
178        arg3: c_int,
179        arg4: c_int,
180    ) -> *mut _node;
181    #[cfg(not(Py_LIMITED_API))]
182    pub fn PyRun_StringFlags(
183        arg1: *const c_char,
184        arg2: c_int,
185        arg3: *mut PyObject,
186        arg4: *mut PyObject,
187        arg5: *mut PyCompilerFlags,
188    ) -> *mut PyObject;
189    #[cfg(not(Py_LIMITED_API))]
190    pub fn PyRun_FileExFlags(
191        fp: *mut FILE,
192        filename: *const c_char,
193        start: c_int,
194        globals: *mut PyObject,
195        locals: *mut PyObject,
196        closeit: c_int,
197        flags: *mut PyCompilerFlags,
198    ) -> *mut PyObject;
199    #[cfg(Py_LIMITED_API)]
200    pub fn Py_CompileString(string: *const c_char, p: *const c_char, s: c_int) -> *mut PyObject;
201}
202#[cfg(not(Py_LIMITED_API))]
203#[inline]
204pub unsafe fn Py_CompileString(string: *const c_char, p: *const c_char, s: c_int) -> *mut PyObject {
205    Py_CompileStringExFlags(string, p, s, ptr::null_mut(), -1)
206}
207#[cfg(not(Py_LIMITED_API))]
208#[inline]
209pub unsafe fn Py_CompileStringFlags(
210    string: *const c_char,
211    p: *const c_char,
212    s: c_int,
213    f: *mut PyCompilerFlags,
214) -> *mut PyObject {
215    Py_CompileStringExFlags(string, p, s, f, -1)
216}
217#[cfg_attr(windows, link(name = "pythonXY"))]
218extern "C" {
219    #[cfg(not(Py_LIMITED_API))]
220    pub fn Py_CompileStringExFlags(
221        str: *const c_char,
222        filename: *const c_char,
223        start: c_int,
224        flags: *mut PyCompilerFlags,
225        optimize: c_int,
226    ) -> *mut PyObject;
227    #[cfg(not(Py_LIMITED_API))]
228    #[cfg(Py_3_4)]
229    pub fn Py_CompileStringObject(
230        str: *const c_char,
231        filename: *mut PyObject,
232        start: c_int,
233        flags: *mut PyCompilerFlags,
234        optimize: c_int,
235    ) -> *mut PyObject;
236    #[cfg(not(Py_3_10))]
237    pub fn Py_SymtableString(
238        str: *const c_char,
239        filename: *const c_char,
240        start: c_int,
241    ) -> *mut symtable;
242    #[cfg(not(Py_LIMITED_API))]
243    #[cfg(Py_3_4)]
244    #[cfg(not(Py_3_10))]
245    pub fn Py_SymtableStringObject(
246        str: *const c_char,
247        filename: *mut PyObject,
248        start: c_int,
249    ) -> *mut symtable;
250
251    pub fn PyErr_Print() -> ();
252    pub fn PyErr_PrintEx(arg1: c_int) -> ();
253    pub fn PyErr_Display(arg1: *mut PyObject, arg2: *mut PyObject, arg3: *mut PyObject) -> ();
254
255    // TODO: these moved to pylifecycle.h
256    pub fn Py_AtExit(func: Option<extern "C" fn() -> ()>) -> c_int;
257    pub fn Py_Exit(arg1: c_int) -> ();
258    pub fn Py_Main(argc: c_int, argv: *mut *mut wchar_t) -> c_int;
259    #[cfg(Py_3_8)]
260    pub fn Py_BytesMain(argc: c_int, argv: *mut *mut c_char) -> c_int;
261    pub fn Py_GetProgramFullPath() -> *mut wchar_t;
262    pub fn Py_GetPrefix() -> *mut wchar_t;
263    pub fn Py_GetExecPrefix() -> *mut wchar_t;
264    pub fn Py_GetPath() -> *mut wchar_t;
265    pub fn Py_SetPath(arg1: *const wchar_t) -> ();
266    pub fn Py_GetVersion() -> *const c_char;
267    pub fn Py_GetPlatform() -> *const c_char;
268    pub fn Py_GetCopyright() -> *const c_char;
269    pub fn Py_GetCompiler() -> *const c_char;
270    pub fn Py_GetBuildInfo() -> *const c_char;
271    #[cfg(Py_3_11)]
272    pub static Py_Version: c_ulong;
273}