| 1 | #[cfg (test)] |
| 2 | #[path = "./tests.rs" ] |
| 3 | mod tests; |
| 4 | |
| 5 | pub(crate) macro weak { |
| 6 | (fn $name:ident($($param:ident : $t:ty),* $(,)?) -> $ret:ty;) => ( |
| 7 | let ref $name: ExternWeak<unsafe extern "C" fn($($t),*) -> $ret> = { |
| 8 | unsafe extern "C" { |
| 9 | #[linkage = "extern_weak" ] |
| 10 | static $name: Option<unsafe extern "C" fn($($t),*) -> $ret>; |
| 11 | } |
| 12 | #[allow(unused_unsafe)] |
| 13 | ExternWeak::new(unsafe { $name }) |
| 14 | }; |
| 15 | ) |
| 16 | } |
| 17 | |
| 18 | pub(crate) struct ExternWeak<F: Copy> { |
| 19 | weak_ptr: Option<F>, |
| 20 | } |
| 21 | |
| 22 | impl<F: Copy> ExternWeak<F> { |
| 23 | #[inline ] |
| 24 | pub fn new(weak_ptr: Option<F>) -> Self { |
| 25 | ExternWeak { weak_ptr } |
| 26 | } |
| 27 | |
| 28 | #[inline ] |
| 29 | pub fn get(&self) -> Option<F> { |
| 30 | self.weak_ptr |
| 31 | } |
| 32 | } |
| 33 | |