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

wasm: fix host function arg translation #18225

Merged
merged 2 commits into from
May 3, 2024
Merged
Changes from 1 commit
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
42 changes: 25 additions & 17 deletions src/v/wasm/wasmtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1090,23 +1090,31 @@ struct host_function<module_func> {
memory* mem,
std::span<const wasmtime_val_t> args,
std::span<wasmtime_val_t> results) {
auto raw = to_raw_values(args);
auto host_params = ffi::extract_parameters<ArgTypes...>(mem, raw, 0);
using FutureType = typename ReturnType::value_type;
if constexpr (std::is_void_v<FutureType>) {
return ss::futurize_apply(
module_func,
std::tuple_cat(
std::make_tuple(host_module), std::move(host_params)));
} else {
return ss::futurize_apply(
module_func,
std::tuple_cat(
std::make_tuple(host_module), std::move(host_params)))
.then([results](FutureType host_future_result) {
results[0] = convert_to_wasmtime<FutureType>(
host_future_result);
});
try {
auto raw = to_raw_values(args);
auto host_params = ffi::extract_parameters<ArgTypes...>(
mem, raw, 0);
using FutureType = typename ReturnType::value_type;
if constexpr (std::is_void_v<FutureType>) {
return std::apply(
module_func,
std::tuple_cat(
std::make_tuple(host_module), std::move(host_params)));
} else {
return std::apply(
module_func,
std::tuple_cat(
std::make_tuple(host_module),
std::move(host_params)))
.then([results](FutureType host_future_result) {
// This is safe to write too because wasmtime ensures the
// result is kept alive until the future completes.
results[0] = convert_to_wasmtime<FutureType>(
host_future_result);
});
}
} catch (...) {
return ss::current_exception_as_future();
rockwotj marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down