about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-10-10 21:59:10 -0700
committerAlex Crichton <alex@alexcrichton.com>2014-10-10 22:09:49 -0700
commitdae48a07f34dcf714b3b57029f4e03a0b95a269e (patch)
tree4ced3fe4c6c167508f0f7d1308473dfec676846d /src/libstd
parent1add4dedc131d5f98d82feafe80d92ed1f3f6d49 (diff)
downloadrust-dae48a07f34dcf714b3b57029f4e03a0b95a269e.tar.gz
rust-dae48a07f34dcf714b3b57029f4e03a0b95a269e.zip
Register new snapshots
Also convert a number of `static mut` to just a plain old `static` and remove
some unsafe blocks.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/dynamic_lib.rs4
-rw-r--r--src/libstd/io/tempfile.rs4
-rw-r--r--src/libstd/io/test.rs10
-rw-r--r--src/libstd/os.rs10
-rw-r--r--src/libstd/rt/backtrace.rs20
-rw-r--r--src/libstd/rt/util.rs6
6 files changed, 25 insertions, 29 deletions
diff --git a/src/libstd/dynamic_lib.rs b/src/libstd/dynamic_lib.rs
index 5cd0b3010c5..bc71f8ae790 100644
--- a/src/libstd/dynamic_lib.rs
+++ b/src/libstd/dynamic_lib.rs
@@ -230,11 +230,11 @@ pub mod dl {
 
     pub fn check_for_errors_in<T>(f: || -> T) -> Result<T, String> {
         use rt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
-        static mut lock: StaticNativeMutex = NATIVE_MUTEX_INIT;
+        static LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
         unsafe {
             // dlerror isn't thread safe, so we need to lock around this entire
             // sequence
-            let _guard = lock.lock();
+            let _guard = LOCK.lock();
             let _old_error = dlerror();
 
             let result = f();
diff --git a/src/libstd/io/tempfile.rs b/src/libstd/io/tempfile.rs
index 1d8aedb172b..e9d6ef2e341 100644
--- a/src/libstd/io/tempfile.rs
+++ b/src/libstd/io/tempfile.rs
@@ -38,14 +38,14 @@ impl TempDir {
             return TempDir::new_in(&os::make_absolute(tmpdir), suffix);
         }
 
-        static mut CNT: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT;
+        static CNT: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT;
 
         let mut attempts = 0u;
         loop {
             let filename =
                 format!("rs-{}-{}-{}",
                         unsafe { libc::getpid() },
-                        unsafe { CNT.fetch_add(1, atomic::SeqCst) },
+                        CNT.fetch_add(1, atomic::SeqCst),
                         suffix);
             let p = tmpdir.join(filename);
             match fs::mkdir(&p, io::USER_RWX) {
diff --git a/src/libstd/io/test.rs b/src/libstd/io/test.rs
index 1a47e20f585..9b4333a6d82 100644
--- a/src/libstd/io/test.rs
+++ b/src/libstd/io/test.rs
@@ -20,22 +20,20 @@ use sync::atomic::{AtomicUint, INIT_ATOMIC_UINT, Relaxed};
 
 /// Get a port number, starting at 9600, for use in tests
 pub fn next_test_port() -> u16 {
-    static mut next_offset: AtomicUint = INIT_ATOMIC_UINT;
-    unsafe {
-        base_port() + next_offset.fetch_add(1, Relaxed) as u16
-    }
+    static NEXT_OFFSET: AtomicUint = INIT_ATOMIC_UINT;
+    base_port() + NEXT_OFFSET.fetch_add(1, Relaxed) as u16
 }
 
 /// Get a temporary path which could be the location of a unix socket
 pub fn next_test_unix() -> Path {
-    static mut COUNT: AtomicUint = INIT_ATOMIC_UINT;
+    static COUNT: AtomicUint = INIT_ATOMIC_UINT;
     // base port and pid are an attempt to be unique between multiple
     // test-runners of different configurations running on one
     // buildbot, the count is to be unique within this executable.
     let string = format!("rust-test-unix-path-{}-{}-{}",
                          base_port(),
                          unsafe {libc::getpid()},
-                         unsafe {COUNT.fetch_add(1, Relaxed)});
+                         COUNT.fetch_add(1, Relaxed));
     if cfg!(unix) {
         os::tmpdir().join(string)
     } else {
diff --git a/src/libstd/os.rs b/src/libstd/os.rs
index 60386ec0631..03eca5c728b 100644
--- a/src/libstd/os.rs
+++ b/src/libstd/os.rs
@@ -192,10 +192,10 @@ Serialize access through a global lock.
 fn with_env_lock<T>(f: || -> T) -> T {
     use rt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
 
-    static mut lock: StaticNativeMutex = NATIVE_MUTEX_INIT;
+    static LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
 
     unsafe {
-        let _guard = lock.lock();
+        let _guard = LOCK.lock();
         f()
     }
 }
@@ -1073,7 +1073,7 @@ pub fn last_os_error() -> String {
     error_string(errno() as uint)
 }
 
-static mut EXIT_STATUS: AtomicInt = INIT_ATOMIC_INT;
+static EXIT_STATUS: AtomicInt = INIT_ATOMIC_INT;
 
 /**
  * Sets the process exit code
@@ -1086,13 +1086,13 @@ static mut EXIT_STATUS: AtomicInt = INIT_ATOMIC_INT;
  * Note that this is not synchronized against modifications of other threads.
  */
 pub fn set_exit_status(code: int) {
-    unsafe { EXIT_STATUS.store(code, SeqCst) }
+    EXIT_STATUS.store(code, SeqCst)
 }
 
 /// Fetches the process's current exit code. This defaults to 0 and can change
 /// by calling `set_exit_status`.
 pub fn get_exit_status() -> int {
-    unsafe { EXIT_STATUS.load(SeqCst) }
+    EXIT_STATUS.load(SeqCst)
 }
 
 #[cfg(target_os = "macos")]
diff --git a/src/libstd/rt/backtrace.rs b/src/libstd/rt/backtrace.rs
index 6cbbc0af390..e05e533be56 100644
--- a/src/libstd/rt/backtrace.rs
+++ b/src/libstd/rt/backtrace.rs
@@ -28,20 +28,18 @@ pub use self::imp::write;
 // For now logging is turned off by default, and this function checks to see
 // whether the magical environment variable is present to see if it's turned on.
 pub fn log_enabled() -> bool {
-    static mut ENABLED: atomic::AtomicInt = atomic::INIT_ATOMIC_INT;
-    unsafe {
-        match ENABLED.load(atomic::SeqCst) {
-            1 => return false,
-            2 => return true,
-            _ => {}
-        }
+    static ENABLED: atomic::AtomicInt = atomic::INIT_ATOMIC_INT;
+    match ENABLED.load(atomic::SeqCst) {
+        1 => return false,
+        2 => return true,
+        _ => {}
     }
 
     let val = match os::getenv("RUST_BACKTRACE") {
         Some(..) => 2,
         None => 1,
     };
-    unsafe { ENABLED.store(val, atomic::SeqCst); }
+    ENABLED.store(val, atomic::SeqCst);
     val == 2
 }
 
@@ -268,7 +266,7 @@ mod imp {
         // while it doesn't requires lock for work as everything is
         // local, it still displays much nicer backtraces when a
         // couple of tasks fail simultaneously
-        static mut LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
+        static LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
         let _g = unsafe { LOCK.lock() };
 
         try!(writeln!(w, "stack backtrace:"));
@@ -301,7 +299,7 @@ mod imp {
         // is semi-reasonable in terms of printing anyway, and we know that all
         // I/O done here is blocking I/O, not green I/O, so we don't have to
         // worry about this being a native vs green mutex.
-        static mut LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
+        static LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
         let _g = unsafe { LOCK.lock() };
 
         try!(writeln!(w, "stack backtrace:"));
@@ -931,7 +929,7 @@ mod imp {
     pub fn write(w: &mut Writer) -> IoResult<()> {
         // According to windows documentation, all dbghelp functions are
         // single-threaded.
-        static mut LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
+        static LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
         let _g = unsafe { LOCK.lock() };
 
         // Open up dbghelp.dll, we don't link to it explicitly because it can't
diff --git a/src/libstd/rt/util.rs b/src/libstd/rt/util.rs
index ed24ed2a569..ec301369804 100644
--- a/src/libstd/rt/util.rs
+++ b/src/libstd/rt/util.rs
@@ -41,8 +41,8 @@ pub fn limit_thread_creation_due_to_osx_and_valgrind() -> bool {
 }
 
 pub fn min_stack() -> uint {
-    static mut MIN: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT;
-    match unsafe { MIN.load(atomic::SeqCst) } {
+    static MIN: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT;
+    match MIN.load(atomic::SeqCst) {
         0 => {}
         n => return n - 1,
     }
@@ -50,7 +50,7 @@ pub fn min_stack() -> uint {
     let amt = amt.unwrap_or(2 * 1024 * 1024);
     // 0 is our sentinel value, so ensure that we'll never see 0 after
     // initialization has run
-    unsafe { MIN.store(amt + 1, atomic::SeqCst); }
+    MIN.store(amt + 1, atomic::SeqCst);
     return amt;
 }