Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Refactor function.rs to handle empty input and returns #116

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading