1use crate::pyport::Py_ssize_t;
4#[cfg(Py_3_9)]
5use libc::c_void;
6use libc::{c_char, c_int, c_ulong, wchar_t};
7
8#[repr(C)]
9#[derive(Copy, Clone)]
10pub enum PyStatusType {
11 _PyStatus_TYPE_OK = 0,
12 _PyStatus_TYPE_ERROR = 1,
13 _PyStatus_TYPE_EXIT = 2,
14}
15
16#[repr(C)]
17#[derive(Copy, Clone)]
18pub struct PyStatus {
19 pub _type: PyStatusType,
20 pub func: *const c_char,
21 pub err_msg: *const c_char,
22 pub exitcode: c_int,
23}
24
25impl Default for PyStatus {
26 fn default() -> Self {
27 let mut status: Self = unsafe { core::mem::zeroed() };
32 status._type = PyStatusType::_PyStatus_TYPE_OK;
33
34 status
35 }
36}
37
38#[cfg_attr(windows, link(name = "pythonXY"))]
39extern "C" {
40 pub fn PyStatus_Ok() -> PyStatus;
41 pub fn PyStatus_Error(err_msg: *const c_char) -> PyStatus;
42 pub fn PyStatus_NoMemory() -> PyStatus;
43 pub fn PyStatus_Exit(exitcode: c_int) -> PyStatus;
44
45 pub fn PyStatus_IsError(err: PyStatus) -> c_int;
46 pub fn PyStatus_IsExit(err: PyStatus) -> c_int;
47 pub fn PyStatus_Exception(err: PyStatus) -> c_int;
48}
49
50#[repr(C)]
51#[derive(Copy, Clone)]
52pub struct PyWideStringList {
53 pub length: Py_ssize_t,
54 pub items: *mut *mut wchar_t,
55}
56
57#[cfg_attr(windows, link(name = "pythonXY"))]
58extern "C" {
59 pub fn PyWideStringList_Append(list: *mut PyWideStringList, item: *const wchar_t) -> PyStatus;
60 pub fn PyWideStringList_Insert(
61 list: *mut PyWideStringList,
62 index: Py_ssize_t,
63 item: *const wchar_t,
64 ) -> PyStatus;
65}
66
67#[repr(C)]
68#[derive(Clone)]
69pub struct PyPreConfig {
70 pub _config_init: c_int,
71 pub parse_argv: c_int,
72 pub isolated: c_int,
73 pub use_environment: c_int,
74 pub configure_locale: c_int,
75 pub coerce_c_locale: c_int,
76 pub coerce_c_locale_warn: c_int,
77 #[cfg(windows)]
78 pub legacy_windows_fs_encoding: c_int,
79 pub utf8_mode: c_int,
80 pub dev_mode: c_int,
81 pub allocator: c_int,
82}
83
84impl Default for PyPreConfig {
85 fn default() -> Self {
86 unsafe { core::mem::zeroed() }
87 }
88}
89
90#[cfg_attr(windows, link(name = "pythonXY"))]
91extern "C" {
92 pub fn PyPreConfig_InitPythonConfig(config: *mut PyPreConfig) -> ();
93 pub fn PyPreConfig_InitIsolatedConfig(config: *mut PyPreConfig) -> ();
94}
95
96#[repr(C)]
97#[derive(Clone)]
98pub struct PyConfig {
99 pub _config_init: c_int,
100 pub isolated: c_int,
101 pub use_environment: c_int,
102 pub dev_mode: c_int,
103 pub install_signal_handlers: c_int,
104 pub use_hash_seed: c_int,
105 pub hash_seed: c_ulong,
106 pub faulthandler: c_int,
107 #[cfg(all(Py_3_9, not(Py_3_10)))]
108 pub _use_peg_parser: c_int,
109 pub tracemalloc: c_int,
110 #[cfg(Py_3_12)]
111 pub perf_profiling: c_int,
112 pub import_time: c_int,
113 #[cfg(Py_3_11)]
114 pub code_debug_ranges: c_int,
115 pub show_ref_count: c_int,
116 #[cfg(not(Py_3_9))]
117 pub show_alloc_count: c_int,
118 pub dump_refs: c_int,
119 #[cfg(Py_3_11)]
120 pub dump_refs_file: *mut wchar_t,
121 pub malloc_stats: c_int,
122 pub filesystem_encoding: *mut wchar_t,
123 pub filesystem_errors: *mut wchar_t,
124 pub pycache_prefix: *mut wchar_t,
125 pub parse_argv: c_int,
126 #[cfg(Py_3_10)]
127 pub orig_argv: PyWideStringList,
128 pub argv: PyWideStringList,
129 #[cfg(not(Py_3_10))]
130 pub program_name: *mut wchar_t,
131 pub xoptions: PyWideStringList,
132 pub warnoptions: PyWideStringList,
133 pub site_import: c_int,
134 pub bytes_warning: c_int,
135 #[cfg(Py_3_10)]
136 pub warn_default_encoding: c_int,
137 pub inspect: c_int,
138 pub interactive: c_int,
139 pub optimization_level: c_int,
140 pub parser_debug: c_int,
141 pub write_bytecode: c_int,
142 pub verbose: c_int,
143 pub quiet: c_int,
144 pub user_site_directory: c_int,
145 pub configure_c_stdio: c_int,
146 pub buffered_stdio: c_int,
147 pub stdio_encoding: *mut wchar_t,
148 pub stdio_errors: *mut wchar_t,
149 #[cfg(windows)]
150 pub legacy_windows_stdio: c_int,
151 pub check_hash_pycs_mode: *mut wchar_t,
152 #[cfg(Py_3_11)]
153 pub use_frozen_modules: c_int,
154 #[cfg(Py_3_11)]
155 pub safe_path: c_int,
156 #[cfg(Py_3_12)]
157 pub int_max_str_digits: c_int,
158 pub pathconfig_warnings: c_int,
160 #[cfg(Py_3_10)]
161 pub program_name: *mut wchar_t,
162 pub pythonpath_env: *mut wchar_t,
163 pub home: *mut wchar_t,
164 #[cfg(Py_3_10)]
165 pub platlibdir: *mut wchar_t,
166 pub module_search_paths_set: c_int,
168 pub module_search_paths: PyWideStringList,
169 #[cfg(Py_3_11)]
170 pub stdlib_dir: *mut wchar_t,
171 pub executable: *mut wchar_t,
172 pub base_executable: *mut wchar_t,
173 pub prefix: *mut wchar_t,
174 pub base_prefix: *mut wchar_t,
175 pub exec_prefix: *mut wchar_t,
176 pub base_exec_prefix: *mut wchar_t,
177 #[cfg(all(Py_3_9, not(Py_3_10)))]
178 pub platlibdir: *mut wchar_t,
179 pub skip_source_first_line: c_int,
181 pub run_command: *mut wchar_t,
182 pub run_module: *mut wchar_t,
183 pub run_filename: *mut wchar_t,
184 pub _install_importlib: c_int,
186 pub _init_main: c_int,
187 #[cfg(all(Py_3_9, not(Py_3_12)))]
188 pub _isolated_interpreter: c_int,
189 #[cfg(Py_3_11)]
190 pub _is_python_build: c_int,
191 #[cfg(all(Py_3_9, not(Py_3_10)))]
192 pub _orig_argv: PyWideStringList,
193}
194
195impl Default for PyConfig {
196 fn default() -> Self {
197 unsafe { core::mem::zeroed() }
198 }
199}
200
201#[cfg_attr(windows, link(name = "pythonXY"))]
202extern "C" {
203 pub fn PyConfig_InitPythonConfig(config: *mut PyConfig) -> ();
204 pub fn PyConfig_InitIsolatedConfig(config: *mut PyConfig) -> ();
205 pub fn PyConfig_Clear(config: *mut PyConfig) -> ();
206 pub fn PyConfig_SetString(
207 config: *mut PyConfig,
208 config_str: *mut *mut wchar_t,
209 value: *const wchar_t,
210 ) -> PyStatus;
211 pub fn PyConfig_SetBytesString(
212 config: *mut PyConfig,
213 config_str: *mut *mut wchar_t,
214 value: *const c_char,
215 ) -> PyStatus;
216 pub fn PyConfig_Read(config: *mut PyConfig) -> PyStatus;
217 pub fn PyConfig_SetBytesArgv(
218 config: *mut PyConfig,
219 argc: Py_ssize_t,
220 argv: *const *mut c_char,
221 ) -> PyStatus;
222 pub fn PyConfig_SetArgv(
223 config: *mut PyConfig,
224 argc: Py_ssize_t,
225 argv: *const *mut wchar_t,
226 ) -> PyStatus;
227 pub fn PyConfig_SetWideStringList(
228 config: *mut PyConfig,
229 list: *mut PyWideStringList,
230 length: Py_ssize_t,
231 items: *mut *mut wchar_t,
232 ) -> PyStatus;
233
234 #[cfg(Py_3_9)]
235 pub fn Py_GetArgcArgv(argc: *mut c_int, argv: *mut *mut *mut wchar_t) -> c_void;
236}