File tree 1 file changed +14
-4
lines changed
library/std/src/sys/windows
1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -77,6 +77,10 @@ macro_rules! compat_fn {
77
77
static INIT_TABLE_ENTRY : unsafe extern "C" fn ( ) = init;
78
78
79
79
unsafe extern "C" fn init( ) {
80
+ PTR = get_f( ) ;
81
+ }
82
+
83
+ unsafe extern "C" fn get_f( ) -> Option <F > {
80
84
// There is no locking here. This code is executed before main() is entered, and
81
85
// is guaranteed to be single-threaded.
82
86
//
@@ -91,10 +95,11 @@ macro_rules! compat_fn {
91
95
match $crate:: sys:: c:: GetProcAddress ( module_handle, symbol_name as * const i8 ) . addr( ) {
92
96
0 => { }
93
97
n => {
94
- PTR = Some ( mem:: transmute:: <usize , F >( n) ) ;
98
+ return Some ( mem:: transmute:: <usize , F >( n) ) ;
95
99
}
96
100
}
97
101
}
102
+ return None ;
98
103
}
99
104
100
105
#[ allow( dead_code) ]
@@ -105,10 +110,15 @@ macro_rules! compat_fn {
105
110
#[ allow( dead_code) ]
106
111
pub unsafe fn call( $( $argname: $argtype) ,* ) -> $rettype {
107
112
if let Some ( ptr) = PTR {
108
- ptr( $( $argname) ,* )
109
- } else {
110
- $fallback_body
113
+ return ptr( $( $argname) ,* ) ;
114
+ }
115
+ if cfg!( miri) {
116
+ // Miri does not run `init`, so we just call `get_f` each time.
117
+ if let Some ( ptr) = get_f( ) {
118
+ return ptr( $( $argname) ,* ) ;
119
+ }
111
120
}
121
+ $fallback_body
112
122
}
113
123
}
114
124
You can’t perform that action at this time.
0 commit comments