about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorHuon Wilson <dbau.pp+github@gmail.com>2013-08-29 20:57:37 +1000
committerHuon Wilson <dbau.pp+github@gmail.com>2013-08-29 22:55:59 +1000
commit54e7bdc48e97d369acd51d1c08988fd946ccafd2 (patch)
tree1477e941b25b68ca5633d7448afa9c60ea04fcb8 /src/libstd
parent33d65720360dedf612cab5f0d4343429e11b227e (diff)
downloadrust-54e7bdc48e97d369acd51d1c08988fd946ccafd2.tar.gz
rust-54e7bdc48e97d369acd51d1c08988fd946ccafd2.zip
rt: Handle non-integer RUST_THREADS (slightly) more gracefully.
Previously it would call Option.unwrap(), which calls `fail!` on None,
which doesn't work without the runtime (e.g. when initialising it).
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/rt/util.rs10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/libstd/rt/util.rs b/src/libstd/rt/util.rs
index 9113f03ffee..6f39cbbade3 100644
--- a/src/libstd/rt/util.rs
+++ b/src/libstd/rt/util.rs
@@ -11,7 +11,7 @@
 use container::Container;
 use from_str::FromStr;
 use libc;
-use option::{Some, None};
+use option::{Some, None, Option};
 use os;
 use str::StrSlice;
 use unstable::atomics::{AtomicInt, INIT_ATOMIC_INT, SeqCst};
@@ -57,7 +57,13 @@ pub fn limit_thread_creation_due_to_osx_and_valgrind() -> bool {
 /// either `RUST_THREADS` or `num_cpus`.
 pub fn default_sched_threads() -> uint {
     match os::getenv("RUST_THREADS") {
-        Some(nstr) => FromStr::from_str(nstr).unwrap(),
+        Some(nstr) => {
+            let opt_n: Option<uint> = FromStr::from_str(nstr);
+            match opt_n {
+                Some(n) if n > 0 => n,
+                _ => rtabort!("`RUST_THREADS` is `%s`, should be a positive integer", nstr)
+            }
+        }
         None => {
             if limit_thread_creation_due_to_osx_and_valgrind() {
                 1