From 518e233874b5432b5a9171f18cb25ee81c678c78 Mon Sep 17 00:00:00 2001 From: csh <458761603@qq.com> Date: Mon, 22 Jul 2024 16:23:02 +0800 Subject: [PATCH] [Fix] Refactor function.rs to handle empty input and returns Signed-off-by: csh <458761603@qq.com> --- crates/wasmedge-sys/src/async/function.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/crates/wasmedge-sys/src/async/function.rs b/crates/wasmedge-sys/src/async/function.rs index 64dd801d4..00e28fb1e 100644 --- a/crates/wasmedge-sys/src/async/function.rs +++ b/crates/wasmedge-sys/src/async/function.rs @@ -37,14 +37,21 @@ unsafe extern "C" fn wrap_async_fn( 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::>() }; // 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);