`funcref`s are implemented as `NonNull<VMCallerCheckedAnyfunc>`. This should be more efficient than using a `VMExternRef` that points at a `VMCallerCheckedAnyfunc` because it gets rid of an indirection, dynamic allocation, and some reference counting. Note that the null function reference is *NOT* a null pointer; it is a `VMCallerCheckedAnyfunc` that has a null `func_ptr` member. Part of #929
22 lines
620 B
Rust
22 lines
620 B
Rust
use anyhow::Result;
|
|
use wasmtime::*;
|
|
|
|
#[test]
|
|
fn use_func_after_drop() -> Result<()> {
|
|
let table;
|
|
{
|
|
let store = Store::default();
|
|
let closed_over_data = String::from("abcd");
|
|
let func = Func::wrap(&store, move || {
|
|
assert_eq!(closed_over_data, "abcd");
|
|
});
|
|
let ty = TableType::new(ValType::FuncRef, Limits::new(1, None));
|
|
table = Table::new(&store, ty, Val::FuncRef(None))?;
|
|
table.set(0, func.into())?;
|
|
}
|
|
let func = table.get(0).unwrap().funcref().unwrap().unwrap().clone();
|
|
let func = func.get0::<()>()?;
|
|
func()?;
|
|
Ok(())
|
|
}
|