Skip to content

Commit

Permalink
Merge pull request #115 from second-state/0.13.x
Browse files Browse the repository at this point in the history
[Fix] Refactor function.rs to handle empty input and returns
  • Loading branch information
L-jasmine authored Jul 22, 2024
2 parents cbd9e3a + 518e233 commit 0cab09a
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 0cab09a

Please sign in to comment.