]> git.lizzy.rs Git - rust.git/commitdiff
Remove the dependence of std::io::test on rand.
authorHuon Wilson <dbau.pp+github@gmail.com>
Sat, 1 Mar 2014 13:36:33 +0000 (00:36 +1100)
committerHuon Wilson <dbau.pp+github@gmail.com>
Wed, 12 Mar 2014 00:31:43 +0000 (11:31 +1100)
This replaces it with a manual "task rng" using XorShift and a crappy
seeding mechanism. Theoretically good enough for the purposes
though (unique for tests).

src/libstd/io/test.rs

index b491891ff59df15523fb61494bdea4e8e9bb877d..d6f7f58f01c84b966fc1249e52590b94a9497579 100644 (file)
 
 #[macro_escape];
 
+use libc;
 use os;
 use prelude::*;
-use rand;
-use rand::Rng;
 use std::io::net::ip::*;
 use sync::atomics::{AtomicUint, INIT_ATOMIC_UINT, Relaxed};
 
@@ -65,10 +64,18 @@ pub fn next_test_port() -> 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;
+    // 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)});
     if cfg!(unix) {
-        os::tmpdir().join(rand::task_rng().gen_ascii_str(20))
+        os::tmpdir().join(string)
     } else {
-        Path::new(r"\\.\pipe\" + rand::task_rng().gen_ascii_str(20))
+        Path::new(r"\\.\pipe\" + string)
     }
 }