MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / function_interposition

Function function_interposition

tests/all/linker.rs:97–126  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

95#[test]
96#[cfg_attr(miri, ignore)]
97fn function_interposition() -> Result<()> {
98 let mut store = Store::<()>::default();
99 let mut linker = Linker::new(store.engine());
100 linker.allow_shadowing(true);
101 let mut module = Module::new(
102 store.engine(),
103 r#"(module (func (export "green") (result i32) (i32.const 7)))"#,
104 )?;
105 for _ in 0..4 {
106 let instance = linker.instantiate(&mut store, &module)?;
107 let green = instance.get_export(&mut store, "green").unwrap().clone();
108 linker.define(&mut store, "red", "green", green)?;
109 module = Module::new(
110 store.engine(),
111 r#"(module
112 (import "red" "green" (func (result i32)))
113 (func (export "green") (result i32) (i32.mul (call 0) (i32.const 2)))
114 )"#,
115 )?;
116 }
117 let instance = linker.instantiate(&mut store, &module)?;
118 let func = instance
119 .get_export(&mut store, "green")
120 .unwrap()
121 .into_func()
122 .unwrap();
123 let func = func.typed::<(), i32>(&store)?;
124 assert_eq!(func.call(&mut store, ())?, 112);
125 Ok(())
126}
127
128// Same as `function_interposition`, but the linker's name for the function
129// differs from the module's name.

Callers

nothing calls this directly

Calls 10

OkFunction · 0.85
newFunction · 0.50
engineMethod · 0.45
allow_shadowingMethod · 0.45
instantiateMethod · 0.45
cloneMethod · 0.45
unwrapMethod · 0.45
get_exportMethod · 0.45
defineMethod · 0.45
into_funcMethod · 0.45

Tested by

no test coverage detected