Skip to content

Commit

Permalink
c-api: reuse CallbackDataPtr
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Rockwood <rockwood@redpanda.com>
  • Loading branch information
rockwotj committed Nov 3, 2023
1 parent 630f8e3 commit f3dbed5
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions crates/c-api/src/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ use wasmtime::{
use crate::{
bad_utf8, handle_result, to_str, translate_args, wasm_config_t, wasm_functype_t, wasm_trap_t,
wasmtime_caller_t, wasmtime_error_t, wasmtime_instance_pre_t, wasmtime_linker_t,
wasmtime_module_t, wasmtime_val_t, wasmtime_val_union, CStoreContextMut, WASMTIME_I32,
wasmtime_module_t, wasmtime_val_t, wasmtime_val_union, CStoreContextMut, CallbackDataPtr,
WASMTIME_I32,
};

#[no_mangle]
Expand Down Expand Up @@ -89,14 +90,9 @@ impl Future for wasmtime_async_continuation_t {

pub type wasmtime_func_async_continuation_callback_t = extern "C" fn(*mut c_void) -> bool;

struct CallbackData {
env: *mut c_void,
}
unsafe impl Send for CallbackData {}

async fn invoke_c_async_callback<'a>(
cb: wasmtime_func_async_callback_t,
data: CallbackData,
data: CallbackDataPtr,
mut caller: Caller<'a, crate::StoreData>,
params: &'a [Val],
results: &'a mut [Val],
Expand Down Expand Up @@ -127,7 +123,7 @@ async fn invoke_c_async_callback<'a>(
finalizer: None,
};
cb(
data.env,
data.ptr,
&mut caller,
params.as_ptr(),
params.len(),
Expand Down Expand Up @@ -171,7 +167,7 @@ unsafe fn c_async_callback_to_rust_fn(
let foreign = crate::ForeignData { data, finalizer };
move |caller, params, results| {
let _ = &foreign; // move entire foreign into this closure
let data = CallbackData { env: foreign.data };
let data = CallbackDataPtr { ptr: foreign.data };
Box::new(invoke_c_async_callback(
callback, data, caller, params, results,
))
Expand Down

0 comments on commit f3dbed5

Please sign in to comment.