Skip to content

Commit 940e0b3

Browse files
committed
fix compat_fn option method on miri
1 parent 09d52bc commit 940e0b3

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

library/std/src/sys/windows/compat.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -103,20 +103,21 @@ macro_rules! compat_fn {
103103

104104
#[allow(dead_code)]
105105
pub fn option() -> Option<F> {
106-
unsafe { PTR }
106+
unsafe {
107+
if cfg!(miri) {
108+
// Miri does not run `init`, so we just call `get_f` each time.
109+
get_f()
110+
} else {
111+
PTR
112+
}
113+
}
107114
}
108115

109116
#[allow(dead_code)]
110117
pub unsafe fn call($($argname: $argtype),*) -> $rettype {
111-
if let Some(ptr) = PTR {
118+
if let Some(ptr) = option() {
112119
return ptr($($argname),*);
113120
}
114-
if cfg!(miri) {
115-
// Miri does not run `init`, so we just call `get_f` each time.
116-
if let Some(ptr) = get_f() {
117-
return ptr($($argname),*);
118-
}
119-
}
120121
$fallback_body
121122
}
122123
}

0 commit comments

Comments
 (0)