1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8#[repr(i32)]
9pub enum ExecutionResult {
10 Success = 0,
12 DeserializationError = -1,
14 CellError = -2,
16 SerializationError = -3,
18 Panic = -4,
20}
21
22impl From<i32> for ExecutionResult {
23 fn from(code: i32) -> Self {
24 match code {
25 0 => Self::Success,
26 -1 => Self::DeserializationError,
27 -2 => Self::CellError,
28 -3 => Self::SerializationError,
29 -4 => Self::Panic,
30 _ => Self::CellError, }
32 }
33}
34
35pub type EntryFn0 = unsafe extern "C" fn(
46 *const u8, usize, *mut *mut u8, *mut usize,
48) -> i32;
49
50pub type EntryFn1 = unsafe extern "C" fn(
52 *const u8, usize, *const u8, usize, *mut *mut u8, *mut usize,
55) -> i32;
56
57pub type EntryFn2 = unsafe extern "C" fn(
59 *const u8, usize, *const u8, usize, *const u8, usize, *mut *mut u8, *mut usize,
63) -> i32;
64
65pub type EntryFn3 = unsafe extern "C" fn(
67 *const u8, usize, *const u8, usize, *const u8, usize, *const u8, usize, *mut *mut u8, *mut usize,
72) -> i32;
73
74pub type EntryFn4 = unsafe extern "C" fn(
76 *const u8, usize, *const u8, usize, *const u8, usize, *const u8, usize, *const u8, usize, *mut *mut u8, *mut usize,
82) -> i32;
83
84pub type EntryFn5 = unsafe extern "C" fn(
86 *const u8, usize, *const u8, usize, *const u8, usize, *const u8, usize, *const u8, usize, *const u8, usize, *mut *mut u8, *mut usize,
93) -> i32;
94
95pub type EntryFn6 = unsafe extern "C" fn(
97 *const u8, usize, *const u8, usize, *const u8, usize, *const u8, usize, *const u8, usize, *const u8, usize, *const u8, usize, *mut *mut u8, *mut usize,
105) -> i32;
106
107pub type EntryFn7 = unsafe extern "C" fn(
109 *const u8, usize, *const u8, usize, *const u8, usize, *const u8, usize, *const u8, usize, *const u8, usize, *const u8, usize, *const u8, usize, *mut *mut u8, *mut usize,
118) -> i32;
119
120pub type EntryFn8 = unsafe extern "C" fn(
122 *const u8, usize, *const u8, usize, *const u8, usize, *const u8, usize, *const u8, usize, *const u8, usize, *const u8, usize, *const u8, usize, *const u8, usize, *mut *mut u8, *mut usize,
132) -> i32;
133
134macro_rules! call_cell_n_deps {
151 ($executor:expr, $loaded:expr, $symbol_name:expr, $inputs:expr, $widget_values:expr, $fn_type:ty, $($idx:tt),*) => {{
152 use libloading::Symbol;
153 use $crate::error::Error;
154
155 let func: Symbol<$fn_type> = unsafe {
156 $loaded.library.get($symbol_name.as_bytes())
157 }.map_err(|e| {
158 Error::Execution(format!("Failed to get symbol {}: {}", $symbol_name, e))
159 })?;
160
161 let mut out_ptr: *mut u8 = std::ptr::null_mut();
162 let mut out_len: usize = 0;
163
164 $( let _input_bytes = $inputs[$idx].bytes(); )*
166 let inputs_array = [$( $inputs[$idx].bytes() ),*];
167
168 let result_code = unsafe {
170 func(
171 $( inputs_array[$idx].as_ptr(), inputs_array[$idx].len(), )*
172 $widget_values.as_ptr(), $widget_values.len(),
173 &mut out_ptr,
174 &mut out_len,
175 )
176 };
177
178 $executor.process_ffi_result(result_code, out_ptr, out_len, &$loaded.compiled.name)
179 }};
180}
181
182pub(crate) use call_cell_n_deps;
183
184#[cfg(test)]
185mod tests {
186 use super::*;
187
188 #[test]
189 fn test_execution_result_from_i32() {
190 assert_eq!(ExecutionResult::from(0), ExecutionResult::Success);
191 assert_eq!(
192 ExecutionResult::from(-1),
193 ExecutionResult::DeserializationError
194 );
195 assert_eq!(ExecutionResult::from(-2), ExecutionResult::CellError);
196 assert_eq!(
197 ExecutionResult::from(-3),
198 ExecutionResult::SerializationError
199 );
200 assert_eq!(ExecutionResult::from(-4), ExecutionResult::Panic);
201 assert_eq!(ExecutionResult::from(-99), ExecutionResult::CellError);
202 }
203}