From 8aeea227daf4a78761c41bb32321e8b2e505d27e Mon Sep 17 00:00:00 2001 From: Christiaan Dirkx Date: Sun, 18 Apr 2021 05:13:53 +0200 Subject: [PATCH 1/1] Apply suggestions from review --- library/std/src/sys/unix/mod.rs | 4 ++-- library/std/src/sys/windows/net.rs | 13 ++++++++----- library/std/src/sys_common/rt.rs | 4 ++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/library/std/src/sys/unix/mod.rs b/library/std/src/sys/unix/mod.rs index bd9ac32b0d2..8ae0c1120ff 100644 --- a/library/std/src/sys/unix/mod.rs +++ b/library/std/src/sys/unix/mod.rs @@ -64,10 +64,10 @@ pub unsafe fn init(argc: isize, argv: *const *const u8) { args::init(argc, argv); unsafe fn sanitize_standard_fds() { + #[cfg(not(miri))] + // The standard fds are always available in Miri. cfg_if::cfg_if! { if #[cfg(not(any( - // The standard fds are always available in Miri. - miri, target_os = "emscripten", target_os = "fuchsia", target_os = "vxworks", diff --git a/library/std/src/sys/windows/net.rs b/library/std/src/sys/windows/net.rs index f577169e0e0..1ad13254c08 100644 --- a/library/std/src/sys/windows/net.rs +++ b/library/std/src/sys/windows/net.rs @@ -26,12 +26,12 @@ pub mod netc { pub struct Socket(c::SOCKET); +static INIT: Once = Once::new(); + /// Checks whether the Windows socket interface has been started already, and /// if not, starts it. pub fn init() { - static START: Once = Once::new(); - - START.call_once(|| unsafe { + INIT.call_once(|| unsafe { let mut data: c::WSADATA = mem::zeroed(); let ret = c::WSAStartup( 0x202, // version 2.2 @@ -42,8 +42,11 @@ pub fn init() { } pub fn cleanup() { - unsafe { - c::WSACleanup(); + if INIT.is_completed() { + // only close the socket interface if it has actually been started + unsafe { + c::WSACleanup(); + } } } diff --git a/library/std/src/sys_common/rt.rs b/library/std/src/sys_common/rt.rs index dc20cf0e14a..5906b4e3e0e 100644 --- a/library/std/src/sys_common/rt.rs +++ b/library/std/src/sys_common/rt.rs @@ -29,10 +29,10 @@ pub fn init(argc: isize, argv: *const *const u8) { pub fn cleanup() { static CLEANUP: Once = Once::new(); CLEANUP.call_once(|| unsafe { - // SAFETY: Only called once during runtime cleanup. - sys::cleanup(); // Flush stdout and disable buffering. crate::io::cleanup(); + // SAFETY: Only called once during runtime cleanup. + sys::cleanup(); }); } -- 2.44.0