Skip to content

Commit

Permalink
[Fix] Refactor function.rs to handle empty input and returns
Browse files Browse the repository at this point in the history
Signed-off-by: csh <[email protected]>
  • Loading branch information
L-jasmine committed Jul 22, 2024
1 parent dd067a3 commit 255c00e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions crates/wasmedge-sys/src/async/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,21 @@ unsafe extern "C" fn wrap_async_fn<Data>(
let data = &mut *(data as *mut Data);

// arguments
let input = {
let input = if params.is_null() || param_len == 0 {
vec![]
} else {
let raw_input = unsafe { std::slice::from_raw_parts(params, param_len as usize) };
raw_input.iter().map(|r| (*r).into()).collect::<Vec<_>>()
};

// returns
let return_len = return_len as usize;
let raw_returns = unsafe { std::slice::from_raw_parts_mut(returns, return_len) };
let mut empty_return = [];
let raw_returns = if returns.is_null() || return_len == 0 {
&mut empty_return
} else {
unsafe { std::slice::from_raw_parts_mut(returns, return_len) }
};

// get and call host function
let real_fn: AsyncFn<'_, '_, '_, '_, Data> = std::mem::transmute(key_ptr);
Expand Down

0 comments on commit 255c00e

Please sign in to comment.