auto merge of #8385 : cmr/rust/big-rollup, r=alexcrichton

This is a fairly large rollup, but I've tested everything locally, and none of
it should be platform-specific.

r=alexcrichton (bdfdbdd)
r=brson (d803c18)
r=alexcrichton (a5041d0)
r=bstrie (317412a)
r=alexcrichton (135c85e)
r=thestinger (8805baa)
r=pcwalton (0661178)
r=cmr (9397fe0)
r=cmr (caa4135)
r=cmr (6a21d93)
r=cmr (4dc3379)
r=cmr (0aa5154)
r=cmr (18be261)
r=thestinger (f10be03)
This commit is contained in:
bors 2013-08-08 14:32:02 -07:00
commit 8f65dbfcfa
70 changed files with 772 additions and 564 deletions

View file

@ -12,7 +12,7 @@
use clone::Clone;
use container::Container;
use iterator::{Iterator, range};
use iterator::Iterator;
use option::{Option, Some, None};
use sys;
use unstable::raw::Repr;
@ -92,8 +92,8 @@ pub fn append<T:Clone>(lhs: @[T], rhs: &[T]) -> @[T] {
for x in lhs.iter() {
push((*x).clone());
}
for i in range(0u, rhs.len()) {
push(rhs[i].clone());
for elt in rhs.iter() {
push(elt.clone());
}
}
}

View file

@ -314,7 +314,7 @@ mod pipesy {
#[allow(non_camel_case_types)]
pub mod oneshot {
priv use std::kinds::Send;
use std::kinds::Send;
use ptr::to_mut_unsafe_ptr;
pub fn init<T: Send>() -> (server::Oneshot<T>, client::Oneshot<T>) {
@ -341,7 +341,7 @@ mod pipesy {
#[allow(non_camel_case_types)]
pub mod client {
priv use std::kinds::Send;
use std::kinds::Send;
#[allow(non_camel_case_types)]
pub fn try_send<T: Send>(pipe: Oneshot<T>, x_0: T) ->
@ -489,7 +489,7 @@ mod pipesy {
#[allow(non_camel_case_types)]
pub mod streamp {
priv use std::kinds::Send;
use std::kinds::Send;
pub fn init<T: Send>() -> (server::Open<T>, client::Open<T>) {
pub use std::pipes::HasBuffer;
@ -501,7 +501,7 @@ mod pipesy {
#[allow(non_camel_case_types)]
pub mod client {
priv use std::kinds::Send;
use std::kinds::Send;
#[allow(non_camel_case_types)]
pub fn try_data<T: Send>(pipe: Open<T>, x_0: T) ->

View file

@ -19,7 +19,7 @@ use container::{Container, Mutable, Map, MutableMap, Set, MutableSet};
use clone::Clone;
use cmp::{Eq, Equiv};
use hash::Hash;
use iterator::{Iterator, IteratorUtil, FromIterator, Extendable, range};
use iterator::{Iterator, IteratorUtil, FromIterator, Extendable};
use iterator::{FilterMap, Chain, Repeat, Zip};
use num;
use option::{None, Option, Some};
@ -265,8 +265,8 @@ impl<K:Hash + Eq,V> Container for HashMap<K, V> {
impl<K:Hash + Eq,V> Mutable for HashMap<K, V> {
/// Clear the map, removing all key-value pairs.
fn clear(&mut self) {
for idx in range(0u, self.buckets.len()) {
self.buckets[idx] = None;
for bkt in self.buckets.mut_iter() {
*bkt = None;
}
self.size = 0;
}

View file

@ -18,9 +18,9 @@ implementing the `Iterator` trait.
*/
use cmp;
use num::{Zero, One, Saturating};
use num::{Zero, One, Integer, Saturating};
use option::{Option, Some, None};
use ops::{Add, Mul};
use ops::{Add, Mul, Sub};
use cmp::Ord;
use clone::Clone;
use uint;
@ -1531,7 +1531,7 @@ pub fn range<A: Add<A, A> + Ord + Clone + One>(start: A, stop: A) -> Range<A> {
Range{state: start, stop: stop, one: One::one()}
}
impl<A: Add<A, A> + Ord + Clone + One> Iterator<A> for Range<A> {
impl<A: Add<A, A> + Ord + Clone> Iterator<A> for Range<A> {
#[inline]
fn next(&mut self) -> Option<A> {
if self.state < self.stop {
@ -1544,6 +1544,22 @@ impl<A: Add<A, A> + Ord + Clone + One> Iterator<A> for Range<A> {
}
}
impl<A: Sub<A, A> + Integer + Ord + Clone> DoubleEndedIterator<A> for Range<A> {
#[inline]
fn next_back(&mut self) -> Option<A> {
if self.stop > self.state {
// Integer doesn't technically define this rule, but we're going to assume that every
// Integer is reachable from every other one by adding or subtracting enough Ones. This
// seems like a reasonable-enough rule that every Integer should conform to, even if it
// can't be statically checked.
self.stop = self.stop - self.one;
Some(self.stop.clone())
} else {
None
}
}
}
impl<A: Add<A, A> + Clone> Iterator<A> for Counter<A> {
#[inline]
fn next(&mut self) -> Option<A> {
@ -2121,4 +2137,17 @@ mod tests {
check_randacc_iter(xs.iter().cycle().take_(27), 27);
check_randacc_iter(empty.iter().cycle(), 0);
}
#[test]
fn test_double_ended_range() {
assert_eq!(range(11i, 14).invert().collect::<~[int]>(), ~[13i, 12, 11]);
for _ in range(10i, 0).invert() {
fail!("unreachable");
}
assert_eq!(range(11u, 14).invert().collect::<~[uint]>(), ~[13u, 12, 11]);
for _ in range(10u, 0).invert() {
fail!("unreachable");
}
}
}

View file

@ -278,18 +278,22 @@ impl One for f64 {
#[cfg(not(test))]
impl Add<f64,f64> for f64 {
#[inline]
fn add(&self, other: &f64) -> f64 { *self + *other }
}
#[cfg(not(test))]
impl Sub<f64,f64> for f64 {
#[inline]
fn sub(&self, other: &f64) -> f64 { *self - *other }
}
#[cfg(not(test))]
impl Mul<f64,f64> for f64 {
#[inline]
fn mul(&self, other: &f64) -> f64 { *self * *other }
}
#[cfg(not(test))]
impl Div<f64,f64> for f64 {
#[inline]
fn div(&self, other: &f64) -> f64 { *self / *other }
}
#[cfg(not(test))]

View file

@ -124,14 +124,6 @@ pub fn range_step_inclusive(start: $T, last: $T, step: $T, it: &fn($T) -> bool)
range_step_core(start, last, step, Closed, it)
}
#[inline]
/// Iterate over the range (`hi`..`lo`]
pub fn range_rev(hi: $T, lo: $T, it: &fn($T) -> bool) -> bool {
if hi == min_value { return true; }
range_step_inclusive(hi-1, lo, -1 as $T, it)
}
impl Num for $T {}
#[cfg(not(test))]
@ -889,10 +881,6 @@ mod tests {
fn test_ranges() {
let mut l = ~[];
do range_rev(14,11) |i| {
l.push(i);
true
};
do range_step(20,26,2) |i| {
l.push(i);
true
@ -917,8 +905,7 @@ mod tests {
l.push(i);
true
};
assert_eq!(l, ~[13,12,11,
20,22,24,
assert_eq!(l, ~[20,22,24,
36,34,32,
max_value-2,
max_value-3,max_value-1,
@ -926,9 +913,6 @@ mod tests {
min_value+3,min_value+1]);
// None of the `fail`s should execute.
do range_rev(0,10) |_i| {
fail!(~"unreachable");
};
do range_step(10,0,1) |_i| {
fail!(~"unreachable");
};

View file

@ -422,9 +422,9 @@ pub fn float_to_str_common<T:NumCast+Zero+One+Eq+Ord+NumStrConv+Float+Round+
// Some constants for from_str_bytes_common's input validation,
// they define minimum radix values for which the character is a valid digit.
priv static DIGIT_P_RADIX: uint = ('p' as uint) - ('a' as uint) + 11u;
priv static DIGIT_I_RADIX: uint = ('i' as uint) - ('a' as uint) + 11u;
priv static DIGIT_E_RADIX: uint = ('e' as uint) - ('a' as uint) + 11u;
static DIGIT_P_RADIX: uint = ('p' as uint) - ('a' as uint) + 11u;
static DIGIT_I_RADIX: uint = ('i' as uint) - ('a' as uint) + 11u;
static DIGIT_E_RADIX: uint = ('e' as uint) - ('a' as uint) + 11u;
/**
* Parses a byte slice as a number. This is meant to

View file

@ -125,13 +125,6 @@ pub fn range_step_inclusive(start: $T, last: $T, step: $T_SIGNED, it: &fn($T) ->
range_step_core(start, last, step, Closed, it)
}
#[inline]
/// Iterate over the range (`hi`..`lo`]
pub fn range_rev(hi: $T, lo: $T, it: &fn($T) -> bool) -> bool {
if hi == min_value { return true; }
range_step_inclusive(hi-1, lo, -1 as $T_SIGNED, it)
}
impl Num for $T {}
#[cfg(not(test))]
@ -654,10 +647,6 @@ mod tests {
pub fn test_ranges() {
let mut l = ~[];
do range_rev(14,11) |i| {
l.push(i);
true
};
do range_step(20,26,2) |i| {
l.push(i);
true
@ -683,8 +672,7 @@ mod tests {
true
};
assert_eq!(l, ~[13,12,11,
20,22,24,
assert_eq!(l, ~[20,22,24,
36,34,32,
max_value-2,
max_value-3,max_value-1,
@ -692,9 +680,6 @@ mod tests {
min_value+3,min_value+1]);
// None of the `fail`s should execute.
do range_rev(0,0) |_i| {
fail!("unreachable");
};
do range_step(10,0,1) |_i| {
fail!("unreachable");
};

View file

@ -610,15 +610,32 @@ impl<R: Rng> RngUtil for R {
}
/// Create a random number generator with a default algorithm and seed.
///
/// It returns the cryptographically-safest `Rng` algorithm currently
/// available in Rust. If you require a specifically seeded `Rng` for
/// consistency over time you should pick one algorithm and create the
/// `Rng` yourself.
pub fn rng() -> IsaacRng {
IsaacRng::new()
}
/// Create a weak random number generator with a default algorithm and seed.
///
/// It returns the fatest `Rng` algorithm currently available in Rust without
/// consideration for cryptography or security. If you require a specifically
/// seeded `Rng` for consistency over time you should pick one algorithm and
/// create the `Rng` yourself.
pub fn weak_rng() -> XorShiftRng {
XorShiftRng::new()
}
static RAND_SIZE_LEN: u32 = 8;
static RAND_SIZE: u32 = 1 << RAND_SIZE_LEN;
/// A random number generator that uses the [ISAAC
/// algorithm](http://en.wikipedia.org/wiki/ISAAC_%28cipher%29).
///
/// The ISAAC algorithm is suitable for cryptographic purposes.
pub struct IsaacRng {
priv cnt: u32,
priv rsl: [u32, .. RAND_SIZE],
@ -794,8 +811,11 @@ impl Rng for IsaacRng {
}
/// An [Xorshift random number
/// generator](http://en.wikipedia.org/wiki/Xorshift). Not suitable for
/// cryptographic purposes.
/// generator](http://en.wikipedia.org/wiki/Xorshift).
///
/// The Xorshift algorithm is not suitable for cryptographic purposes
/// but is very fast. If you do not know for sure that it fits your
/// requirements, use a more secure one such as `IsaacRng`.
pub struct XorShiftRng {
priv x: u32,
priv y: u32,

View file

@ -508,7 +508,11 @@ impl<T> Peekable<T> for Port<T> {
}
}
impl<T> Select for Port<T> {
// XXX: Kind of gross. A Port<T> should be selectable so you can make an array
// of them, but a &Port<T> should also be selectable so you can select2 on it
// alongside a PortOne<U> without passing the port by value in recv_ready.
impl<'self, T> Select for &'self Port<T> {
#[inline]
fn optimistic_check(&mut self) -> bool {
do self.next.with_mut_ref |pone| { pone.optimistic_check() }
@ -526,12 +530,29 @@ impl<T> Select for Port<T> {
}
}
impl<T> SelectPort<(T, Port<T>)> for Port<T> {
fn recv_ready(self) -> Option<(T, Port<T>)> {
impl<T> Select for Port<T> {
#[inline]
fn optimistic_check(&mut self) -> bool {
(&*self).optimistic_check()
}
#[inline]
fn block_on(&mut self, sched: &mut Scheduler, task: BlockedTask) -> bool {
(&*self).block_on(sched, task)
}
#[inline]
fn unblock_from(&mut self) -> bool {
(&*self).unblock_from()
}
}
impl<'self, T> SelectPort<T> for &'self Port<T> {
fn recv_ready(self) -> Option<T> {
match self.next.take().recv_ready() {
Some(StreamPayload { val, next }) => {
self.next.put_back(next);
Some((val, self))
Some(val)
}
None => None
}

View file

@ -590,7 +590,8 @@ impl Death {
#[inline]
pub fn assert_may_sleep(&self) {
if self.wont_sleep != 0 {
rtabort!("illegal atomic-sleep: can't deschedule inside atomically()");
rtabort!("illegal atomic-sleep: attempt to reschedule while \
using an Exclusive or LittleLock");
}
}
}

View file

@ -199,9 +199,7 @@ mod test {
// get it back out
util::swap(port.get_mut_ref(), &mut ports[index]);
// NB. Not recv(), because optimistic_check randomly fails.
let (data, new_port) = port.take_unwrap().recv_ready().unwrap();
assert!(data == 31337);
port = Some(new_port);
assert!(port.get_ref().recv_ready().unwrap() == 31337);
}
}
}

View file

@ -632,7 +632,6 @@ fn spawn_process_os(prog: &str, args: &[~str],
use libc::funcs::posix88::unistd::{fork, dup2, close, chdir, execvp};
use libc::funcs::bsd44::getdtablesize;
use int;
mod rustrt {
use libc::c_void;
@ -665,10 +664,9 @@ fn spawn_process_os(prog: &str, args: &[~str],
fail!("failure in dup3(err_fd, 2): %s", os::last_os_error());
}
// close all other fds
do int::range_rev(getdtablesize() as int, 3) |fd| {
for fd in range(3, getdtablesize()).invert() {
close(fd as c_int);
true
};
}
do with_dirp(dir) |dirp| {
if !dirp.is_null() && chdir(dirp) == -1 {
@ -763,14 +761,14 @@ fn with_dirp<T>(d: Option<&Path>,
}
#[cfg(windows)]
priv fn free_handle(handle: *()) {
fn free_handle(handle: *()) {
unsafe {
libc::funcs::extra::kernel32::CloseHandle(cast::transmute(handle));
}
}
#[cfg(unix)]
priv fn free_handle(_handle: *()) {
fn free_handle(_handle: *()) {
// unix has no process handle object, just a pid
}
@ -825,7 +823,7 @@ pub fn process_output(prog: &str, args: &[~str]) -> ProcessOutput {
* operate on a none-existant process or, even worse, on a newer process
* with the same id.
*/
priv fn waitpid(pid: pid_t) -> int {
fn waitpid(pid: pid_t) -> int {
return waitpid_os(pid);
#[cfg(windows)]

View file

@ -738,7 +738,7 @@ pub fn count_bytes<'b>(s: &'b str, start: uint, n: uint) -> uint {
}
// https://tools.ietf.org/html/rfc3629
priv static UTF8_CHAR_WIDTH: [u8, ..256] = [
static UTF8_CHAR_WIDTH: [u8, ..256] = [
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x1F
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
@ -781,15 +781,15 @@ macro_rules! utf8_acc_cont_byte(
)
// UTF-8 tags and ranges
priv static TAG_CONT_U8: u8 = 128u8;
priv static TAG_CONT: uint = 128u;
priv static MAX_ONE_B: uint = 128u;
priv static TAG_TWO_B: uint = 192u;
priv static MAX_TWO_B: uint = 2048u;
priv static TAG_THREE_B: uint = 224u;
priv static MAX_THREE_B: uint = 65536u;
priv static TAG_FOUR_B: uint = 240u;
priv static MAX_UNICODE: uint = 1114112u;
static TAG_CONT_U8: u8 = 128u8;
static TAG_CONT: uint = 128u;
static MAX_ONE_B: uint = 128u;
static TAG_TWO_B: uint = 192u;
static MAX_TWO_B: uint = 2048u;
static TAG_THREE_B: uint = 224u;
static MAX_THREE_B: uint = 65536u;
static TAG_FOUR_B: uint = 240u;
static MAX_UNICODE: uint = 1114112u;
/// Unsafe operations
pub mod raw {

View file

@ -274,7 +274,7 @@ pub fn to_ascii_lower(string: &str) -> ~str {
}
#[inline]
priv fn map_bytes(string: &str, map: &'static [u8]) -> ~str {
fn map_bytes(string: &str, map: &'static [u8]) -> ~str {
let len = string.len();
let mut result = str::with_capacity(len);
unsafe {
@ -298,7 +298,7 @@ pub fn eq_ignore_ascii_case(a: &str, b: &str) -> bool {
|(byte_a, byte_b)| ASCII_LOWER_MAP[*byte_a] == ASCII_LOWER_MAP[*byte_b])
}
priv static ASCII_LOWER_MAP: &'static [u8] = &[
static ASCII_LOWER_MAP: &'static [u8] = &[
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
@ -333,7 +333,7 @@ priv static ASCII_LOWER_MAP: &'static [u8] = &[
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
];
priv static ASCII_UPPER_MAP: &'static [u8] = &[
static ASCII_UPPER_MAP: &'static [u8] = &[
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,

View file

@ -271,8 +271,8 @@ impl<T> TrieNode<T> {
impl<T> TrieNode<T> {
fn each<'a>(&'a self, f: &fn(&uint, &'a T) -> bool) -> bool {
for idx in range(0u, self.children.len()) {
match self.children[idx] {
for elt in self.children.iter() {
match *elt {
Internal(ref x) => if !x.each(|i,t| f(i,t)) { return false },
External(k, ref v) => if !f(&k, v) { return false },
Nothing => ()
@ -282,13 +282,14 @@ impl<T> TrieNode<T> {
}
fn each_reverse<'a>(&'a self, f: &fn(&uint, &'a T) -> bool) -> bool {
do uint::range_rev(self.children.len(), 0) |idx| {
match self.children[idx] {
Internal(ref x) => x.each_reverse(|i,t| f(i,t)),
External(k, ref v) => f(&k, v),
Nothing => true
for elt in self.children.rev_iter() {
match *elt {
Internal(ref x) => if !x.each_reverse(|i,t| f(i,t)) { return false },
External(k, ref v) => if !f(&k, v) { return false },
Nothing => ()
}
}
true
}
fn mutate_values<'a>(&'a mut self, f: &fn(&uint, &mut T) -> bool) -> bool {
@ -539,10 +540,9 @@ mod test_map {
fn test_each_break() {
let mut m = TrieMap::new();
do uint::range_rev(uint::max_value, uint::max_value - 10000) |x| {
for x in range(uint::max_value - 10000, uint::max_value).invert() {
m.insert(x, x / 2);
true
};
}
let mut n = uint::max_value - 10000;
do m.each |k, v| {
@ -580,10 +580,9 @@ mod test_map {
fn test_each_reverse_break() {
let mut m = TrieMap::new();
do uint::range_rev(uint::max_value, uint::max_value - 10000) |x| {
for x in range(uint::max_value - 10000, uint::max_value).invert() {
m.insert(x, x / 2);
true
};
}
let mut n = uint::max_value - 1;
do m.each_reverse |k, v| {
@ -634,10 +633,9 @@ mod test_map {
let last = uint::max_value;
let mut map = TrieMap::new();
do uint::range_rev(last, first) |x| {
for x in range(first, last).invert() {
map.insert(x, x / 2);
true
};
}
let mut i = 0;
for (k, &v) in map.iter() {

View file

@ -1602,8 +1602,8 @@ impl<T:Clone> OwnedCopyableVector<T> for ~[T] {
let new_len = self.len() + rhs.len();
self.reserve(new_len);
for i in range(0u, rhs.len()) {
self.push(unsafe { raw::get(rhs, i) })
for elt in rhs.iter() {
self.push((*elt).clone())
}
}