From 7f3d11e1d8c8610894e8960116628f0b77b11cad Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Sun, 31 Jul 2022 14:45:26 +0100 Subject: [PATCH 1/2] Fix compat.rs for `cfg(miri)` --- library/std/src/sys/windows/compat.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/sys/windows/compat.rs b/library/std/src/sys/windows/compat.rs index b4ffbdc9609..b8df46957a5 100644 --- a/library/std/src/sys/windows/compat.rs +++ b/library/std/src/sys/windows/compat.rs @@ -251,7 +251,7 @@ pub fn option() -> Option { pub fn option() -> Option { let mut func = NonNull::new(PTR.load(Ordering::Relaxed)); if func.is_none() { - Module::new($module).map(preload); + unsafe { Module::new($module).map(preload) }; func = NonNull::new(PTR.load(Ordering::Relaxed)); } unsafe { From bf0b18e91005d22081b5122c4dba8ee7f1c108d5 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Sun, 31 Jul 2022 15:07:47 +0100 Subject: [PATCH 2/2] Make sure `symbol_name` is const evaluated --- library/std/src/sys/windows/compat.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/std/src/sys/windows/compat.rs b/library/std/src/sys/windows/compat.rs index b8df46957a5..ccc90177a20 100644 --- a/library/std/src/sys/windows/compat.rs +++ b/library/std/src/sys/windows/compat.rs @@ -180,8 +180,8 @@ pub mod $symbol { fn load_from_module(module: Option) -> F { unsafe { - static symbol_name: &CStr = ansi_str!(sym $symbol); - if let Some(f) = module.and_then(|m| m.proc_address(symbol_name)) { + static SYMBOL_NAME: &CStr = ansi_str!(sym $symbol); + if let Some(f) = module.and_then(|m| m.proc_address(SYMBOL_NAME)) { PTR.store(f.as_ptr(), Ordering::Relaxed); mem::transmute(f) } else { @@ -262,8 +262,8 @@ pub fn option() -> Option { #[allow(unused)] pub(in crate::sys) fn preload(module: Module) { unsafe { - let symbol_name = ansi_str!(sym $symbol); - if let Some(f) = module.proc_address(symbol_name) { + static SYMBOL_NAME: &CStr = ansi_str!(sym $symbol); + if let Some(f) = module.proc_address(SYMBOL_NAME) { PTR.store(f.as_ptr(), Ordering::Relaxed); } }