|
| 1 | +// This entire module is Python 3.8+ and !Py_LIMITED_API only. |
| 2 | + |
| 3 | +use crate::pyport::Py_ssize_t; |
| 4 | +use libc::{c_char, c_int, c_ulong, wchar_t}; |
| 5 | + |
| 6 | +#[repr(C)] |
| 7 | +#[derive(Copy, Clone)] |
| 8 | +pub enum PyStatusType { |
| 9 | + _PyStatus_TYPE_OK = 0, |
| 10 | + _PyStatus_TYPE_ERROR = 1, |
| 11 | + _PyStatus_TYPE_EXIT = 2, |
| 12 | +} |
| 13 | + |
| 14 | +#[repr(C)] |
| 15 | +#[derive(Copy, Clone)] |
| 16 | +pub struct PyStatus { |
| 17 | + _type: PyStatusType, |
| 18 | + func: *const c_char, |
| 19 | + err_msg: *const c_char, |
| 20 | + exitcode: c_int, |
| 21 | +} |
| 22 | + |
| 23 | +#[cfg_attr(windows, link(name = "pythonXY"))] |
| 24 | +extern "C" { |
| 25 | + pub fn PyStatus_Ok() -> PyStatus; |
| 26 | + pub fn PyStatus_Error(err_msg: *const c_char) -> PyStatus; |
| 27 | + pub fn PyStatus_NoMemory() -> PyStatus; |
| 28 | + pub fn PyStatus_Exit(exitcode: c_int) -> PyStatus; |
| 29 | + |
| 30 | + pub fn PyStatus_IsError(err: PyStatus) -> c_int; |
| 31 | + pub fn PyStatus_IsExit(err: PyStatus) -> c_int; |
| 32 | + pub fn PyStatus_Exception(err: PyStatus) -> c_int; |
| 33 | +} |
| 34 | + |
| 35 | +#[repr(C)] |
| 36 | +#[derive(Copy, Clone)] |
| 37 | +pub struct PyWideStringList { |
| 38 | + length: Py_ssize_t, |
| 39 | + items: *mut *mut wchar_t, |
| 40 | +} |
| 41 | + |
| 42 | +#[cfg_attr(windows, link(name = "pythonXY"))] |
| 43 | +extern "C" { |
| 44 | + pub fn PyWideStringList_Append(list: *mut PyWideStringList, item: *const wchar_t) -> PyStatus; |
| 45 | + pub fn PyWideStringList_Insert( |
| 46 | + list: *mut PyWideStringList, |
| 47 | + index: Py_ssize_t, |
| 48 | + item: *const wchar_t, |
| 49 | + ) -> PyStatus; |
| 50 | +} |
| 51 | + |
| 52 | +#[repr(C)] |
| 53 | +#[derive(Clone)] |
| 54 | +pub struct PyPreConfig { |
| 55 | + _config_init: c_int, |
| 56 | + parse_argv: c_int, |
| 57 | + isolated: c_int, |
| 58 | + use_environment: c_int, |
| 59 | + configure_locale: c_int, |
| 60 | + coerce_c_locale: c_int, |
| 61 | + coerce_c_locale_warn: c_int, |
| 62 | + #[cfg(windows)] |
| 63 | + legacy_windows_fs_encoding: c_int, |
| 64 | + utf8_mode: c_int, |
| 65 | + dev_mode: c_int, |
| 66 | + allocator: c_int, |
| 67 | +} |
| 68 | + |
| 69 | +#[cfg_attr(windows, link(name = "pythonXY"))] |
| 70 | +extern "C" { |
| 71 | + pub fn PyPreConfig_InitPythonConfig(config: *mut PyPreConfig) -> (); |
| 72 | + pub fn PyPreConfig_InitIsolatedConfig(config: *mut PyPreConfig) -> (); |
| 73 | +} |
| 74 | + |
| 75 | +#[repr(C)] |
| 76 | +#[derive(Clone)] |
| 77 | +pub struct PyConfig { |
| 78 | + _config_init: c_int, |
| 79 | + isolated: c_int, |
| 80 | + use_environment: c_int, |
| 81 | + dev_mode: c_int, |
| 82 | + install_signal_handlers: c_int, |
| 83 | + use_hash_seed: c_int, |
| 84 | + hash_seed: c_ulong, |
| 85 | + faulthandler: c_int, |
| 86 | + tracemalloc: c_int, |
| 87 | + import_time: c_int, |
| 88 | + show_ref_count: c_int, |
| 89 | + show_alloc_count: c_int, |
| 90 | + dump_refs: c_int, |
| 91 | + malloc_stats: c_int, |
| 92 | + filesystem_encoding: *mut wchar_t, |
| 93 | + filesystem_errors: *mut wchar_t, |
| 94 | + pycache_prefix: *mut wchar_t, |
| 95 | + parse_argv: c_int, |
| 96 | + argv: PyWideStringList, |
| 97 | + program_name: *mut wchar_t, |
| 98 | + xoptions: PyWideStringList, |
| 99 | + warnoptions: PyWideStringList, |
| 100 | + site_import: c_int, |
| 101 | + bytes_warning: c_int, |
| 102 | + inspect: c_int, |
| 103 | + interactive: c_int, |
| 104 | + optimization_level: c_int, |
| 105 | + parser_debug: c_int, |
| 106 | + write_bytecode: c_int, |
| 107 | + verbose: c_int, |
| 108 | + quiet: c_int, |
| 109 | + user_site_directory: c_int, |
| 110 | + configure_c_stdio: c_int, |
| 111 | + buffered_stdio: c_int, |
| 112 | + stdio_encoding: *mut wchar_t, |
| 113 | + stdio_errors: *mut wchar_t, |
| 114 | + #[cfg(windows)] |
| 115 | + legacy_windows_stdio: c_int, |
| 116 | + check_hash_pycs_mode: *mut wchar_t, |
| 117 | + pathconfig_warnings: c_int, |
| 118 | + pythonpath_env: *mut wchar_t, |
| 119 | + home: *mut wchar_t, |
| 120 | + module_search_paths_set: c_int, |
| 121 | + module_search_paths: PyWideStringList, |
| 122 | + executable: *mut wchar_t, |
| 123 | + base_executable: *mut wchar_t, |
| 124 | + prefix: *mut wchar_t, |
| 125 | + base_prefix: *mut wchar_t, |
| 126 | + exec_prefix: *mut wchar_t, |
| 127 | + base_exec_prefix: *mut wchar_t, |
| 128 | + skip_source_first_line: c_int, |
| 129 | + run_command: *mut wchar_t, |
| 130 | + run_module: *mut wchar_t, |
| 131 | + run_filename: *mut wchar_t, |
| 132 | + _install_importlib: c_int, |
| 133 | + _init_main: c_int, |
| 134 | +} |
| 135 | + |
| 136 | +#[cfg_attr(windows, link(name = "pythonXY"))] |
| 137 | +extern "C" { |
| 138 | + pub fn PyConfig_InitPythonConfig(config: *mut PyConfig) -> (); |
| 139 | + pub fn PyConfig_InitIsolatedConfig(config: *mut PyConfig) -> (); |
| 140 | + pub fn PyConfig_Clear(config: *mut PyConfig) -> (); |
| 141 | + pub fn PyConfig_SetString( |
| 142 | + config: *mut PyConfig, |
| 143 | + config_str: *mut *mut wchar_t, |
| 144 | + value: *const wchar_t, |
| 145 | + ) -> PyStatus; |
| 146 | + pub fn PyConfig_SetBytesString( |
| 147 | + config: *mut PyConfig, |
| 148 | + config_str: *mut *mut wchar_t, |
| 149 | + value: *const c_char, |
| 150 | + ) -> PyStatus; |
| 151 | + pub fn PyConfig_Read(config: *mut PyConfig) -> PyStatus; |
| 152 | + pub fn PyConfig_SetBytesArgv( |
| 153 | + config: *mut PyConfig, |
| 154 | + argc: Py_ssize_t, |
| 155 | + argv: *const *mut c_char, |
| 156 | + ) -> PyStatus; |
| 157 | + pub fn PyConfig_SetArgv( |
| 158 | + config: *mut PyConfig, |
| 159 | + argc: Py_ssize_t, |
| 160 | + argv: *const *mut wchar_t, |
| 161 | + ) -> PyStatus; |
| 162 | + pub fn PyConfig_SetWideStringList( |
| 163 | + config: *mut PyConfig, |
| 164 | + list: *mut PyWideStringList, |
| 165 | + length: Py_ssize_t, |
| 166 | + items: *mut *mut wchar_t, |
| 167 | + ) -> PyStatus; |
| 168 | +} |
0 commit comments