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

Function drop_delayed

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

Source from the content-addressed store, hash-verified

84#[test]
85#[cfg_attr(miri, ignore)]
86fn drop_delayed() -> Result<()> {
87 static HITS: AtomicUsize = AtomicUsize::new(0);
88
89 struct A;
90
91 impl Drop for A {
92 fn drop(&mut self) {
93 HITS.fetch_add(1, SeqCst);
94 }
95 }
96
97 let engine = Engine::default();
98 let mut linker = Linker::<()>::new(&engine);
99
100 let a = A;
101 linker.func_wrap("", "", move || {
102 let _ = &a;
103 })?;
104
105 assert_eq!(HITS.load(SeqCst), 0);
106
107 let module = Module::new(&engine, &wat::parse_str(r#"(import "" "" (func))"#)?)?;
108
109 let mut store = Store::new(&engine, ());
110 let func = linker.get(&mut store, "", "").unwrap();
111 Instance::new(&mut store, &module, &[func])?;
112
113 drop(store);
114
115 assert_eq!(HITS.load(SeqCst), 0);
116
117 let mut store = Store::new(&engine, ());
118 let func = linker.get(&mut store, "", "").unwrap();
119 Instance::new(&mut store, &module, &[func])?;
120
121 drop(store);
122
123 assert_eq!(HITS.load(SeqCst), 0);
124
125 drop(linker);
126
127 assert_eq!(HITS.load(SeqCst), 1);
128
129 Ok(())
130}
131
132#[test]
133fn signatures_match() -> Result<()> {

Callers

nothing calls this directly

Calls 6

OkFunction · 0.85
newFunction · 0.50
dropFunction · 0.50
func_wrapMethod · 0.45
unwrapMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected