Skip to content

Commit 26ab4af

Browse files
authored
Merge pull request #677 from dtolnay-contrib/rawdylib
Recognize windows-sys signatures as "C" or "system" depending on cfg
2 parents 4f3acf7 + d3c8205 commit 26ab4af

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/dbghelp.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@ use core::mem;
3030
use core::ptr;
3131
use core::slice;
3232

33-
// This is used when we're double-checking function signatures against windows-sys.
34-
#[inline(always)]
35-
fn assert_equal_types<T>(a: T, _b: T) -> T {
36-
a
37-
}
38-
3933
// This macro is used to define a `Dbghelp` structure which internally contains
4034
// all the function pointers that we might load.
4135
macro_rules! dbghelp {
@@ -85,14 +79,23 @@ macro_rules! dbghelp {
8579
// either read the cached function pointer or load it and return the
8680
// loaded value. Loads are asserted to succeed.
8781
$(pub fn $name(&mut self) -> Option<$name> {
82+
// Assert that windows_sys::$name is declared to have the same
83+
// argument types and return type as our declaration, although
84+
// it might be either extern "C" or extern "system".
85+
cfg_if::cfg_if! {
86+
if #[cfg(any(target_arch = "x86", not(windows_raw_dylib)))] {
87+
let _: unsafe extern "system" fn($($argty),*) -> $ret = super::windows_sys::$name;
88+
} else {
89+
let _: unsafe extern "C" fn($($argty),*) -> $ret = super::windows_sys::$name;
90+
}
91+
}
92+
8893
unsafe {
8994
if self.$name == 0 {
9095
let name = concat!(stringify!($name), "\0");
9196
self.$name = self.symbol(name.as_bytes())?;
9297
}
93-
let ret = mem::transmute::<usize, $name>(self.$name);
94-
assert_equal_types(ret, super::windows_sys::$name);
95-
Some(ret)
98+
Some(mem::transmute::<usize, $name>(self.$name))
9699
}
97100
})*
98101

0 commit comments

Comments
 (0)