diff options
| author | bors <bors@rust-lang.org> | 2014-12-31 21:01:42 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-12-31 21:01:42 +0000 |
| commit | 10d99a973498c5a1be6ba318210751efc1c2cf61 (patch) | |
| tree | 7f6c86aebf4ac2cf41fadaeef8d1548147ab70d9 /src/libstd | |
| parent | 84f5ad8679c7fc454473ffbf389030f3e5fee379 (diff) | |
| parent | 139f44bae82a7c74bcda9cb2b16dd2ab93f18b17 (diff) | |
| download | rust-10d99a973498c5a1be6ba318210751efc1c2cf61.tar.gz rust-10d99a973498c5a1be6ba318210751efc1c2cf61.zip | |
auto merge of #20360 : alexcrichton/rust/rollup, r=alexcrichton
Diffstat (limited to 'src/libstd')
34 files changed, 150 insertions, 390 deletions
diff --git a/src/libstd/bitflags.rs b/src/libstd/bitflags.rs index a46b8a9ad90..aeb4df402a2 100644 --- a/src/libstd/bitflags.rs +++ b/src/libstd/bitflags.rs @@ -241,17 +241,6 @@ macro_rules! bitflags { } } - // NOTE(stage0): Remove impl after a snapshot - #[cfg(stage0)] - impl Not<$BitFlags> for $BitFlags { - /// Returns the complement of this set of flags. - #[inline] - fn not(&self) -> $BitFlags { - $BitFlags { bits: !self.bits } & $BitFlags::all() - } - } - - #[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot impl Not<$BitFlags> for $BitFlags { /// Returns the complement of this set of flags. #[inline] diff --git a/src/libstd/c_str.rs b/src/libstd/c_str.rs index f28abcc10cf..4e22fc60080 100644 --- a/src/libstd/c_str.rs +++ b/src/libstd/c_str.rs @@ -74,7 +74,7 @@ use fmt; use hash; use mem; use ptr; -use slice::{mod, ImmutableIntSlice}; +use slice::{mod, IntSliceExt}; use str; use string::String; use core::kinds::marker; @@ -486,6 +486,8 @@ fn check_for_null(v: &[u8], buf: *mut libc::c_char) { /// External iterator for a CString's bytes. /// /// Use with the `std::iter` module. +#[allow(raw_pointer_deriving)] +#[deriving(Clone)] pub struct CChars<'a> { ptr: *const libc::c_char, marker: marker::ContravariantLifetime<'a>, diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 7b7473b2c99..3bfe2009f8b 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -1261,6 +1261,7 @@ impl<K: Eq + Hash<S>, V: Clone, S, H: Hasher<S>> HashMap<K, V, H> { } } +#[stable] impl<K: Eq + Hash<S>, V: PartialEq, S, H: Hasher<S>> PartialEq for HashMap<K, V, H> { fn eq(&self, other: &HashMap<K, V, H>) -> bool { if self.len() != other.len() { return false; } @@ -1271,6 +1272,7 @@ impl<K: Eq + Hash<S>, V: PartialEq, S, H: Hasher<S>> PartialEq for HashMap<K, V, } } +#[stable] impl<K: Eq + Hash<S>, V: Eq, S, H: Hasher<S>> Eq for HashMap<K, V, H> {} impl<K: Eq + Hash<S> + Show, V: Show, S, H: Hasher<S>> Show for HashMap<K, V, H> { @@ -1317,6 +1319,15 @@ pub struct Iter<'a, K: 'a, V: 'a> { inner: table::Iter<'a, K, V> } +// FIXME(#19839) Remove in favor of `#[deriving(Clone)]` +impl<'a, K, V> Clone for Iter<'a, K, V> { + fn clone(&self) -> Iter<'a, K, V> { + Iter { + inner: self.inner.clone() + } + } +} + /// HashMap mutable values iterator pub struct IterMut<'a, K: 'a, V: 'a> { inner: table::IterMut<'a, K, V> @@ -1337,11 +1348,29 @@ pub struct Keys<'a, K: 'a, V: 'a> { inner: Map<(&'a K, &'a V), &'a K, Iter<'a, K, V>, fn((&'a K, &'a V)) -> &'a K> } +// FIXME(#19839) Remove in favor of `#[deriving(Clone)]` +impl<'a, K, V> Clone for Keys<'a, K, V> { + fn clone(&self) -> Keys<'a, K, V> { + Keys { + inner: self.inner.clone() + } + } +} + /// HashMap values iterator pub struct Values<'a, K: 'a, V: 'a> { inner: Map<(&'a K, &'a V), &'a V, Iter<'a, K, V>, fn((&'a K, &'a V)) -> &'a V> } +// FIXME(#19839) Remove in favor of `#[deriving(Clone)]` +impl<'a, K, V> Clone for Values<'a, K, V> { + fn clone(&self) -> Values<'a, K, V> { + Values { + inner: self.inner.clone() + } + } +} + /// HashMap drain iterator pub struct Drain<'a, K: 'a, V: 'a> { inner: iter::Map< diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index 6d83d5510b3..93f6895f688 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -572,6 +572,7 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S>> HashSet<T, H> { } } +#[stable] impl<T: Eq + Hash<S>, S, H: Hasher<S>> PartialEq for HashSet<T, H> { fn eq(&self, other: &HashSet<T, H>) -> bool { if self.len() != other.len() { return false; } @@ -580,6 +581,7 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S>> PartialEq for HashSet<T, H> { } } +#[stable] impl<T: Eq + Hash<S>, S, H: Hasher<S>> Eq for HashSet<T, H> {} impl<T: Eq + Hash<S> + fmt::Show, S, H: Hasher<S>> fmt::Show for HashSet<T, H> { diff --git a/src/libstd/collections/hash/table.rs b/src/libstd/collections/hash/table.rs index f76b8ac3326..6938ab9b0b6 100644 --- a/src/libstd/collections/hash/table.rs +++ b/src/libstd/collections/hash/table.rs @@ -718,6 +718,18 @@ struct RawBuckets<'a, K, V> { marker: marker::ContravariantLifetime<'a>, } +// FIXME(#19839) Remove in favor of `#[deriving(Clone)]` +impl<'a, K, V> Clone for RawBuckets<'a, K, V> { + fn clone(&self) -> RawBuckets<'a, K, V> { + RawBuckets { + raw: self.raw, + hashes_end: self.hashes_end, + marker: marker::ContravariantLifetime, + } + } +} + + impl<'a, K, V> Iterator<RawBucket<K, V>> for RawBuckets<'a, K, V> { fn next(&mut self) -> Option<RawBucket<K, V>> { while self.raw.hash != self.hashes_end { @@ -775,6 +787,17 @@ pub struct Iter<'a, K: 'a, V: 'a> { elems_left: uint, } +// FIXME(#19839) Remove in favor of `#[deriving(Clone)]` +impl<'a, K, V> Clone for Iter<'a, K, V> { + fn clone(&self) -> Iter<'a, K, V> { + Iter { + iter: self.iter.clone(), + elems_left: self.elems_left + } + } +} + + /// Iterator over mutable references to entries in a table. pub struct IterMut<'a, K: 'a, V: 'a> { iter: RawBuckets<'a, K, V>, diff --git a/src/libstd/comm/sync.rs b/src/libstd/comm/sync.rs index 82ec1814ebd..a8004155af0 100644 --- a/src/libstd/comm/sync.rs +++ b/src/libstd/comm/sync.rs @@ -148,7 +148,7 @@ impl<T: Send> Packet<T> { tail: 0 as *mut Node, }, buf: Buffer { - buf: Vec::from_fn(cap + if cap == 0 {1} else {0}, |_| None), + buf: range(0, cap + if cap == 0 {1} else {0}).map(|_| None).collect(), start: 0, size: 0, }, diff --git a/src/libstd/fmt.rs b/src/libstd/fmt.rs index b75cf9a196b..957dd54a037 100644 --- a/src/libstd/fmt.rs +++ b/src/libstd/fmt.rs @@ -406,8 +406,6 @@ pub use core::fmt::{Argument, Arguments, write, radix, Radix, RadixFmt}; #[doc(hidden)] pub use core::fmt::{argument, argumentuint}; -// NOTE(stage0): Remove cfg after a snapshot -#[cfg(not(stage0))] /// The format function takes a precompiled format string and a list of /// arguments, to return the resulting formatted string. /// @@ -431,31 +429,6 @@ pub fn format(args: Arguments) -> string::String { string::String::from_utf8(output).unwrap() } -// NOTE(stage0): Remove function after a snapshot -#[cfg(stage0)] -/// The format function takes a precompiled format string and a list of -/// arguments, to return the resulting formatted string. -/// -/// # Arguments -/// -/// * args - a structure of arguments generated via the `format_args!` macro. -/// -/// # Example -/// -/// ```rust -/// use std::fmt; -/// -/// let s = format_args!(fmt::format, "Hello, {}!", "world"); -/// assert_eq!(s, "Hello, world!".to_string()); -/// ``` -#[experimental = "this is an implementation detail of format! and should not \ - be called directly"] -pub fn format(args: &Arguments) -> string::String { - let mut output = Vec::new(); - let _ = write!(&mut output as &mut Writer, "{}", args); - string::String::from_utf8(output).unwrap() -} - impl<'a> Writer for Formatter<'a> { fn write(&mut self, b: &[u8]) -> io::IoResult<()> { match (*self).write(b) { diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index fdbce101c1d..0fba0f6704b 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -439,9 +439,10 @@ mod test { impl Reader for ShortReader { fn read(&mut self, _: &mut [u8]) -> io::IoResult<uint> { - match self.lengths.remove(0) { - Some(i) => Ok(i), - None => Err(io::standard_error(io::EndOfFile)) + if self.lengths.is_empty() { + Err(io::standard_error(io::EndOfFile)) + } else { + Ok(self.lengths.remove(0)) } } } diff --git a/src/libstd/io/fs.rs b/src/libstd/io/fs.rs index caa6590bb28..e4c31ff8dd3 100644 --- a/src/libstd/io/fs.rs +++ b/src/libstd/io/fs.rs @@ -558,6 +558,7 @@ pub fn walk_dir(path: &Path) -> IoResult<Directories> { } /// An iterator that walks over a directory +#[deriving(Clone)] pub struct Directories { stack: Vec<Path>, } diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 7a25360e695..8d5b125bb08 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -1017,8 +1017,6 @@ pub trait Writer { /// decide whether their stream needs to be buffered or not. fn flush(&mut self) -> IoResult<()> { Ok(()) } - // NOTE(stage0): Remove cfg after a snapshot - #[cfg(not(stage0))] /// Writes a formatted string into this writer, returning any error /// encountered. /// @@ -1057,45 +1055,6 @@ pub trait Writer { } - // NOTE(stage0): Remove method after a snapshot - #[cfg(stage0)] - /// Writes a formatted string into this writer, returning any error - /// encountered. - /// - /// This method is primarily used to interface with the `format_args!` - /// macro, but it is rare that this should explicitly be called. The - /// `write!` macro should be favored to invoke this method instead. - /// - /// # Errors - /// - /// This function will return any I/O error reported while formatting. - fn write_fmt(&mut self, fmt: &fmt::Arguments) -> IoResult<()> { - // Create a shim which translates a Writer to a FormatWriter and saves - // off I/O errors. instead of discarding them - struct Adaptor<'a, T:'a> { - inner: &'a mut T, - error: IoResult<()>, - } - - impl<'a, T: Writer> fmt::FormatWriter for Adaptor<'a, T> { - fn write(&mut self, bytes: &[u8]) -> fmt::Result { - match self.inner.write(bytes) { - Ok(()) => Ok(()), - Err(e) => { - self.error = Err(e); - Err(fmt::Error) - } - } - } - } - - let mut output = Adaptor { inner: self, error: Ok(()) }; - match fmt::write(&mut output, fmt) { - Ok(()) => Ok(()), - Err(..) => output.error - } - } - /// Write a rust string into this sink. /// /// The bytes written will be the UTF-8 encoded version of the input string. diff --git a/src/libstd/io/net/addrinfo.rs b/src/libstd/io/net/addrinfo.rs index 69ba64d856e..e8fbb121181 100644 --- a/src/libstd/io/net/addrinfo.rs +++ b/src/libstd/io/net/addrinfo.rs @@ -10,8 +10,8 @@ //! Synchronous DNS Resolution //! -//! Contains the functionality to perform DNS resolution in a style related to -//! `getaddrinfo()` +//! Contains the functionality to perform DNS resolution or reverse lookup, +//! in a style related to `getaddrinfo()` and `getnameinfo()`, respectively. #![allow(missing_docs)] @@ -24,6 +24,7 @@ use io::{IoResult}; use io::net::ip::{SocketAddr, IpAddr}; use option::Option; use option::Option::{Some, None}; +use string::String; use sys; use vec::Vec; @@ -83,6 +84,12 @@ pub fn get_host_addresses(host: &str) -> IoResult<Vec<IpAddr>> { lookup(Some(host), None, None).map(|a| a.into_iter().map(|i| i.address.ip).collect()) } +/// Reverse name resolution. Given an address, returns the corresponding +/// hostname. +pub fn get_address_name(addr: IpAddr) -> IoResult<String> { + sys::addrinfo::get_address_name(addr) +} + /// Full-fledged resolution. This function will perform a synchronous call to /// getaddrinfo, controlled by the parameters /// diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index 6c8e4eea40f..43d2e078035 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -378,38 +378,18 @@ pub fn println(s: &str) { }) } -// NOTE(stage0): Remove cfg after a snapshot -#[cfg(not(stage0))] /// Similar to `print`, but takes a `fmt::Arguments` structure to be compatible /// with the `format_args!` macro. pub fn print_args(fmt: fmt::Arguments) { with_task_stdout(|io| write!(io, "{}", fmt)) } -// NOTE(stage0): Remove function after a snapshot -#[cfg(stage0)] -/// Similar to `print`, but takes a `fmt::Arguments` structure to be compatible -/// with the `format_args!` macro. -pub fn print_args(fmt: &fmt::Arguments) { - with_task_stdout(|io| write!(io, "{}", fmt)) -} - -// NOTE(stage0): Remove cfg after a snapshot -#[cfg(not(stage0))] /// Similar to `println`, but takes a `fmt::Arguments` structure to be /// compatible with the `format_args!` macro. pub fn println_args(fmt: fmt::Arguments) { with_task_stdout(|io| writeln!(io, "{}", fmt)) } -// NOTE(stage0): Remove function after a snapshot -#[cfg(stage0)] -/// Similar to `println`, but takes a `fmt::Arguments` structure to be -/// compatible with the `format_args!` macro. -pub fn println_args(fmt: &fmt::Arguments) { - with_task_stdout(|io| writeln!(io, "{}", fmt)) -} - /// Representation of a reader of a standard input stream pub struct StdReader { inner: StdSource diff --git a/src/libstd/io/util.rs b/src/libstd/io/util.rs index 90d7c1388a1..2a98067c970 100644 --- a/src/libstd/io/util.rs +++ b/src/libstd/io/util.rs @@ -163,6 +163,7 @@ impl Writer for MultiWriter { /// A `Reader` which chains input from multiple `Reader`s, reading each to /// completion before moving onto the next. +#[deriving(Clone)] pub struct ChainedReader<I, R> { readers: I, cur_reader: Option<R>, @@ -246,6 +247,7 @@ pub fn copy<R: Reader, W: Writer>(r: &mut R, w: &mut W) -> io::IoResult<()> { } /// An adaptor converting an `Iterator<u8>` to a `Reader`. +#[deriving(Clone)] pub struct IterReader<T> { iter: T, } diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 8274baeacfa..74c387c5eea 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -158,6 +158,7 @@ pub use alloc::rc; pub use core_collections::slice; pub use core_collections::str; pub use core_collections::string; +#[stable] pub use core_collections::vec; pub use unicode::char; diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index edb6218c5cc..ebb64bc2f2d 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -17,8 +17,6 @@ #![experimental] #![macro_escape] -// NOTE(stage0): Remove cfg after a snapshot -#[cfg(not(stage0))] /// The entry point for panic of Rust tasks. /// /// This macro is used to inject panic into a Rust task, causing the task to @@ -59,63 +57,6 @@ macro_rules! panic { }); } -// NOTE(stage0): Remove macro after a snapshot -#[cfg(stage0)] -/// The entry point for panic of Rust tasks. -/// -/// This macro is used to inject panic into a Rust task, causing the task to -/// unwind and panic entirely. Each task's panic can be reaped as the -/// `Box<Any>` type, and the single-argument form of the `panic!` macro will be -/// the value which is transmitted. -/// -/// The multi-argument form of this macro panics with a string and has the -/// `format!` syntax for building a string. -/// -/// # Example -/// -/// ```should_fail -/// # #![allow(unreachable_code)] -/// panic!(); -/// panic!("this is a terrible mistake!"); -/// panic!(4i); // panic with the value of 4 to be collected elsewhere -/// panic!("this is a {} {message}", "fancy", message = "message"); -/// ``` -#[macro_export] -macro_rules! panic { - () => ({ - panic!("explicit panic") - }); - ($msg:expr) => ({ - // static requires less code at runtime, more constant data - static _FILE_LINE: (&'static str, uint) = (file!(), line!()); - ::std::rt::begin_unwind($msg, &_FILE_LINE) - }); - ($fmt:expr, $($arg:tt)*) => ({ - // a closure can't have return type !, so we need a full - // function to pass to format_args!, *and* we need the - // file and line numbers right here; so an inner bare fn - // is our only choice. - // - // LLVM doesn't tend to inline this, presumably because begin_unwind_fmt - // is #[cold] and #[inline(never)] and because this is flagged as cold - // as returning !. We really do want this to be inlined, however, - // because it's just a tiny wrapper. Small wins (156K to 149K in size) - // were seen when forcing this to be inlined, and that number just goes - // up with the number of calls to panic!() - // - // The leading _'s are to avoid dead code warnings if this is - // used inside a dead function. Just `#[allow(dead_code)]` is - // insufficient, since the user may have - // `#[forbid(dead_code)]` and which cannot be overridden. - #[inline(always)] - fn _run_fmt(fmt: &::std::fmt::Arguments) -> ! { - static _FILE_LINE: (&'static str, uint) = (file!(), line!()); - ::std::rt::begin_unwind_fmt(fmt, &_FILE_LINE) - } - format_args!(_run_fmt, $fmt, $($arg)*) - }); -} - /// Ensure that a boolean expression is `true` at runtime. /// /// This will invoke the `panic!` macro if the provided expression cannot be @@ -289,8 +230,6 @@ macro_rules! unimplemented { () => (panic!("not yet implemented")) } -// NOTE(stage0): Remove cfg after a snapshot -#[cfg(not(stage0))] /// Use the syntax described in `std::fmt` to create a value of type `String`. /// See `std::fmt` for more information. /// @@ -307,28 +246,6 @@ macro_rules! format { ($($arg:tt)*) => (::std::fmt::format(format_args!($($arg)*))) } -// NOTE(stage0): Remove macro after a snapshot -#[cfg(stage0)] -/// Use the syntax described in `std::fmt` to create a value of type `String`. -/// See `std::fmt` for more information. -/// -/// # Example -/// -/// ``` -/// format!("test"); -/// format!("hello {}", "world!"); -/// format!("x = {}, y = {y}", 10i, y = 30i); -/// ``` -#[macro_export] -#[stable] -macro_rules! format { - ($($arg:tt)*) => ( - format_args!(::std::fmt::format, $($arg)*) - ) -} - -// NOTE(stage0): Remove cfg after a snapshot -#[cfg(not(stage0))] /// Use the `format!` syntax to write data into a buffer of type `&mut Writer`. /// See `std::fmt` for more information. /// @@ -347,29 +264,6 @@ macro_rules! write { ($dst:expr, $($arg:tt)*) => ((&mut *$dst).write_fmt(format_args!($($arg)*))) } -// NOTE(stage0): Remove macro after a snapshot -#[cfg(stage0)] -/// Use the `format!` syntax to write data into a buffer of type `&mut Writer`. -/// See `std::fmt` for more information. -/// -/// # Example -/// -/// ``` -/// # #![allow(unused_must_use)] -/// -/// let mut w = Vec::new(); -/// write!(&mut w, "test"); -/// write!(&mut w, "formatted {}", "arguments"); -/// ``` -#[macro_export] -#[stable] -macro_rules! write { - ($dst:expr, $($arg:tt)*) => ({ - let dst = &mut *$dst; - format_args!(|args| { dst.write_fmt(args) }, $($arg)*) - }) -} - /// Equivalent to the `write!` macro, except that a newline is appended after /// the message is written. #[macro_export] @@ -380,8 +274,6 @@ macro_rules! writeln { ) } -// NOTE(stage0): Remove cfg after a snapshot -#[cfg(not(stage0))] /// Equivalent to the `println!` macro except that a newline is not printed at /// the end of the message. #[macro_export] @@ -390,18 +282,6 @@ macro_rules! print { ($($arg:tt)*) => (::std::io::stdio::print_args(format_args!($($arg)*))) } -// NOTE(stage0): Remove macro after a snapshot -#[cfg(stage0)] -/// Equivalent to the `println!` macro except that a newline is not printed at -/// the end of the message. -#[macro_export] -#[stable] -macro_rules! print { - ($($arg:tt)*) => (format_args!(::std::io::stdio::print_args, $($arg)*)) -} - -// NOTE(stage0): Remove cfg after a snapshot -#[cfg(not(stage0))] /// Macro for printing to a task's stdout handle. /// /// Each task can override its stdout handle via `std::io::stdio::set_stdout`. @@ -420,26 +300,6 @@ macro_rules! println { ($($arg:tt)*) => (::std::io::stdio::println_args(format_args!($($arg)*))) } -// NOTE(stage0): Remove macro after a snapshot -#[cfg(stage0)] -/// Macro for printing to a task's stdout handle. -/// -/// Each task can override its stdout handle via `std::io::stdio::set_stdout`. -/// The syntax of this macro is the same as that used for `format!`. For more -/// information, see `std::fmt` and `std::io::stdio`. -/// -/// # Example -/// -/// ``` -/// println!("hello there!"); -/// println!("format {} arguments", "some"); -/// ``` -#[macro_export] -#[stable] -macro_rules! println { - ($($arg:tt)*) => (format_args!(::std::io::stdio::println_args, $($arg)*)) -} - /// Helper macro for unwrapping `Result` values while returning early with an /// error if the value of the expression is `Err`. For more information, see /// `std::io`. diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 989f44f7b8e..df50b7f81af 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -620,10 +620,11 @@ pub fn get_exit_status() -> int { unsafe fn load_argc_and_argv(argc: int, argv: *const *const c_char) -> Vec<Vec<u8>> { use c_str::CString; + use iter::range; - Vec::from_fn(argc as uint, |i| { + range(0, argc as uint).map(|i| { CString::new(*argv.offset(i as int), false).as_bytes_no_nul().to_vec() - }) + }).collect() } /// Returns the command line arguments @@ -715,13 +716,14 @@ fn real_args() -> Vec<String> { #[cfg(windows)] fn real_args() -> Vec<String> { use slice; + use iter::range; let mut nArgs: c_int = 0; let lpArgCount: *mut c_int = &mut nArgs; let lpCmdLine = unsafe { GetCommandLineW() }; let szArgList = unsafe { CommandLineToArgvW(lpCmdLine, lpArgCount) }; - let args = Vec::from_fn(nArgs as uint, |i| unsafe { + let args: Vec<_> = range(0, nArgs as uint).map(|i| unsafe { // Determine the length of this argument. let ptr = *szArgList.offset(i as int); let mut len = 0; @@ -732,7 +734,7 @@ fn real_args() -> Vec<String> { let buf = slice::from_raw_buf(&ptr, len); let opt_s = String::from_utf16(sys::os::truncate_utf16_at_nul(buf)); opt_s.ok().expect("CommandLineToArgvW returned invalid UTF-16") - }); + }).collect(); unsafe { LocalFree(szArgList as *mut c_void); diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index 60f147eac9b..bd4031e6230 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -22,14 +22,14 @@ use option::Option::{None, Some}; use kinds::Sized; use str::{FromStr, Str}; use str; -use slice::{CloneSliceExt, Splits, AsSlice, VectorVector, +use slice::{CloneSliceExt, Split, AsSlice, SliceConcatExt, PartialEqSliceExt, SliceExt}; use vec::Vec; use super::{BytesContainer, GenericPath, GenericPathUnsafe}; /// Iterator that yields successive components of a Path as &[u8] -pub type Components<'a> = Splits<'a, u8, fn(&u8) -> bool>; +pub type Components<'a> = Split<'a, u8, fn(&u8) -> bool>; /// Iterator that yields successive components of a Path as Option<&str> pub type StrComponents<'a> = @@ -306,7 +306,7 @@ impl GenericPath for Path { } } } - Some(Path::new(comps.connect_vec(&SEP_BYTE))) + Some(Path::new(comps.as_slice().connect(&SEP_BYTE))) } } diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index 879a96e8026..751ed4b70fb 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -25,8 +25,8 @@ use iter::{Iterator, IteratorExt, Map, repeat}; use mem; use option::Option; use option::Option::{Some, None}; -use slice::SliceExt; -use str::{SplitTerminator, FromStr, StrVector, StrExt}; +use slice::{SliceExt, SliceConcatExt}; +use str::{SplitTerminator, FromStr, StrExt}; use string::{String, ToString}; use unicode::char::UnicodeChar; use vec::Vec; diff --git a/src/libstd/prelude.rs b/src/libstd/prelude.rs index fc59f06ae6c..f016683e3d0 100644 --- a/src/libstd/prelude.rs +++ b/src/libstd/prelude.rs @@ -66,7 +66,7 @@ #[doc(no_inline)] pub use iter::{FromIterator, Extend, ExactSizeIterator}; #[doc(no_inline)] pub use iter::{Iterator, IteratorExt, DoubleEndedIterator}; #[doc(no_inline)] pub use iter::{DoubleEndedIteratorExt, CloneIteratorExt}; -#[doc(no_inline)] pub use iter::{RandomAccessIterator, IteratorCloneExt}; +#[doc(no_inline)] pub use iter::{RandomAccessIterator, IteratorCloneExt, IteratorPairExt}; #[doc(no_inline)] pub use iter::{IteratorOrdExt, MutableDoubleEndedIterator}; #[doc(no_inline)] pub use num::{ToPrimitive, FromPrimitive}; #[doc(no_inline)] pub use boxed::Box; @@ -80,10 +80,9 @@ #[doc(no_inline)] pub use core::prelude::{Tuple1, Tuple2, Tuple3, Tuple4}; #[doc(no_inline)] pub use core::prelude::{Tuple5, Tuple6, Tuple7, Tuple8}; #[doc(no_inline)] pub use core::prelude::{Tuple9, Tuple10, Tuple11, Tuple12}; -#[doc(no_inline)] pub use str::{Str, StrVector}; -#[doc(no_inline)] pub use str::StrExt; +#[doc(no_inline)] pub use str::{Str, StrExt}; #[doc(no_inline)] pub use slice::AsSlice; -#[doc(no_inline)] pub use slice::{VectorVector, PartialEqSliceExt}; +#[doc(no_inline)] pub use slice::{SliceConcatExt, PartialEqSliceExt}; #[doc(no_inline)] pub use slice::{CloneSliceExt, OrdSliceExt, SliceExt}; #[doc(no_inline)] pub use slice::{BoxedSliceExt}; #[doc(no_inline)] pub use string::{IntoString, String, ToString}; diff --git a/src/libstd/rand/os.rs b/src/libstd/rand/os.rs index 46c3a4f622a..91b6a1f0ce0 100644 --- a/src/libstd/rand/os.rs +++ b/src/libstd/rand/os.rs @@ -170,6 +170,7 @@ mod imp { extern crate libc; use io::{IoResult}; + use kinds::Sync; use mem; use os; use rand::Rng; @@ -196,6 +197,8 @@ mod imp { #[repr(C)] struct SecRandom; + unsafe impl Sync for *const SecRandom {} + #[allow(non_upper_case_globals)] static kSecRandomDefault: *const SecRandom = 0 as *const SecRandom; diff --git a/src/libstd/rt/args.rs b/src/libstd/rt/args.rs index b1f268597c7..98eff621ce0 100644 --- a/src/libstd/rt/args.rs +++ b/src/libstd/rt/args.rs @@ -95,14 +95,14 @@ mod imp { } unsafe fn load_argc_and_argv(argc: int, argv: *const *const u8) -> Vec<Vec<u8>> { - Vec::from_fn(argc as uint, |i| { + range(0, argc as uint).map(|i| { let arg = *argv.offset(i as int); let mut len = 0u; while *arg.offset(len as int) != 0 { len += 1u; } slice::from_raw_buf(&arg, len).to_vec() - }) + }).collect() } #[cfg(test)] diff --git a/src/libstd/rt/macros.rs b/src/libstd/rt/macros.rs index 095a27203f9..0f35500a04a 100644 --- a/src/libstd/rt/macros.rs +++ b/src/libstd/rt/macros.rs @@ -15,22 +15,12 @@ #![macro_escape] -// NOTE(stage0): Remove cfg after a snapshot -#[cfg(not(stage0))] macro_rules! rterrln { ($fmt:expr $($arg:tt)*) => ( { ::rt::util::dumb_print(format_args!(concat!($fmt, "\n") $($arg)*)) } ) } -// NOTE(stage0): Remove macro after a snapshot -#[cfg(stage0)] -macro_rules! rterrln { - ($fmt:expr $($arg:tt)*) => ( { - format_args!(::rt::util::dumb_print, concat!($fmt, "\n") $($arg)*) - } ) -} - // Some basic logging. Enabled by passing `--cfg rtdebug` to the libstd build. macro_rules! rtdebug { ($($arg:tt)*) => ( { @@ -50,14 +40,6 @@ macro_rules! rtassert { } ) } -// NOTE(stage0): Remove cfg after a snapshot -#[cfg(not(stage0))] macro_rules! rtabort { ($($arg:tt)*) => (::rt::util::abort(format_args!($($arg)*))) } - -// NOTE(stage0): Remove macro after a snapshot -#[cfg(stage0)] -macro_rules! rtabort { - ($($arg:tt)*) => (format_args!(::rt::util::abort, $($arg)*)) -} diff --git a/src/libstd/rt/unwind.rs b/src/libstd/rt/unwind.rs index 9b57dcc9e18..c273c52dacc 100644 --- a/src/libstd/rt/unwind.rs +++ b/src/libstd/rt/unwind.rs @@ -477,8 +477,6 @@ pub mod eabi { } } -// NOTE(stage0): Remove cfg after a snapshot -#[cfg(not(stage0))] #[cfg(not(test))] /// Entry point of panic from the libcore crate. #[lang = "panic_fmt"] @@ -487,18 +485,6 @@ pub extern fn rust_begin_unwind(msg: fmt::Arguments, begin_unwind_fmt(msg, &(file, line)) } -// NOTE(stage0): Remove function after a snapshot -#[cfg(stage0)] -#[cfg(not(test))] -/// Entry point of panic from the libcore crate. -#[lang = "panic_fmt"] -pub extern fn rust_begin_unwind(msg: &fmt::Arguments, - file: &'static str, line: uint) -> ! { - begin_unwind_fmt(msg, &(file, line)) -} - -// NOTE(stage0): Remove cfg after a snapshot -#[cfg(not(stage0))] /// The entry point for unwinding with a formatted message. /// /// This is designed to reduce the amount of code required at the call @@ -530,39 +516,6 @@ pub fn begin_unwind_fmt(msg: fmt::Arguments, file_line: &(&'static str, uint)) - begin_unwind_inner(msg, file_line) } -// NOTE(stage0): Remove function after a snapshot -#[cfg(stage0)] -/// The entry point for unwinding with a formatted message. -/// -/// This is designed to reduce the amount of code required at the call -/// site as much as possible (so that `panic!()` has as low an impact -/// on (e.g.) the inlining of other functions as possible), by moving -/// the actual formatting into this shared place. -#[inline(never)] #[cold] -pub fn begin_unwind_fmt(msg: &fmt::Arguments, file_line: &(&'static str, uint)) -> ! { - use fmt::FormatWriter; - - // We do two allocations here, unfortunately. But (a) they're - // required with the current scheme, and (b) we don't handle - // panic + OOM properly anyway (see comment in begin_unwind - // below). - - struct VecWriter<'a> { v: &'a mut Vec<u8> } - - impl<'a> fmt::FormatWriter for VecWriter<'a> { - fn write(&mut self, buf: &[u8]) -> fmt::Result { - self.v.push_all(buf); - Ok(()) - } - } - - let mut v = Vec::new(); - let _ = write!(&mut VecWriter { v: &mut v }, "{}", msg); - - let msg = box String::from_utf8_lossy(v.as_slice()).into_owned(); - begin_unwind_inner(msg, file_line) -} - /// This is the entry point of unwinding for panic!() and assert!(). #[inline(never)] #[cold] // avoid code bloat at the call sites as much as possible pub fn begin_unwind<M: Any + Send>(msg: M, file_line: &(&'static str, uint)) -> ! { diff --git a/src/libstd/rt/util.rs b/src/libstd/rt/util.rs index 6b007056a51..5448af3f753 100644 --- a/src/libstd/rt/util.rs +++ b/src/libstd/rt/util.rs @@ -112,25 +112,11 @@ impl fmt::FormatWriter for Stdio { } } -// NOTE(stage0): Remove cfg after a snapshot -#[cfg(not(stage0))] pub fn dumb_print(args: fmt::Arguments) { let _ = Stderr.write_fmt(args); } -// NOTE(stage0): Remove function after a snapshot -#[cfg(stage0)] -pub fn dumb_print(args: &fmt::Arguments) { - let mut w = Stderr; - let _ = write!(&mut w, "{}", args); -} - -// NOTE(stage0): Remove wrappers after a snapshot -#[cfg(not(stage0))] pub fn abort(args: fmt::Arguments) -> ! { abort_(&args) } -#[cfg(stage0)] pub fn abort(args: &fmt::Arguments) -> ! { abort_(args) } - -// NOTE(stage0): Change to `pub fn abort(args: fmt::Arguments) -> !` after a snapshot -fn abort_(args: &fmt::Arguments) -> ! { +pub fn abort(args: fmt::Arguments) -> ! { use fmt::FormatWriter; struct BufWriter<'a> { diff --git a/src/libstd/sync/atomic.rs b/src/libstd/sync/atomic.rs index bdf947438f3..18c917aca8a 100644 --- a/src/libstd/sync/atomic.rs +++ b/src/libstd/sync/atomic.rs @@ -101,9 +101,9 @@ use core::mem; use core::prelude::{Send, Drop, None, Option, Some}; pub use core::atomic::{AtomicBool, AtomicInt, AtomicUint, AtomicPtr}; -pub use core::atomic::{Ordering, Relaxed, Release, Acquire, AcqRel, SeqCst}; pub use core::atomic::{INIT_ATOMIC_BOOL, INIT_ATOMIC_INT, INIT_ATOMIC_UINT}; pub use core::atomic::fence; +pub use core::atomic::Ordering::{mod, Relaxed, Release, Acquire, AcqRel, SeqCst}; /// An atomic, nullable unique pointer /// diff --git a/src/libstd/sys/common/net.rs b/src/libstd/sys/common/net.rs index 7a09137a225..87ec20fbef8 100644 --- a/src/libstd/sys/common/net.rs +++ b/src/libstd/sys/common/net.rs @@ -13,6 +13,7 @@ use self::InAddr::*; use alloc::arc::Arc; use libc::{mod, c_char, c_int}; +use c_str::CString; use mem; use num::Int; use ptr::{mod, null, null_mut}; @@ -291,6 +292,43 @@ pub fn get_host_addresses(host: Option<&str>, servname: Option<&str>, } //////////////////////////////////////////////////////////////////////////////// +// get_address_name +//////////////////////////////////////////////////////////////////////////////// + +extern "system" { + fn getnameinfo(sa: *const libc::sockaddr, salen: libc::socklen_t, + host: *mut c_char, hostlen: libc::size_t, + serv: *mut c_char, servlen: libc::size_t, + flags: c_int) -> c_int; +} + +const NI_MAXHOST: uint = 1025; + +pub fn get_address_name(addr: IpAddr) -> Result<String, IoError> { + let addr = SocketAddr{ip: addr, port: 0}; + + let mut storage: libc::sockaddr_storage = unsafe { mem::zeroed() }; + let len = addr_to_sockaddr(addr, &mut storage); + + let mut hostbuf = [0 as c_char, ..NI_MAXHOST]; + + let res = unsafe { + getnameinfo(&storage as *const _ as *const libc::sockaddr, len, + hostbuf.as_mut_ptr(), NI_MAXHOST as libc::size_t, + ptr::null_mut(), 0, + 0) + }; + + if res != 0 { + return Err(last_gai_error(res)); + } + + unsafe { + Ok(CString::new(hostbuf.as_ptr(), false).as_str().unwrap().to_string()) + } +} + +//////////////////////////////////////////////////////////////////////////////// // Timeout helpers // // The read/write functions below are the helpers for reading/writing a socket diff --git a/src/libstd/sys/unix/c.rs b/src/libstd/sys/unix/c.rs index a4ebcbd25d0..208dc60e405 100644 --- a/src/libstd/sys/unix/c.rs +++ b/src/libstd/sys/unix/c.rs @@ -214,8 +214,8 @@ mod signal { sa_resv: [libc::c_int, ..1], } - impl ::kinds::Send for sigaction { } - impl ::kinds::Sync for sigaction { } + unsafe impl ::kinds::Send for sigaction { } + unsafe impl ::kinds::Sync for sigaction { } #[repr(C)] pub struct sigset_t { diff --git a/src/libstd/sys/unix/mod.rs b/src/libstd/sys/unix/mod.rs index 4b7ac8ff4d3..c82dacf1e44 100644 --- a/src/libstd/sys/unix/mod.rs +++ b/src/libstd/sys/unix/mod.rs @@ -56,6 +56,7 @@ pub mod udp; pub mod addrinfo { pub use sys_common::net::get_host_addresses; + pub use sys_common::net::get_address_name; } // FIXME: move these to c module diff --git a/src/libstd/sys/unix/timer.rs b/src/libstd/sys/unix/timer.rs index fe393b81e3d..c0ef89666c0 100644 --- a/src/libstd/sys/unix/timer.rs +++ b/src/libstd/sys/unix/timer.rs @@ -120,9 +120,9 @@ fn helper(input: libc::c_int, messages: Receiver<Req>, _: ()) { // signals the first requests in the queue, possible re-enqueueing it. fn signal(active: &mut Vec<Box<Inner>>, dead: &mut Vec<(uint, Box<Inner>)>) { - let mut timer = match active.remove(0) { - Some(timer) => timer, None => return - }; + if active.is_empty() { return } + + let mut timer = active.remove(0); let mut cb = timer.cb.take().unwrap(); cb.call(); if timer.repeat { @@ -178,7 +178,7 @@ fn helper(input: libc::c_int, messages: Receiver<Req>, _: ()) { Ok(RemoveTimer(id, ack)) => { match dead.iter().position(|&(i, _)| id == i) { Some(i) => { - let (_, i) = dead.remove(i).unwrap(); + let (_, i) = dead.remove(i); ack.send(i); continue } @@ -186,7 +186,7 @@ fn helper(input: libc::c_int, messages: Receiver<Req>, _: ()) { } let i = active.iter().position(|i| i.id == id); let i = i.expect("no timer found"); - let t = active.remove(i).unwrap(); + let t = active.remove(i); ack.send(t); } Err(..) => break diff --git a/src/libstd/sys/windows/mod.rs b/src/libstd/sys/windows/mod.rs index aee98e22836..57c284ed6a3 100644 --- a/src/libstd/sys/windows/mod.rs +++ b/src/libstd/sys/windows/mod.rs @@ -57,6 +57,7 @@ pub mod udp; pub mod addrinfo { pub use sys_common::net::get_host_addresses; + pub use sys_common::net::get_address_name; } // FIXME: move these to c module diff --git a/src/libstd/sys/windows/os.rs b/src/libstd/sys/windows/os.rs index fa08290a888..e7194df7ac3 100644 --- a/src/libstd/sys/windows/os.rs +++ b/src/libstd/sys/windows/os.rs @@ -17,14 +17,14 @@ use prelude::*; use fmt; use io::{IoResult, IoError}; -use libc::{c_int, c_char, c_void}; +use iter::repeat; +use libc::{c_int, c_void}; use libc; use os; use path::BytesContainer; use ptr; -use sync::atomic::{AtomicInt, INIT_ATOMIC_INT, SeqCst}; -use sys::fs::FileDesc; use slice; +use sys::fs::FileDesc; use os::TMPBUF_SZ; use libc::types::os::arch::extra::DWORD; @@ -130,7 +130,7 @@ pub fn fill_utf16_buf_and_decode(f: |*mut u16, DWORD| -> DWORD) -> Option<String let mut res = None; let mut done = false; while !done { - let mut buf = Vec::from_elem(n as uint, 0u16); + let mut buf: Vec<u16> = repeat(0u16).take(n as uint).collect(); let k = f(buf.as_mut_ptr(), n); if k == (0 as DWORD) { done = true; diff --git a/src/libstd/sys/windows/tty.rs b/src/libstd/sys/windows/tty.rs index 99292b3b44b..a88d11eed22 100644 --- a/src/libstd/sys/windows/tty.rs +++ b/src/libstd/sys/windows/tty.rs @@ -34,6 +34,7 @@ use libc::{c_int, HANDLE, LPDWORD, DWORD, LPVOID}; use libc::{get_osfhandle, CloseHandle}; use libc::types::os::arch::extra::LPCVOID; use io::{mod, IoError, IoResult, MemReader}; +use iter::repeat; use prelude::*; use ptr; use str::from_utf8; @@ -89,7 +90,7 @@ impl TTY { pub fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> { // Read more if the buffer is empty if self.utf8.eof() { - let mut utf16 = Vec::from_elem(0x1000, 0u16); + let mut utf16: Vec<u16> = repeat(0u16).take(0x1000).collect(); let mut num: DWORD = 0; match unsafe { ReadConsoleW(self.handle, utf16.as_mut_ptr() as LPVOID, diff --git a/src/libstd/thread_local/mod.rs b/src/libstd/thread_local/mod.rs index 4cfa2709352..14dd2a1ac9b 100644 --- a/src/libstd/thread_local/mod.rs +++ b/src/libstd/thread_local/mod.rs @@ -189,22 +189,7 @@ macro_rules! __thread_local_inner { } }; - #[cfg(all(stage0, not(any(target_os = "macos", target_os = "linux"))))] - const INIT: ::std::thread_local::KeyInner<$t> = { - unsafe extern fn __destroy(ptr: *mut u8) { - ::std::thread_local::destroy_value::<$t>(ptr); - } - - ::std::thread_local::KeyInner { - inner: ::std::cell::UnsafeCell { value: $init }, - os: ::std::thread_local::OsStaticKey { - inner: ::std::thread_local::OS_INIT_INNER, - dtor: ::std::option::Option::Some(__destroy), - }, - } - }; - - #[cfg(all(not(stage0), not(any(target_os = "macos", target_os = "linux"))))] + #[cfg(all(not(any(target_os = "macos", target_os = "linux"))))] const INIT: ::std::thread_local::KeyInner<$t> = { unsafe extern fn __destroy(ptr: *mut u8) { ::std::thread_local::destroy_value::<$t>(ptr); @@ -346,16 +331,10 @@ mod imp { // *should* be the case that this loop always terminates because we // provide the guarantee that a TLS key cannot be set after it is // flagged for destruction. - #[cfg(not(stage0))] static DTORS: os::StaticKey = os::StaticKey { inner: os::INIT_INNER, dtor: Some(run_dtors as unsafe extern "C" fn(*mut u8)), }; - #[cfg(stage0)] - static DTORS: os::StaticKey = os::StaticKey { - inner: os::INIT_INNER, - dtor: Some(run_dtors), - }; type List = Vec<(*mut u8, unsafe extern fn(*mut u8))>; if DTORS.get().is_null() { let v: Box<List> = box Vec::new(); diff --git a/src/libstd/time/duration.rs b/src/libstd/time/duration.rs index f7351c9580f..51564b53976 100644 --- a/src/libstd/time/duration.rs +++ b/src/libstd/time/duration.rs @@ -262,20 +262,6 @@ impl Duration { } } -// NOTE(stage0): Remove impl after a snapshot -#[cfg(stage0)] -impl Neg<Duration> for Duration { - #[inline] - fn neg(&self) -> Duration { - if self.nanos == 0 { - Duration { secs: -self.secs, nanos: 0 } - } else { - Duration { secs: -self.secs - 1, nanos: NANOS_PER_SEC - self.nanos } - } - } -} - -#[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot impl Neg<Duration> for Duration { #[inline] fn neg(self) -> Duration { |
