Skip to content

Commit 54e7bdc

Browse files
committed
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).
1 parent 33d6572 commit 54e7bdc

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/libstd/rt/util.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use container::Container;
1212
use from_str::FromStr;
1313
use libc;
14-
use option::{Some, None};
14+
use option::{Some, None, Option};
1515
use os;
1616
use str::StrSlice;
1717
use unstable::atomics::{AtomicInt, INIT_ATOMIC_INT, SeqCst};
@@ -57,7 +57,13 @@ pub fn limit_thread_creation_due_to_osx_and_valgrind() -> bool {
5757
/// either `RUST_THREADS` or `num_cpus`.
5858
pub fn default_sched_threads() -> uint {
5959
match os::getenv("RUST_THREADS") {
60-
Some(nstr) => FromStr::from_str(nstr).unwrap(),
60+
Some(nstr) => {
61+
let opt_n: Option<uint> = FromStr::from_str(nstr);
62+
match opt_n {
63+
Some(n) if n > 0 => n,
64+
_ => rtabort!("`RUST_THREADS` is `%s`, should be a positive integer", nstr)
65+
}
66+
}
6167
None => {
6268
if limit_thread_creation_due_to_osx_and_valgrind() {
6369
1

0 commit comments

Comments
 (0)