]> git.lizzy.rs Git - rust.git/commitdiff
Apply suggestions from review
authorChristiaan Dirkx <christiaan@dirkx.email>
Sun, 18 Apr 2021 03:13:53 +0000 (05:13 +0200)
committerChristiaan Dirkx <christiaan@dirkx.email>
Thu, 22 Apr 2021 16:00:17 +0000 (18:00 +0200)
library/std/src/sys/unix/mod.rs
library/std/src/sys/windows/net.rs
library/std/src/sys_common/rt.rs

index bd9ac32b0d2bd5fe9c9d97c62029f2ad759522ed..8ae0c1120ff2b9245a3707033d9992ec3a8a15bc 100644 (file)
@@ -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",
index f577169e0e0ec725f4b4146e3e5617ffc3003536..1ad13254c0846f2e27bfd0a4793b906211ef991f 100644 (file)
@@ -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();
+        }
     }
 }
 
index dc20cf0e14ad19cfcc834bf1ac83d48be0c51a37..5906b4e3e0e47a078181264453484fea1a1e98c3 100644 (file)
@@ -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();
     });
 }