Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/crates/c-api/src/component/func.rs
3069 views
1
use super::wasmtime_component_val_t;
2
use crate::{WasmtimeStoreContextMut, wasmtime_component_func_type_t, wasmtime_error_t};
3
use wasmtime::component::{Func, Val};
4
5
#[unsafe(no_mangle)]
6
pub unsafe extern "C" fn wasmtime_component_func_call(
7
func: &Func,
8
mut context: WasmtimeStoreContextMut<'_>,
9
args: *const wasmtime_component_val_t,
10
args_len: usize,
11
results: *mut wasmtime_component_val_t,
12
results_len: usize,
13
) -> Option<Box<wasmtime_error_t>> {
14
let c_args = unsafe { crate::slice_from_raw_parts(args, args_len) };
15
let c_results = unsafe { crate::slice_from_raw_parts_mut(results, results_len) };
16
17
let args = c_args.iter().map(Val::from).collect::<Vec<_>>();
18
let mut results = vec![Val::Bool(false); results_len];
19
20
let result = func.call(&mut context, &args, &mut results);
21
22
crate::handle_result(result, |_| {
23
for (c_val, rust_val) in std::iter::zip(c_results, results) {
24
*c_val = wasmtime_component_val_t::from(&rust_val);
25
}
26
})
27
}
28
29
#[deprecated(note = "no longer has any effect")]
30
#[unsafe(no_mangle)]
31
pub unsafe extern "C" fn wasmtime_component_func_post_return(
32
_func: &Func,
33
_context: WasmtimeStoreContextMut<'_>,
34
) -> Option<Box<wasmtime_error_t>> {
35
None
36
}
37
38
#[unsafe(no_mangle)]
39
pub extern "C" fn wasmtime_component_func_type(
40
func: &Func,
41
context: WasmtimeStoreContextMut<'_>,
42
) -> Box<wasmtime_component_func_type_t> {
43
Box::new(func.ty(context).into())
44
}
45
46