| 84 | #[test] |
| 85 | #[cfg_attr(miri, ignore)] |
| 86 | fn 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] |
| 133 | fn signatures_match() -> Result<()> { |