File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed
library/std/src/sys/windows Expand file tree Collapse file tree 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 {
7777 static INIT_TABLE_ENTRY : unsafe extern "C" fn ( ) = init;
7878
7979 unsafe extern "C" fn init( ) {
80+ PTR = get_f( ) ;
81+ }
82+
83+ unsafe extern "C" fn get_f( ) -> Option <F > {
8084 // There is no locking here. This code is executed before main() is entered, and
8185 // is guaranteed to be single-threaded.
8286 //
@@ -91,10 +95,11 @@ macro_rules! compat_fn {
9195 match $crate:: sys:: c:: GetProcAddress ( module_handle, symbol_name as * const i8 ) . addr( ) {
9296 0 => { }
9397 n => {
94- PTR = Some ( mem:: transmute:: <usize , F >( n) ) ;
98+ return Some ( mem:: transmute:: <usize , F >( n) ) ;
9599 }
96100 }
97101 }
102+ return None ;
98103 }
99104
100105 #[ allow( dead_code) ]
@@ -105,10 +110,15 @@ macro_rules! compat_fn {
105110 #[ allow( dead_code) ]
106111 pub unsafe fn call( $( $argname: $argtype) ,* ) -> $rettype {
107112 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+ }
111120 }
121+ $fallback_body
112122 }
113123 }
114124
You can’t perform that action at this time.
0 commit comments