The only user-facing change is handling non-integer (and zero) `RUST_THREADS` more nicely:
```
$ RUST_THREADS=x rustc # old
You've met with a terrible fate, haven't you?
fatal runtime error: runtime tls key not initialized
Aborted
$ RUST_THREADS=x ./x86_64-unknown-linux-gnu/stage2/bin/rustc # new
You've met with a terrible fate, haven't you?
fatal runtime error: `RUST_THREADS` is `x`, should be a positive integer
Aborted
```
The other changes are converting some `for .. in range(x,y)` to `vec::from_fn` or `for .. in x.iter()` as appropriate; and removing a chain of (seemingly) unnecessary pointer casts.
(Also, fixes a typo in `extra::test` from #8823.)
let opt_n: Option<uint> = FromStr::from_str(s);
match opt_n {
Some(n) if n > 0 => n,
- _ => fail!("RUST_TEST_TASKS is `%s`, should be a non-negative integer.", s)
+ _ => fail!("RUST_TEST_TASKS is `%s`, should be a positive integer.", s)
}
}
None => {
mod imp {
use libc;
use option::{Option, Some, None};
- use iterator::{Iterator, range};
+ use iterator::Iterator;
use str;
use unstable::finally::Finally;
use util;
+ use vec;
pub unsafe fn init(argc: int, argv: **u8) {
let args = load_argc_and_argv(argc, argv);
// Copied from `os`.
unsafe fn load_argc_and_argv(argc: int, argv: **u8) -> ~[~str] {
- let mut args = ~[];
- for i in range(0u, argc as uint) {
- args.push(str::raw::from_c_str(*(argv as **libc::c_char).offset(i as int)));
+ do vec::from_fn(argc as uint) |i| {
+ str::raw::from_c_str(*(argv as **libc::c_char).offset(i as int))
}
- args
}
#[cfg(stage0)]
/// For the Scheduler pointer to be aliased
pub unsafe fn unsafe_borrow<T>() -> *mut T {
let key = tls_key();
- let mut void_ptr: *mut c_void = tls::get(key);
+ let void_ptr = tls::get(key);
if void_ptr.is_null() {
rtabort!("thread-local pointer is null. bogus!");
}
- let ptr: *mut *mut c_void = &mut void_ptr;
- let ptr: *mut ~T = ptr as *mut ~T;
- let ptr: *mut T = &mut **ptr;
- return ptr;
+ void_ptr as *mut T
}
pub unsafe fn try_unsafe_borrow<T>() -> Option<*mut T> {
let key = tls_key();
- let mut void_ptr: *mut c_void = tls::get(key);
+ let void_ptr = tls::get(key);
if void_ptr.is_null() {
- return None;
- }
- {
- let ptr: *mut *mut c_void = &mut void_ptr;
- let ptr: *mut ~T = ptr as *mut ~T;
- let ptr: *mut T = &mut **ptr;
- return Some(ptr);
+ None
+ } else {
+ Some(void_ptr as *mut T)
}
}
use cell::Cell;
use clone::Clone;
use container::Container;
-use iterator::{Iterator, range};
+use iterator::Iterator;
use option::{Option, None, Some};
use ptr::RawPtr;
use rt::local::Local;
use rt::uv::uvio::UvEventLoop;
use unstable::atomics::{AtomicInt, SeqCst};
use unstable::sync::UnsafeArc;
-use vec::{OwnedVector, MutableVector};
+use vec;
+use vec::{OwnedVector, MutableVector, ImmutableVector};
/// The global (exchange) heap.
pub mod global_heap;
// Create a work queue for each scheduler, ntimes. Create an extra
// for the main thread if that flag is set. We won't steal from it.
- let mut work_queues = ~[];
- for _ in range(0u, nscheds) {
- let work_queue: WorkQueue<~Task> = WorkQueue::new();
- work_queues.push(work_queue);
- }
+ let work_queues: ~[WorkQueue<~Task>] = vec::from_fn(nscheds, |_| WorkQueue::new());
// The schedulers.
let mut scheds = ~[];
// sent the Shutdown message to terminate the schedulers.
let mut handles = ~[];
- for i in range(0u, nscheds) {
+ for work_queue in work_queues.iter() {
rtdebug!("inserting a regular scheduler");
// Every scheduler is driven by an I/O event loop.
let loop_ = ~UvEventLoop::new();
let mut sched = ~Scheduler::new(loop_,
- work_queues[i].clone(),
+ work_queue.clone(),
work_queues.clone(),
sleepers.clone());
let handle = sched.make_handle();
}
// Run each remaining scheduler in a thread.
- while !scheds.is_empty() {
+ for sched in scheds.move_rev_iter() {
rtdebug!("creating regular schedulers");
- let sched = scheds.pop();
let sched_cell = Cell::new(sched);
let thread = do Thread::start {
let mut sched = sched_cell.take();
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};
/// 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
--- /dev/null
+// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// This checks that RUST_TEST_TASKS not being 1, 2, ... is detected
+// properly.
+
+// error-pattern:should be a positive integer
+// compile-flags: --test
+// exec-env:RUST_TEST_TASKS=foo
+
+#[test]
+fn do_nothing() {}
+++ /dev/null
-// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// This checks that RUST_TEST_TASKS not being 1, 2, ... is detected
-// properly.
-
-// error-pattern:should be a non-negative integer
-// compile-flags: --test
-// exec-env:RUST_TEST_TASKS=foo
-
-#[test]
-fn do_nothing() {}