diff options
| author | bors <bors@rust-lang.org> | 2014-04-08 08:16:52 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-04-08 08:16:52 -0700 |
| commit | 02f51211eddbbaf6c6e02cecc78957ce1d5b4600 (patch) | |
| tree | d7c5f1dbc4a37e473577b39abd56e2f1df433069 /src/libstd | |
| parent | e415c25bcd81dc1f9a5a3d25d9b48ed2d545336b (diff) | |
| parent | da8d4fddc6445c19ad434a1f104c1c310c6c3c34 (diff) | |
| download | rust-02f51211eddbbaf6c6e02cecc78957ce1d5b4600.tar.gz rust-02f51211eddbbaf6c6e02cecc78957ce1d5b4600.zip | |
auto merge of #13397 : alexcrichton/rust/rollup, r=alexcrichton
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/c_vec.rs | 4 | ||||
| -rw-r--r-- | src/libstd/io/mod.rs | 8 | ||||
| -rw-r--r-- | src/libstd/io/net/unix.rs | 2 | ||||
| -rw-r--r-- | src/libstd/io/stdio.rs | 10 | ||||
| -rw-r--r-- | src/libstd/iter.rs | 36 | ||||
| -rw-r--r-- | src/libstd/lib.rs | 1 | ||||
| -rw-r--r-- | src/libstd/macros.rs | 3 | ||||
| -rw-r--r-- | src/libstd/ptr.rs | 235 | ||||
| -rw-r--r-- | src/libstd/rt/at_exit_imp.rs | 4 | ||||
| -rw-r--r-- | src/libstd/rt/local_ptr.rs | 2 | ||||
| -rw-r--r-- | src/libstd/rt/mod.rs | 4 | ||||
| -rw-r--r-- | src/libstd/rt/rtio.rs | 2 | ||||
| -rw-r--r-- | src/libstd/rt/task.rs | 4 | ||||
| -rw-r--r-- | src/libstd/rt/thread.rs | 12 | ||||
| -rw-r--r-- | src/libstd/slice.rs | 26 | ||||
| -rw-r--r-- | src/libstd/str.rs | 2 | ||||
| -rw-r--r-- | src/libstd/task.rs | 18 | ||||
| -rw-r--r-- | src/libstd/unstable/finally.rs | 4 | ||||
| -rw-r--r-- | src/libstd/unstable/mod.rs | 2 | ||||
| -rw-r--r-- | src/libstd/vec.rs | 1 |
20 files changed, 259 insertions, 121 deletions
diff --git a/src/libstd/c_vec.rs b/src/libstd/c_vec.rs index 3b6b914cf14..4ef5af9275c 100644 --- a/src/libstd/c_vec.rs +++ b/src/libstd/c_vec.rs @@ -46,7 +46,7 @@ use raw; pub struct CVec<T> { base: *mut T, len: uint, - dtor: Option<proc:Send()>, + dtor: Option<proc():Send>, } #[unsafe_destructor] @@ -90,7 +90,7 @@ impl<T> CVec<T> { /// * dtor - A proc to run when the value is destructed, useful /// for freeing the buffer, etc. pub unsafe fn new_with_dtor(base: *mut T, len: uint, - dtor: proc:Send()) -> CVec<T> { + dtor: proc():Send) -> CVec<T> { assert!(base != ptr::mut_null()); CVec { base: base, diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 97519adbc3f..f384000896c 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -632,28 +632,28 @@ pub trait Reader { /// Reads a little-endian unsigned integer. /// - /// The number of bytes returned is system-dependant. + /// The number of bytes returned is system-dependent. fn read_le_uint(&mut self) -> IoResult<uint> { self.read_le_uint_n(uint::BYTES).map(|i| i as uint) } /// Reads a little-endian integer. /// - /// The number of bytes returned is system-dependant. + /// The number of bytes returned is system-dependent. fn read_le_int(&mut self) -> IoResult<int> { self.read_le_int_n(int::BYTES).map(|i| i as int) } /// Reads a big-endian unsigned integer. /// - /// The number of bytes returned is system-dependant. + /// The number of bytes returned is system-dependent. fn read_be_uint(&mut self) -> IoResult<uint> { self.read_be_uint_n(uint::BYTES).map(|i| i as uint) } /// Reads a big-endian integer. /// - /// The number of bytes returned is system-dependant. + /// The number of bytes returned is system-dependent. fn read_be_int(&mut self) -> IoResult<int> { self.read_be_int_n(int::BYTES).map(|i| i as int) } diff --git a/src/libstd/io/net/unix.rs b/src/libstd/io/net/unix.rs index 0d64a7b141e..a58cdbdba44 100644 --- a/src/libstd/io/net/unix.rs +++ b/src/libstd/io/net/unix.rs @@ -141,7 +141,7 @@ mod tests { use io::*; use io::test::*; - pub fn smalltest(server: proc:Send(UnixStream), client: proc:Send(UnixStream)) { + pub fn smalltest(server: proc(UnixStream):Send, client: proc(UnixStream):Send) { let path1 = next_test_unix(); let path2 = path1.clone(); diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index ae98333ca96..33306dba8de 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -99,7 +99,15 @@ fn src<T>(fd: libc::c_int, readable: bool, f: |StdSource| -> T) -> T { /// /// See `stdout()` for more notes about this function. pub fn stdin() -> BufferedReader<StdReader> { - BufferedReader::new(stdin_raw()) + // The default buffer capacity is 64k, but apparently windows doesn't like + // 64k reads on stdin. See #13304 for details, but the idea is that on + // windows we use a slighly smaller buffer that's been seen to be + // acceptable. + if cfg!(windows) { + BufferedReader::with_capacity(8 * 1024, stdin_raw()) + } else { + BufferedReader::new(stdin_raw()) + } } /// Creates a new non-blocking handle to the stdin of the current process. diff --git a/src/libstd/iter.rs b/src/libstd/iter.rs index d7424fc9f61..1c7579e6b8e 100644 --- a/src/libstd/iter.rs +++ b/src/libstd/iter.rs @@ -156,7 +156,7 @@ pub trait Iterator<A> { /// assert!(it.next().is_none()); /// ``` #[inline] - fn map<'r, B>(self, f: 'r |A| -> B) -> Map<'r, A, B, Self> { + fn map<'r, B>(self, f: |A|: 'r -> B) -> Map<'r, A, B, Self> { Map{iter: self, f: f} } @@ -173,7 +173,7 @@ pub trait Iterator<A> { /// assert!(it.next().is_none()); /// ``` #[inline] - fn filter<'r>(self, predicate: 'r |&A| -> bool) -> Filter<'r, A, Self> { + fn filter<'r>(self, predicate: |&A|: 'r -> bool) -> Filter<'r, A, Self> { Filter{iter: self, predicate: predicate} } @@ -190,7 +190,7 @@ pub trait Iterator<A> { /// assert!(it.next().is_none()); /// ``` #[inline] - fn filter_map<'r, B>(self, f: 'r |A| -> Option<B>) -> FilterMap<'r, A, B, Self> { + fn filter_map<'r, B>(self, f: |A|: 'r -> Option<B>) -> FilterMap<'r, A, B, Self> { FilterMap { iter: self, f: f } } @@ -249,7 +249,7 @@ pub trait Iterator<A> { /// assert!(it.next().is_none()); /// ``` #[inline] - fn skip_while<'r>(self, predicate: 'r |&A| -> bool) -> SkipWhile<'r, A, Self> { + fn skip_while<'r>(self, predicate: |&A|: 'r -> bool) -> SkipWhile<'r, A, Self> { SkipWhile{iter: self, flag: false, predicate: predicate} } @@ -267,7 +267,7 @@ pub trait Iterator<A> { /// assert!(it.next().is_none()); /// ``` #[inline] - fn take_while<'r>(self, predicate: 'r |&A| -> bool) -> TakeWhile<'r, A, Self> { + fn take_while<'r>(self, predicate: |&A|: 'r -> bool) -> TakeWhile<'r, A, Self> { TakeWhile{iter: self, flag: false, predicate: predicate} } @@ -327,7 +327,7 @@ pub trait Iterator<A> { /// assert!(it.next().is_none()); /// ``` #[inline] - fn scan<'r, St, B>(self, initial_state: St, f: 'r |&mut St, A| -> Option<B>) + fn scan<'r, St, B>(self, initial_state: St, f: |&mut St, A|: 'r -> Option<B>) -> Scan<'r, A, B, Self, St> { Scan{iter: self, f: f, state: initial_state} } @@ -351,7 +351,7 @@ pub trait Iterator<A> { /// } /// ``` #[inline] - fn flat_map<'r, B, U: Iterator<B>>(self, f: 'r |A| -> U) + fn flat_map<'r, B, U: Iterator<B>>(self, f: |A|: 'r -> U) -> FlatMap<'r, A, Self, U> { FlatMap{iter: self, f: f, frontiter: None, backiter: None } } @@ -405,7 +405,7 @@ pub trait Iterator<A> { /// println!("{}", sum); /// ``` #[inline] - fn inspect<'r>(self, f: 'r |&A|) -> Inspect<'r, A, Self> { + fn inspect<'r>(self, f: |&A|: 'r) -> Inspect<'r, A, Self> { Inspect{iter: self, f: f} } @@ -1235,7 +1235,7 @@ RandomAccessIterator<(A, B)> for Zip<T, U> { /// An iterator which maps the values of `iter` with `f` pub struct Map<'a, A, B, T> { iter: T, - f: 'a |A| -> B + f: |A|: 'a -> B } impl<'a, A, B, T> Map<'a, A, B, T> { @@ -1284,7 +1284,7 @@ impl<'a, A, B, T: RandomAccessIterator<A>> RandomAccessIterator<B> for Map<'a, A /// An iterator which filters the elements of `iter` with `predicate` pub struct Filter<'a, A, T> { iter: T, - predicate: 'a |&A| -> bool + predicate: |&A|: 'a -> bool } impl<'a, A, T: Iterator<A>> Iterator<A> for Filter<'a, A, T> { @@ -1328,7 +1328,7 @@ impl<'a, A, T: DoubleEndedIterator<A>> DoubleEndedIterator<A> for Filter<'a, A, /// An iterator which uses `f` to both filter and map elements from `iter` pub struct FilterMap<'a, A, B, T> { iter: T, - f: 'a |A| -> Option<B> + f: |A|: 'a -> Option<B> } impl<'a, A, B, T: Iterator<A>> Iterator<B> for FilterMap<'a, A, B, T> { @@ -1477,7 +1477,7 @@ impl<'a, A, T: Iterator<A>> Peekable<A, T> { pub struct SkipWhile<'a, A, T> { iter: T, flag: bool, - predicate: 'a |&A| -> bool + predicate: |&A|: 'a -> bool } impl<'a, A, T: Iterator<A>> Iterator<A> for SkipWhile<'a, A, T> { @@ -1515,7 +1515,7 @@ impl<'a, A, T: Iterator<A>> Iterator<A> for SkipWhile<'a, A, T> { pub struct TakeWhile<'a, A, T> { iter: T, flag: bool, - predicate: 'a |&A| -> bool + predicate: |&A|: 'a -> bool } impl<'a, A, T: Iterator<A>> Iterator<A> for TakeWhile<'a, A, T> { @@ -1662,7 +1662,7 @@ impl<A, T: RandomAccessIterator<A>> RandomAccessIterator<A> for Take<T> { /// An iterator to maintain state while iterating another iterator pub struct Scan<'a, A, B, T, St> { iter: T, - f: 'a |&mut St, A| -> Option<B>, + f: |&mut St, A|: 'a -> Option<B>, /// The current internal state to be passed to the closure next. pub state: St, @@ -1686,7 +1686,7 @@ impl<'a, A, B, T: Iterator<A>, St> Iterator<B> for Scan<'a, A, B, T, St> { /// pub struct FlatMap<'a, A, T, U> { iter: T, - f: 'a |A| -> U, + f: |A|: 'a -> U, frontiter: Option<U>, backiter: Option<U>, } @@ -1817,7 +1817,7 @@ impl<T> Fuse<T> { /// element before yielding it. pub struct Inspect<'a, A, T> { iter: T, - f: 'a |&A| + f: |&A|: 'a } impl<'a, A, T> Inspect<'a, A, T> { @@ -1869,7 +1869,7 @@ for Inspect<'a, A, T> { /// An iterator which just modifies the contained state throughout iteration. pub struct Unfold<'a, A, St> { - f: 'a |&mut St| -> Option<A>, + f: |&mut St|: 'a -> Option<A>, /// Internal state that will be yielded on the next iteration pub state: St, } @@ -1878,7 +1878,7 @@ impl<'a, A, St> Unfold<'a, A, St> { /// Creates a new iterator with the specified closure as the "iterator /// function" and an initial state to eventually pass to the iterator #[inline] - pub fn new<'a>(initial_state: St, f: 'a |&mut St| -> Option<A>) + pub fn new<'a>(initial_state: St, f: |&mut St|: 'a -> Option<A>) -> Unfold<'a, A, St> { Unfold { f: f, diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 1a5ca76d5c0..985f8a8eb0a 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -58,7 +58,6 @@ #![no_std] #![deny(missing_doc)] -#![allow(unknown_features)] // NOTE: remove after a stage0 snap // When testing libstd, bring in libuv as the I/O backend so tests can print // things and all of the std::io tests have an I/O interface to run on top diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index 1a35252f8ca..fbb48f2ebcb 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -273,7 +273,8 @@ macro_rules! vec( let mut _temp = ::std::vec::Vec::new(); $(_temp.push($e);)* _temp - }) + }); + ($($e:expr),+,) => (vec!($($e),+)) ) diff --git a/src/libstd/ptr.rs b/src/libstd/ptr.rs index 504c613bf4c..19eee8755a0 100644 --- a/src/libstd/ptr.rs +++ b/src/libstd/ptr.rs @@ -8,7 +8,87 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//! Unsafe pointer utility functions +//! Conveniences for working with unsafe pointers, the `*T`, and `*mut T` types. +//! +//! Working with unsafe pointers in Rust is fairly uncommon, +//! and often limited to some narrow use cases: holding +//! an unsafe pointer when safe pointers are unsuitable; +//! checking for null; and converting back to safe pointers. +//! As a result, there is not yet an abundance of library code +//! for working with unsafe poniters, and in particular, +//! since pointer math is fairly uncommon in Rust, it is not +//! all that convenient. +//! +//! Use the [`null` function](fn.null.html) to create null pointers, +//! the [`is_null`](trait.RawPtr.html#tymethod.is_null) +//! and [`is_not_null`](trait.RawPtr.html#method.is_not_null) +//! methods of the [`RawPtr` trait](trait.RawPtr.html) to check for null. +//! The `RawPtr` trait is imported by the prelude, so `is_null` etc. +//! work everywhere. +//! +//! # Common ways to create unsafe pointers +//! +//! ## 1. Coerce a reference (`&T`) or mutable reference (`&mut T`). +//! +//! ``` +//! let my_num: int = 10; +//! let my_num_ptr: *int = &my_num; +//! let mut my_speed: int = 88; +//! let my_speed_ptr: *mut int = &mut my_speed; +//! ``` +//! +//! This does not take ownership of the original allocation +//! and requires no resource management later, +//! but you must not use the pointer after its lifetime. +//! +//! ## 2. Transmute an owned box (`~T`). +//! +//! The `transmute` function takes, by value, whatever it's given +//! and returns it as whatever type is requested, as long as the +//! types are the same size. Because `~T` and `*T` have the same +//! representation they can be trivially, +//! though unsafely, transformed from one type to the other. +//! +//! ``` +//! use std::cast; +//! +//! unsafe { +//! let my_num: ~int = ~10; +//! let my_num: *int = cast::transmute(my_num); +//! let my_speed: ~int = ~88; +//! let my_speed: *mut int = cast::transmute(my_speed); +//! +//! // By taking ownership of the original `~T` though +//! // we are obligated to transmute it back later to be destroyed. +//! drop(cast::transmute::<_, ~int>(my_speed)); +//! drop(cast::transmute::<_, ~int>(my_num)); +//! } +//! ``` +//! +//! Note that here the call to `drop` is for clarity - it indicates +//! that we are done with the given value and it should be destroyed. +//! +//! ## 3. Get it from C. +//! +//! ``` +//! extern crate libc; +//! +//! use std::mem; +//! +//! fn main() { +//! unsafe { +//! let my_num: *mut int = libc::malloc(mem::size_of::<int>() as libc::size_t) as *mut int; +//! if my_num.is_null() { +//! fail!("failed to allocate memory"); +//! } +//! libc::free(my_num as *mut libc::c_void); +//! } +//! } +//! ``` +//! +//! Usually you wouldn't literally use `malloc` and `free` from Rust, +//! but C APIs hand out a lot of pointers generally, so are a common source +//! of unsafe pointers in Rust. use cast; use clone::Clone; @@ -51,31 +131,97 @@ pub unsafe fn position<T>(buf: *T, f: |&T| -> bool) -> uint { } } -/// Create an unsafe null pointer +/// Create an null pointer. +/// +/// # Example +/// +/// ``` +/// use std::ptr; +/// +/// let p: *int = ptr::null(); +/// assert!(p.is_null()); +/// ``` #[inline] pub fn null<T>() -> *T { 0 as *T } -/// Create an unsafe mutable null pointer +/// Create an unsafe mutable null pointer. +/// +/// # Example +/// +/// ``` +/// use std::ptr; +/// +/// let p: *mut int = ptr::mut_null(); +/// assert!(p.is_null()); +/// ``` #[inline] pub fn mut_null<T>() -> *mut T { 0 as *mut T } -/** - * Copies data from one location to another. - * - * Copies `count` elements (not bytes) from `src` to `dst`. The source - * and destination may overlap. - */ +/// Copies data from one location to another. +/// +/// Copies `count` elements (not bytes) from `src` to `dst`. The source +/// and destination may overlap. +/// +/// `copy_memory` is semantically equivalent to C's `memmove`. +/// +/// # Example +/// +/// Efficiently create a Rust vector from an unsafe buffer: +/// +/// ``` +/// use std::ptr; +/// use std::slice; +/// +/// unsafe fn from_buf_raw<T>(ptr: *T, elts: uint) -> ~[T] { +/// let mut dst = slice::with_capacity(elts); +/// dst.set_len(elts); +/// ptr::copy_memory(dst.as_mut_ptr(), ptr, elts); +/// dst +/// } +/// ``` +/// #[inline] pub unsafe fn copy_memory<T>(dst: *mut T, src: *T, count: uint) { intrinsics::copy_memory(dst, src, count) } -/** - * Copies data from one location to another. - * - * Copies `count` elements (not bytes) from `src` to `dst`. The source - * and destination may *not* overlap. - */ +/// Copies data from one location to another. +/// +/// Copies `count` elements (not bytes) from `src` to `dst`. The source +/// and destination may *not* overlap. +/// +/// `copy_nonoverlapping_memory` is semantically equivalent to C's `memcpy`. +/// +/// # Example +/// +/// A safe swap function: +/// +/// ``` +/// use std::cast; +/// use std::mem; +/// use std::ptr; +/// +/// fn swap<T>(x: &mut T, y: &mut T) { +/// unsafe { +/// // Give ourselves some scratch space to work with +/// let mut t: T = mem::uninit(); +/// +/// // Perform the swap, `&mut` pointers never alias +/// ptr::copy_nonoverlapping_memory(&mut t, &*x, 1); +/// ptr::copy_nonoverlapping_memory(x, &*y, 1); +/// ptr::copy_nonoverlapping_memory(y, &t, 1); +/// +/// // y and t now point to the same thing, but we need to completely forget `tmp` +/// // because it's no longer relevant. +/// cast::forget(t); +/// } +/// } +/// ``` +/// +/// # Safety Note +/// +/// If the source and destination overlap then the behavior of this +/// function is undefined. #[inline] pub unsafe fn copy_nonoverlapping_memory<T>(dst: *mut T, src: *T, @@ -83,27 +229,21 @@ pub unsafe fn copy_nonoverlapping_memory<T>(dst: *mut T, intrinsics::copy_nonoverlapping_memory(dst, src, count) } -/** - * Invokes memset on the specified pointer, setting `count * size_of::<T>()` - * bytes of memory starting at `dst` to `c`. - */ +/// Invokes memset on the specified pointer, setting `count * size_of::<T>()` +/// bytes of memory starting at `dst` to `c`. #[inline] pub unsafe fn set_memory<T>(dst: *mut T, c: u8, count: uint) { intrinsics::set_memory(dst, c, count) } -/** - * Zeroes out `count * size_of::<T>` bytes of memory at `dst` - */ +/// Zeroes out `count * size_of::<T>` bytes of memory at `dst` #[inline] pub unsafe fn zero_memory<T>(dst: *mut T, count: uint) { set_memory(dst, 0, count); } -/** - * Swap the values at two mutable locations of the same type, without - * deinitialising either. They may overlap. - */ +/// Swap the values at two mutable locations of the same type, without +/// deinitialising either. They may overlap. #[inline] pub unsafe fn swap<T>(x: *mut T, y: *mut T) { // Give ourselves some scratch space to work with @@ -120,19 +260,15 @@ pub unsafe fn swap<T>(x: *mut T, y: *mut T) { cast::forget(tmp); } -/** - * Replace the value at a mutable location with a new one, returning the old - * value, without deinitialising either. - */ +/// Replace the value at a mutable location with a new one, returning the old +/// value, without deinitialising either. #[inline] pub unsafe fn replace<T>(dest: *mut T, mut src: T) -> T { mem::swap(cast::transmute(dest), &mut src); // cannot overlap src } -/** - * Reads the value from `*src` and returns it. - */ +/// Reads the value from `*src` and returns it. #[inline(always)] pub unsafe fn read<T>(src: *T) -> T { let mut tmp: T = mem::uninit(); @@ -140,10 +276,8 @@ pub unsafe fn read<T>(src: *T) -> T { tmp } -/** - * Reads the value from `*src` and nulls it out. - * This currently prevents destructors from executing. - */ +/// Reads the value from `*src` and nulls it out. +/// This currently prevents destructors from executing. #[inline(always)] pub unsafe fn read_and_zero<T>(dest: *mut T) -> T { // Copy the data out from `dest`: @@ -155,13 +289,9 @@ pub unsafe fn read_and_zero<T>(dest: *mut T) -> T { tmp } -/** - Given a **T (pointer to an array of pointers), - iterate through each *T, up to the provided `len`, - passing to the provided callback function - - SAFETY NOTE: Pointer-arithmetic. Dragons be here. -*/ +/// Given a **T (pointer to an array of pointers), +/// iterate through each *T, up to the provided `len`, +/// passing to the provided callback function pub unsafe fn array_each_with_len<T>(arr: **T, len: uint, cb: |*T|) { if arr.is_null() { fail!("ptr::array_each_with_len failure: arr input is null pointer"); @@ -173,15 +303,14 @@ pub unsafe fn array_each_with_len<T>(arr: **T, len: uint, cb: |*T|) { } } -/** - Given a null-pointer-terminated **T (pointer to - an array of pointers), iterate through each *T, - passing to the provided callback function - - SAFETY NOTE: This will only work with a null-terminated - pointer array. Barely less-dodgy Pointer Arithmetic. - Dragons be here. -*/ +/// Given a null-pointer-terminated **T (pointer to +/// an array of pointers), iterate through each *T, +/// passing to the provided callback function +/// +/// # Safety Note +/// +/// This will only work with a null-terminated +/// pointer array. pub unsafe fn array_each<T>(arr: **T, cb: |*T|) { if arr.is_null() { fail!("ptr::array_each_with_len failure: arr input is null pointer"); diff --git a/src/libstd/rt/at_exit_imp.rs b/src/libstd/rt/at_exit_imp.rs index a5bfaf190d9..4be9c8a84ac 100644 --- a/src/libstd/rt/at_exit_imp.rs +++ b/src/libstd/rt/at_exit_imp.rs @@ -21,7 +21,7 @@ use ptr::RawPtr; use unstable::sync::Exclusive; use slice::OwnedVector; -type Queue = Exclusive<~[proc:Send()]>; +type Queue = Exclusive<~[proc():Send]>; // You'll note that these variables are *not* atomic, and this is done on // purpose. This module is designed to have init() called *once* in a @@ -40,7 +40,7 @@ pub fn init() { } } -pub fn push(f: proc:Send()) { +pub fn push(f: proc():Send) { unsafe { rtassert!(!RUNNING); rtassert!(!QUEUE.is_null()); diff --git a/src/libstd/rt/local_ptr.rs b/src/libstd/rt/local_ptr.rs index e486932ac3c..e3f64f40c0d 100644 --- a/src/libstd/rt/local_ptr.rs +++ b/src/libstd/rt/local_ptr.rs @@ -12,7 +12,7 @@ //! //! The runtime will use this for storing ~Task. //! -//! XXX: Add runtime checks for usage of inconsistent pointer types. +//! FIXME: Add runtime checks for usage of inconsistent pointer types. //! and for overwriting an existing pointer. #![allow(dead_code)] diff --git a/src/libstd/rt/mod.rs b/src/libstd/rt/mod.rs index 5e2f8efd2e3..f4a4fd9ab2e 100644 --- a/src/libstd/rt/mod.rs +++ b/src/libstd/rt/mod.rs @@ -157,7 +157,7 @@ pub trait Runtime { // Miscellaneous calls which are very different depending on what context // you're in. - fn spawn_sibling(~self, cur_task: ~Task, opts: TaskOpts, f: proc:Send()); + fn spawn_sibling(~self, cur_task: ~Task, opts: TaskOpts, f: proc():Send); fn local_io<'a>(&'a mut self) -> Option<rtio::LocalIo<'a>>; /// The (low, high) edges of the current stack. fn stack_bounds(&self) -> (uint, uint); // (lo, hi) @@ -196,7 +196,7 @@ pub fn init(argc: int, argv: **u8) { /// /// It is forbidden for procedures to register more `at_exit` handlers when they /// are running, and doing so will lead to a process abort. -pub fn at_exit(f: proc:Send()) { +pub fn at_exit(f: proc():Send) { at_exit_imp::push(f); } diff --git a/src/libstd/rt/rtio.rs b/src/libstd/rt/rtio.rs index 54708d19a1b..1750e685627 100644 --- a/src/libstd/rt/rtio.rs +++ b/src/libstd/rt/rtio.rs @@ -36,7 +36,7 @@ pub trait Callback { pub trait EventLoop { fn run(&mut self); - fn callback(&mut self, arg: proc:Send()); + fn callback(&mut self, arg: proc():Send); fn pausable_idle_callback(&mut self, ~Callback:Send) -> ~PausableIdleCallback:Send; fn remote_callback(&mut self, ~Callback:Send) -> ~RemoteCallback:Send; diff --git a/src/libstd/rt/task.rs b/src/libstd/rt/task.rs index fc266df11e4..bae20d3bb9b 100644 --- a/src/libstd/rt/task.rs +++ b/src/libstd/rt/task.rs @@ -70,7 +70,7 @@ pub enum BlockedTask { pub enum DeathAction { /// Action to be done with the exit code. If set, also makes the task wait /// until all its watched children exit before collecting the status. - Execute(proc:Send(TaskResult)), + Execute(proc(TaskResult):Send), /// A channel to send the result of the task on when the task exits SendMessage(Sender<TaskResult>), } @@ -236,7 +236,7 @@ impl Task { /// Spawns a sibling to this task. The newly spawned task is configured with /// the `opts` structure and will run `f` as the body of its code. - pub fn spawn_sibling(mut ~self, opts: TaskOpts, f: proc:Send()) { + pub fn spawn_sibling(mut ~self, opts: TaskOpts, f: proc():Send) { let ops = self.imp.take_unwrap(); ops.spawn_sibling(self, opts, f) } diff --git a/src/libstd/rt/thread.rs b/src/libstd/rt/thread.rs index c35ffac064c..b1c7c5aab02 100644 --- a/src/libstd/rt/thread.rs +++ b/src/libstd/rt/thread.rs @@ -68,13 +68,13 @@ impl Thread<()> { /// to finish executing. This means that even if `join` is not explicitly /// called, when the `Thread` falls out of scope its destructor will block /// waiting for the OS thread. - pub fn start<T: Send>(main: proc:Send() -> T) -> Thread<T> { + pub fn start<T: Send>(main: proc():Send -> T) -> Thread<T> { Thread::start_stack(DEFAULT_STACK_SIZE, main) } /// Performs the same functionality as `start`, but specifies an explicit /// stack size for the new thread. - pub fn start_stack<T: Send>(stack: uint, main: proc:Send() -> T) -> Thread<T> { + pub fn start_stack<T: Send>(stack: uint, main: proc():Send -> T) -> Thread<T> { // We need the address of the packet to fill in to be stable so when // `main` fills it in it's still valid, so allocate an extra ~ box to do @@ -99,13 +99,13 @@ impl Thread<()> { /// This corresponds to creating threads in the 'detached' state on unix /// systems. Note that platforms may not keep the main program alive even if /// there are detached thread still running around. - pub fn spawn(main: proc:Send()) { + pub fn spawn(main: proc():Send) { Thread::spawn_stack(DEFAULT_STACK_SIZE, main) } /// Performs the same functionality as `spawn`, but explicitly specifies a /// stack size for the new thread. - pub fn spawn_stack(stack: uint, main: proc:Send()) { + pub fn spawn_stack(stack: uint, main: proc():Send) { unsafe { let handle = imp::create(stack, ~main); imp::detach(handle); @@ -156,7 +156,7 @@ mod imp { pub type rust_thread = HANDLE; pub type rust_thread_return = DWORD; - pub unsafe fn create(stack: uint, p: ~proc:Send()) -> rust_thread { + pub unsafe fn create(stack: uint, p: ~proc():Send) -> rust_thread { let arg: *mut libc::c_void = cast::transmute(p); // FIXME On UNIX, we guard against stack sizes that are too small but // that's because pthreads enforces that stacks are at least @@ -215,7 +215,7 @@ mod imp { pub type rust_thread = libc::pthread_t; pub type rust_thread_return = *u8; - pub unsafe fn create(stack: uint, p: ~proc:Send()) -> rust_thread { + pub unsafe fn create(stack: uint, p: ~proc():Send) -> rust_thread { let mut native: libc::pthread_t = mem::uninit(); let mut attr: libc::pthread_attr_t = mem::uninit(); assert_eq!(pthread_attr_init(&mut attr), 0); diff --git a/src/libstd/slice.rs b/src/libstd/slice.rs index f15e3e61ca1..fced9b5dd5b 100644 --- a/src/libstd/slice.rs +++ b/src/libstd/slice.rs @@ -235,7 +235,7 @@ pub fn mut_ref_slice<'a, A>(s: &'a mut A) -> &'a mut [A] { pub struct Splits<'a, T> { v: &'a [T], n: uint, - pred: 'a |t: &T| -> bool, + pred: |t: &T|: 'a -> bool, finished: bool } @@ -284,7 +284,7 @@ impl<'a, T> Iterator<&'a [T]> for Splits<'a, T> { pub struct RevSplits<'a, T> { v: &'a [T], n: uint, - pred: 'a |t: &T| -> bool, + pred: |t: &T|: 'a -> bool, finished: bool } @@ -810,23 +810,23 @@ pub trait ImmutableVector<'a, T> { /// Returns an iterator over the subslices of the vector which are /// separated by elements that match `pred`. The matched element /// is not contained in the subslices. - fn split(self, pred: 'a |&T| -> bool) -> Splits<'a, T>; + fn split(self, pred: |&T|: 'a -> bool) -> Splits<'a, T>; /// Returns an iterator over the subslices of the vector which are /// separated by elements that match `pred`, limited to splitting /// at most `n` times. The matched element is not contained in /// the subslices. - fn splitn(self, n: uint, pred: 'a |&T| -> bool) -> Splits<'a, T>; + fn splitn(self, n: uint, pred: |&T|: 'a -> bool) -> Splits<'a, T>; /// Returns an iterator over the subslices of the vector which are /// separated by elements that match `pred`. This starts at the /// end of the vector and works backwards. The matched element is /// not contained in the subslices. - fn rsplit(self, pred: 'a |&T| -> bool) -> RevSplits<'a, T>; + fn rsplit(self, pred: |&T|: 'a -> bool) -> RevSplits<'a, T>; /// Returns an iterator over the subslices of the vector which are /// separated by elements that match `pred` limited to splitting /// at most `n` times. This starts at the end of the vector and /// works backwards. The matched element is not contained in the /// subslices. - fn rsplitn(self, n: uint, pred: 'a |&T| -> bool) -> RevSplits<'a, T>; + fn rsplitn(self, n: uint, pred: |&T|: 'a -> bool) -> RevSplits<'a, T>; /** * Returns an iterator over all contiguous windows of length @@ -1003,12 +1003,12 @@ impl<'a,T> ImmutableVector<'a, T> for &'a [T] { } #[inline] - fn split(self, pred: 'a |&T| -> bool) -> Splits<'a, T> { + fn split(self, pred: |&T|: 'a -> bool) -> Splits<'a, T> { self.splitn(uint::MAX, pred) } #[inline] - fn splitn(self, n: uint, pred: 'a |&T| -> bool) -> Splits<'a, T> { + fn splitn(self, n: uint, pred: |&T|: 'a -> bool) -> Splits<'a, T> { Splits { v: self, n: n, @@ -1018,12 +1018,12 @@ impl<'a,T> ImmutableVector<'a, T> for &'a [T] { } #[inline] - fn rsplit(self, pred: 'a |&T| -> bool) -> RevSplits<'a, T> { + fn rsplit(self, pred: |&T|: 'a -> bool) -> RevSplits<'a, T> { self.rsplitn(uint::MAX, pred) } #[inline] - fn rsplitn(self, n: uint, pred: 'a |&T| -> bool) -> RevSplits<'a, T> { + fn rsplitn(self, n: uint, pred: |&T|: 'a -> bool) -> RevSplits<'a, T> { RevSplits { v: self, n: n, @@ -2027,7 +2027,7 @@ pub trait MutableVector<'a, T> { /// Returns an iterator over the mutable subslices of the vector /// which are separated by elements that match `pred`. The /// matched element is not contained in the subslices. - fn mut_split(self, pred: 'a |&T| -> bool) -> MutSplits<'a, T>; + fn mut_split(self, pred: |&T|: 'a -> bool) -> MutSplits<'a, T>; /** * Returns an iterator over `size` elements of the vector at a time. @@ -2299,7 +2299,7 @@ impl<'a,T> MutableVector<'a, T> for &'a mut [T] { } #[inline] - fn mut_split(self, pred: 'a |&T| -> bool) -> MutSplits<'a, T> { + fn mut_split(self, pred: |&T|: 'a -> bool) -> MutSplits<'a, T> { MutSplits { v: self, pred: pred, finished: false } } @@ -2736,7 +2736,7 @@ pub type RevMutItems<'a, T> = Rev<MutItems<'a, T>>; /// by elements that match `pred`. pub struct MutSplits<'a, T> { v: &'a mut [T], - pred: 'a |t: &T| -> bool, + pred: |t: &T|: 'a -> bool, finished: bool } diff --git a/src/libstd/str.rs b/src/libstd/str.rs index 1d80af70b97..e24011ca021 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -241,7 +241,7 @@ impl CharEq for char { fn only_ascii(&self) -> bool { (*self as uint) < 128 } } -impl<'a> CharEq for 'a |char| -> bool { +impl<'a> CharEq for |char|: 'a -> bool { #[inline] fn matches(&self, c: char) -> bool { (*self)(c) } diff --git a/src/libstd/task.rs b/src/libstd/task.rs index a3d919921ae..ed10f6d15cd 100644 --- a/src/libstd/task.rs +++ b/src/libstd/task.rs @@ -86,7 +86,7 @@ pub struct TaskOpts { pub struct TaskBuilder { /// Options to spawn the new task with pub opts: TaskOpts, - gen_body: Option<proc:Send(v: proc:Send()) -> proc:Send()>, + gen_body: Option<proc(v: proc():Send):Send -> proc():Send>, nocopy: Option<marker::NoCopy>, } @@ -151,7 +151,7 @@ impl TaskBuilder { * existing body generator to the new body generator. */ pub fn with_wrapper(mut self, - wrapper: proc:Send(v: proc:Send()) -> proc:Send()) + wrapper: proc(v: proc():Send):Send -> proc():Send) -> TaskBuilder { self.gen_body = match self.gen_body.take() { @@ -168,7 +168,7 @@ impl TaskBuilder { * the provided unique closure. The task has the properties and behavior * specified by the task_builder. */ - pub fn spawn(mut self, f: proc:Send()) { + pub fn spawn(mut self, f: proc():Send) { let gen_body = self.gen_body.take(); let f = match gen_body { Some(gen) => gen(f), @@ -191,7 +191,7 @@ impl TaskBuilder { * # Failure * Fails if a future_result was already set for this task. */ - pub fn try<T:Send>(mut self, f: proc:Send() -> T) -> Result<T, ~Any:Send> { + pub fn try<T:Send>(mut self, f: proc():Send -> T) -> Result<T, ~Any:Send> { let (tx, rx) = channel(); let result = self.future_result(); @@ -233,12 +233,12 @@ impl TaskOpts { /// the provided unique closure. /// /// This function is equivalent to `task().spawn(f)`. -pub fn spawn(f: proc:Send()) { +pub fn spawn(f: proc():Send) { let task = task(); task.spawn(f) } -pub fn try<T:Send>(f: proc:Send() -> T) -> Result<T, ~Any:Send> { +pub fn try<T:Send>(f: proc():Send -> T) -> Result<T, ~Any:Send> { /*! * Execute a function in another task and return either the return value * of the function or result::err. @@ -338,7 +338,7 @@ fn test_run_basic() { fn test_with_wrapper() { let (tx, rx) = channel(); task().with_wrapper(proc(body) { - let result: proc:Send() = proc() { + let result: proc():Send = proc() { body(); tx.send(()); }; @@ -424,7 +424,7 @@ fn test_spawn_sched_childs_on_default_sched() { } #[cfg(test)] -fn avoid_copying_the_body(spawnfn: |v: proc:Send()|) { +fn avoid_copying_the_body(spawnfn: |v: proc():Send|) { let (tx, rx) = channel::<uint>(); let x = ~1; @@ -470,7 +470,7 @@ fn test_child_doesnt_ref_parent() { // (well, it would if the constant were 8000+ - I lowered it to be more // valgrind-friendly. try this at home, instead..!) static generations: uint = 16; - fn child_no(x: uint) -> proc:Send() { + fn child_no(x: uint) -> proc():Send { return proc() { if x < generations { task().spawn(child_no(x+1)); diff --git a/src/libstd/unstable/finally.rs b/src/libstd/unstable/finally.rs index 6fb8981b681..82119ad21b9 100644 --- a/src/libstd/unstable/finally.rs +++ b/src/libstd/unstable/finally.rs @@ -39,7 +39,7 @@ pub trait Finally<T> { fn finally(&self, dtor: ||) -> T; } -impl<'a,T> Finally<T> for 'a || -> T { +impl<'a,T> Finally<T> for ||: 'a -> T { fn finally(&self, dtor: ||) -> T { try_finally(&mut (), (), |_, _| (*self)(), @@ -101,7 +101,7 @@ pub fn try_finally<T,U,R>(mutate: &mut T, struct Finallyalizer<'a,A> { mutate: &'a mut A, - dtor: 'a |&mut A| + dtor: |&mut A|: 'a } #[unsafe_destructor] diff --git a/src/libstd/unstable/mod.rs b/src/libstd/unstable/mod.rs index ddbf650e64a..f660d7ae97a 100644 --- a/src/libstd/unstable/mod.rs +++ b/src/libstd/unstable/mod.rs @@ -28,7 +28,7 @@ for it to terminate. The executing thread has no access to a task pointer and will be using a normal large stack. */ -pub fn run_in_bare_thread(f: proc:Send()) { +pub fn run_in_bare_thread(f: proc():Send) { use rt::thread::Thread; Thread::start(f).join() } diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 30416b28241..3c5cdfcf94e 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -1574,6 +1574,7 @@ mod tests { assert_eq!(v, three) } + #[test] fn test_grow_fn() { let mut v = Vec::from_slice([0u, 1]); v.grow_fn(3, |i| i); |
