Recognize windows-sys signatures as "C" or "system" depending on cfg
diff --git a/src/dbghelp.rs b/src/dbghelp.rs
index 82b81e1..f8ea919 100644
--- a/src/dbghelp.rs
+++ b/src/dbghelp.rs
@@ -30,12 +30,6 @@
use core::ptr;
use core::slice;
-// This is used when we're double-checking function signatures against windows-sys.
-#[inline(always)]
-fn assert_equal_types<T>(a: T, _b: T) -> T {
- a
-}
-
// This macro is used to define a `Dbghelp` structure which internally contains
// all the function pointers that we might load.
macro_rules! dbghelp {
@@ -85,14 +79,23 @@
// either read the cached function pointer or load it and return the
// loaded value. Loads are asserted to succeed.
$(pub fn $name(&mut self) -> Option<$name> {
+ // Assert that windows_sys::$name is declared to have the same
+ // argument types and return type as our declaration, although
+ // it might be either extern "C" or extern "system".
+ cfg_if::cfg_if! {
+ if #[cfg(any(target_arch = "x86", not(windows_raw_dylib)))] {
+ let _: unsafe extern "system" fn($($argty),*) -> $ret = super::windows_sys::$name;
+ } else {
+ let _: unsafe extern "C" fn($($argty),*) -> $ret = super::windows_sys::$name;
+ }
+ }
+
unsafe {
if self.$name == 0 {
let name = concat!(stringify!($name), "\0");
self.$name = self.symbol(name.as_bytes())?;
}
- let ret = mem::transmute::<usize, $name>(self.$name);
- assert_equal_types(ret, super::windows_sys::$name);
- Some(ret)
+ Some(mem::transmute::<usize, $name>(self.$name))
}
})*