1b2c64de1SMangoPeachGrape use super::wasmtime_component_val_t;
239ec36caSAlex Crichton use crate::{WasmtimeStoreContextMut, wasmtime_component_func_type_t, wasmtime_error_t};
339ec36caSAlex Crichton use wasmtime::component::{Func, Val};
4b2c64de1SMangoPeachGrape 
5b2c64de1SMangoPeachGrape #[unsafe(no_mangle)]
wasmtime_component_func_call( func: &Func, mut context: WasmtimeStoreContextMut<'_>, args: *const wasmtime_component_val_t, args_len: usize, results: *mut wasmtime_component_val_t, results_len: usize, ) -> Option<Box<wasmtime_error_t>>6b2c64de1SMangoPeachGrape pub unsafe extern "C" fn wasmtime_component_func_call(
7b2c64de1SMangoPeachGrape     func: &Func,
8b2c64de1SMangoPeachGrape     mut context: WasmtimeStoreContextMut<'_>,
9b2c64de1SMangoPeachGrape     args: *const wasmtime_component_val_t,
10b2c64de1SMangoPeachGrape     args_len: usize,
11b2c64de1SMangoPeachGrape     results: *mut wasmtime_component_val_t,
12b2c64de1SMangoPeachGrape     results_len: usize,
13b2c64de1SMangoPeachGrape ) -> Option<Box<wasmtime_error_t>> {
14dbc21cdeSAlex Crichton     let c_args = unsafe { crate::slice_from_raw_parts(args, args_len) };
15dbc21cdeSAlex Crichton     let c_results = unsafe { crate::slice_from_raw_parts_mut(results, results_len) };
16b2c64de1SMangoPeachGrape 
17b2c64de1SMangoPeachGrape     let args = c_args.iter().map(Val::from).collect::<Vec<_>>();
18b2c64de1SMangoPeachGrape     let mut results = vec![Val::Bool(false); results_len];
19b2c64de1SMangoPeachGrape 
2053701b21SMangoPeachGrape     let result = func.call(&mut context, &args, &mut results);
21b2c64de1SMangoPeachGrape 
22b2c64de1SMangoPeachGrape     crate::handle_result(result, |_| {
23b2c64de1SMangoPeachGrape         for (c_val, rust_val) in std::iter::zip(c_results, results) {
24b2c64de1SMangoPeachGrape             *c_val = wasmtime_component_val_t::from(&rust_val);
25b2c64de1SMangoPeachGrape         }
26b2c64de1SMangoPeachGrape     })
27b2c64de1SMangoPeachGrape }
2853701b21SMangoPeachGrape 
29*c09aa380SJoel Dice #[deprecated(note = "no longer has any effect")]
3053701b21SMangoPeachGrape #[unsafe(no_mangle)]
wasmtime_component_func_post_return( _func: &Func, _context: WasmtimeStoreContextMut<'_>, ) -> Option<Box<wasmtime_error_t>>3153701b21SMangoPeachGrape pub unsafe extern "C" fn wasmtime_component_func_post_return(
32*c09aa380SJoel Dice     _func: &Func,
33*c09aa380SJoel Dice     _context: WasmtimeStoreContextMut<'_>,
3453701b21SMangoPeachGrape ) -> Option<Box<wasmtime_error_t>> {
35*c09aa380SJoel Dice     None
3653701b21SMangoPeachGrape }
3739ec36caSAlex Crichton 
3839ec36caSAlex Crichton #[unsafe(no_mangle)]
wasmtime_component_func_type( func: &Func, context: WasmtimeStoreContextMut<'_>, ) -> Box<wasmtime_component_func_type_t>3939ec36caSAlex Crichton pub extern "C" fn wasmtime_component_func_type(
4039ec36caSAlex Crichton     func: &Func,
4139ec36caSAlex Crichton     context: WasmtimeStoreContextMut<'_>,
4239ec36caSAlex Crichton ) -> Box<wasmtime_component_func_type_t> {
4339ec36caSAlex Crichton     Box::new(func.ty(context).into())
4439ec36caSAlex Crichton }
45