1#[cfg(all(Py_3_14, not(any(PyPy, GraalPy))))]
4use crate::PyObject;
5use crate::Py_ssize_t;
6use core::ffi::{c_char, c_int, c_ulong};
7use libc::wchar_t;
8
9#[repr(C)]
10#[derive(Copy, Clone, Debug, PartialEq, Eq)]
11pub enum _PyStatus_TYPE {
12 _PyStatus_TYPE_OK = 0,
13 _PyStatus_TYPE_ERROR = 1,
14 _PyStatus_TYPE_EXIT = 2,
15}
16
17#[repr(C)]
18#[derive(Copy, Clone)]
19pub struct PyStatus {
20 pub _type: _PyStatus_TYPE,
21 pub func: *const c_char,
22 pub err_msg: *const c_char,
23 pub exitcode: c_int,
24}
25
26extern_libpython! {
27 pub fn PyStatus_Ok() -> PyStatus;
28 pub fn PyStatus_Error(err_msg: *const c_char) -> PyStatus;
29 pub fn PyStatus_NoMemory() -> PyStatus;
30 pub fn PyStatus_Exit(exitcode: c_int) -> PyStatus;
31 pub fn PyStatus_IsError(err: PyStatus) -> c_int;
32 pub fn PyStatus_IsExit(err: PyStatus) -> c_int;
33 pub fn PyStatus_Exception(err: PyStatus) -> c_int;
34}
35
36#[repr(C)]
39#[derive(Copy, Clone)]
40pub struct PyWideStringList {
41 pub length: Py_ssize_t,
42 pub items: *mut *mut wchar_t,
43}
44
45extern_libpython! {
46 pub fn PyWideStringList_Append(list: *mut PyWideStringList, item: *const wchar_t) -> PyStatus;
47 pub fn PyWideStringList_Insert(
48 list: *mut PyWideStringList,
49 index: Py_ssize_t,
50 item: *const wchar_t,
51 ) -> PyStatus;
52}
53
54#[repr(C)]
57#[derive(Copy, Clone)]
58pub struct PyPreConfig {
59 pub _config_init: c_int,
60 pub parse_argv: c_int,
61 pub isolated: c_int,
62 pub use_environment: c_int,
63 pub configure_locale: c_int,
64 pub coerce_c_locale: c_int,
65 pub coerce_c_locale_warn: c_int,
66
67 #[cfg(windows)]
68 pub legacy_windows_fs_encoding: c_int,
69
70 pub utf8_mode: c_int,
71 pub dev_mode: c_int,
72 pub allocator: c_int,
73}
74
75extern_libpython! {
76 pub fn PyPreConfig_InitPythonConfig(config: *mut PyPreConfig);
77 pub fn PyPreConfig_InitIsolatedConfig(config: *mut PyPreConfig);
78}
79
80#[repr(C)]
83#[derive(Copy, Clone)]
84pub struct PyConfig {
85 pub _config_init: c_int,
86 pub isolated: c_int,
87 pub use_environment: c_int,
88 pub dev_mode: c_int,
89 pub install_signal_handlers: c_int,
90 pub use_hash_seed: c_int,
91 pub hash_seed: c_ulong,
92 pub faulthandler: c_int,
93 #[cfg(not(Py_3_10))]
94 pub _use_peg_parser: c_int,
95 pub tracemalloc: c_int,
96 #[cfg(Py_3_12)]
97 pub perf_profiling: c_int,
98 #[cfg(Py_3_14)]
99 pub remote_debug: c_int,
100 pub import_time: c_int,
101 #[cfg(Py_3_11)]
102 pub code_debug_ranges: c_int,
103 pub show_ref_count: c_int,
104 pub dump_refs: c_int,
105 #[cfg(Py_3_11)]
106 pub dump_refs_file: *mut wchar_t,
107 pub malloc_stats: c_int,
108 #[cfg(Py_3_15)]
109 pub pymalloc_hugepages: c_int,
110 pub filesystem_encoding: *mut wchar_t,
111 pub filesystem_errors: *mut wchar_t,
112 pub pycache_prefix: *mut wchar_t,
113 pub parse_argv: c_int,
114 #[cfg(Py_3_10)]
115 pub orig_argv: PyWideStringList,
116 pub argv: PyWideStringList,
117 #[cfg(not(Py_3_10))]
118 pub program_name: *mut wchar_t,
119 pub xoptions: PyWideStringList,
120 pub warnoptions: PyWideStringList,
121 pub site_import: c_int,
122 pub bytes_warning: c_int,
123 #[cfg(Py_3_10)]
124 pub warn_default_encoding: c_int,
125 pub inspect: c_int,
126 pub interactive: c_int,
127 pub optimization_level: c_int,
128 pub parser_debug: c_int,
129 pub write_bytecode: c_int,
130 pub verbose: c_int,
131 pub quiet: c_int,
132 pub user_site_directory: c_int,
133 pub configure_c_stdio: c_int,
134 pub buffered_stdio: c_int,
135 pub stdio_encoding: *mut wchar_t,
136 pub stdio_errors: *mut wchar_t,
137
138 #[cfg(windows)]
139 pub legacy_windows_stdio: c_int,
140
141 pub check_hash_pycs_mode: *mut wchar_t,
142 #[cfg(Py_3_11)]
143 pub use_frozen_modules: c_int,
144 #[cfg(Py_3_11)]
145 pub safe_path: c_int,
146 #[cfg(Py_3_12)]
147 pub int_max_str_digits: c_int,
148 #[cfg(Py_3_14)]
149 pub thread_inherit_context: c_int,
150 #[cfg(Py_3_14)]
151 pub context_aware_warnings: c_int,
152 #[cfg(all(Py_3_14, target_os = "macos"))]
153 pub use_system_logger: c_int,
154 #[cfg(Py_3_13)]
155 pub cpu_count: c_int,
156 #[cfg(Py_GIL_DISABLED)]
157 pub enable_gil: c_int,
158 #[cfg(all(Py_3_14, Py_GIL_DISABLED))]
159 pub tlbc_enabled: c_int,
160 #[cfg(Py_3_15)]
161 pub lazy_imports: c_int,
162 pub pathconfig_warnings: c_int,
163 #[cfg(Py_3_10)]
164 pub program_name: *mut wchar_t,
165 pub pythonpath_env: *mut wchar_t,
166 pub home: *mut wchar_t,
167 #[cfg(Py_3_10)]
168 pub platlibdir: *mut wchar_t,
169
170 pub module_search_paths_set: c_int,
171 pub module_search_paths: PyWideStringList,
172 #[cfg(Py_3_11)]
173 pub stdlib_dir: *mut wchar_t,
174 pub executable: *mut wchar_t,
175 pub base_executable: *mut wchar_t,
176 pub prefix: *mut wchar_t,
177 pub base_prefix: *mut wchar_t,
178 pub exec_prefix: *mut wchar_t,
179 pub base_exec_prefix: *mut wchar_t,
180 #[cfg(not(Py_3_10))]
181 pub platlibdir: *mut wchar_t,
182 pub skip_source_first_line: c_int,
183 pub run_command: *mut wchar_t,
184 pub run_module: *mut wchar_t,
185 pub run_filename: *mut wchar_t,
186 #[cfg(Py_3_13)]
187 pub sys_path_0: *mut wchar_t,
188 pub _install_importlib: c_int,
189 pub _init_main: c_int,
190 #[cfg(not(Py_3_12))]
191 pub _isolated_interpreter: c_int,
192 #[cfg(Py_3_11)]
193 pub _is_python_build: c_int,
194 #[cfg(not(Py_3_10))]
195 pub _orig_argv: PyWideStringList,
196 #[cfg(all(Py_3_13, py_sys_config = "Py_DEBUG"))]
197 pub run_presite: *mut wchar_t,
198}
199
200extern_libpython! {
201 pub fn PyConfig_InitPythonConfig(config: *mut PyConfig);
202 pub fn PyConfig_InitIsolatedConfig(config: *mut PyConfig);
203 pub fn PyConfig_Clear(config: *mut PyConfig);
204 pub fn PyConfig_SetString(
205 config: *mut PyConfig,
206 config_str: *mut *mut wchar_t,
207 str: *const wchar_t,
208 ) -> PyStatus;
209 pub fn PyConfig_SetBytesString(
210 config: *mut PyConfig,
211 config_str: *mut *mut wchar_t,
212 str: *const c_char,
213 ) -> PyStatus;
214 pub fn PyConfig_Read(config: *mut PyConfig) -> PyStatus;
215 pub fn PyConfig_SetBytesArgv(
216 config: *mut PyConfig,
217 argc: Py_ssize_t,
218 argv: *mut *const c_char,
219 ) -> PyStatus;
220 pub fn PyConfig_SetArgv(
221 config: *mut PyConfig,
222 argc: Py_ssize_t,
223 argv: *mut *const wchar_t,
224 ) -> PyStatus;
225 pub fn PyConfig_SetWideStringList(
226 config: *mut PyConfig,
227 list: *mut PyWideStringList,
228 length: Py_ssize_t,
229 items: *mut *mut wchar_t,
230 ) -> PyStatus;
231}
232
233extern_libpython! {
236 pub fn Py_GetArgcArgv(argc: *mut c_int, argv: *mut *mut *mut wchar_t);
237}
238
239#[cfg(all(Py_3_14, not(any(PyPy, GraalPy))))]
242opaque_struct!(pub PyInitConfig);
243
244#[cfg(all(Py_3_14, not(any(PyPy, GraalPy))))]
245extern_libpython! {
246 pub fn PyInitConfig_Create() -> *mut PyInitConfig;
247 pub fn PyInitConfig_Free(config: *mut PyInitConfig);
248
249 pub fn PyInitConfig_GetError(
250 config: *mut PyInitConfig,
251 err_message: *mut *const c_char,
252 ) -> c_int;
253 pub fn PyInitConfig_GetExitCode(config: *mut PyInitConfig, exitcode: *mut c_int) -> c_int;
254
255 pub fn PyInitConfig_HasOption(config: *mut PyInitConfig, name: *const c_char) -> c_int;
256 pub fn PyInitConfig_GetInt(
257 config: *mut PyInitConfig,
258 name: *const c_char,
259 value: *mut u64,
260 ) -> c_int;
261 pub fn PyInitConfig_GetStr(
262 config: *mut PyInitConfig,
263 name: *const c_char,
264 value: *mut *mut c_char,
265 ) -> c_int;
266 pub fn PyInitConfig_GetStrList(
267 config: *mut PyInitConfig,
268 name: *const c_char,
269 length: *mut usize,
270 items: *mut *mut *mut c_char,
271 ) -> c_int;
272 pub fn PyInitConfig_FreeStrList(length: usize, items: *mut *mut c_char);
273
274 pub fn PyInitConfig_SetInt(config: *mut PyInitConfig, name: *const c_char, value: u64)
275 -> c_int;
276 pub fn PyInitConfig_SetStr(
277 config: *mut PyInitConfig,
278 name: *const c_char,
279 value: *const c_char,
280 ) -> c_int;
281 pub fn PyInitConfig_SetStrList(
282 config: *mut PyInitConfig,
283 name: *const c_char,
284 length: usize,
285 items: *mut *const c_char,
286 ) -> c_int;
287
288 pub fn PyInitConfig_AddModule(
289 config: *mut PyInitConfig,
290 name: *const c_char,
291 initfunc: extern "C" fn() -> *mut PyObject,
292 ) -> c_int;
293
294 pub fn Py_InitializeFromInitConfig(config: *mut PyInitConfig) -> c_int;
295}