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

Function drop_func

tests/all/host_funcs.rs:47–82  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

45
46#[test]
47fn drop_func() -> Result<()> {
48 static HITS: AtomicUsize = AtomicUsize::new(0);
49 struct A;
50
51 impl Drop for A {
52 fn drop(&mut self) {
53 HITS.fetch_add(1, SeqCst);
54 }
55 }
56
57 let engine = Engine::default();
58 let mut linker = Linker::<()>::new(&engine);
59 linker.allow_shadowing(true);
60
61 let a = A;
62 linker.func_wrap("", "", move || {
63 let _ = &a;
64 })?;
65
66 assert_eq!(HITS.load(SeqCst), 0);
67
68 // Define the function again to ensure redefined functions are dropped
69
70 let a = A;
71 linker.func_wrap("", "", move || {
72 let _ = &a;
73 })?;
74
75 assert_eq!(HITS.load(SeqCst), 1);
76
77 drop(linker);
78
79 assert_eq!(HITS.load(SeqCst), 2);
80
81 Ok(())
82}
83
84#[test]
85#[cfg_attr(miri, ignore)]

Callers

nothing calls this directly

Calls 5

OkFunction · 0.85
newFunction · 0.50
dropFunction · 0.50
allow_shadowingMethod · 0.45
func_wrapMethod · 0.45

Tested by

no test coverage detected