Add an assertion that a HostFunc's store agrees on engines
This commit adds an assertion which was previously forgotten when inserting a `HostFunc` into a `Store`. This can happen when a `Linker` is defined with one engine but it's used to interoperate with a store defined within a different engine. A function contains type information that's only valid relative to the engine that it was defined within. This means that if a function is used within a different engine then type information may look valid when in fact it is not. For example it's otherwise possible to insert a function into an engine with one type and call it in a different engine with a different type. Similar to how `Store` misuse is a panic throughout `wasmtime`'s API this commit also turns this behavior into panic, so there's no API impact. Documentation has been updated accordingly to indicate that various functions on `Linker` will panic if a `store` is provided that's connected to a different `Engine`.
This commit is contained in:
@@ -256,7 +256,7 @@ fn get_host_function() -> Result<()> {
|
||||
|
||||
let mut linker = Linker::new(&engine);
|
||||
linker.func_wrap("mod", "f1", || {})?;
|
||||
let mut store = Store::<()>::default();
|
||||
let mut store = Store::new(&engine, ());
|
||||
assert!(linker
|
||||
.get_by_import(&mut store, &module.imports().nth(0).unwrap())
|
||||
.is_some());
|
||||
|
||||
Reference in New Issue
Block a user