diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-07-02 11:08:21 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-07-02 11:08:21 -0700 |
| commit | ff1dd44b40a7243f43a8d32ba8bd6026197c320b (patch) | |
| tree | 4460cbf0a917a289d1d3744d9645c5ab131ea9df /src/libstd | |
| parent | aa1163b92de7717eb7c5eba002b4012e0574a7fe (diff) | |
| parent | ca2778ede7c21efc3cf2e4e1152875ec09360770 (diff) | |
| download | rust-ff1dd44b40a7243f43a8d32ba8bd6026197c320b.tar.gz rust-ff1dd44b40a7243f43a8d32ba8bd6026197c320b.zip | |
Merge remote-tracking branch 'origin/master' into 0.11.0-release
Conflicts: src/libstd/lib.rs
Diffstat (limited to 'src/libstd')
39 files changed, 456 insertions, 217 deletions
diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index 2730d90f05f..fae1b933210 100644 --- a/src/libstd/ascii.rs +++ b/src/libstd/ascii.rs @@ -10,6 +10,8 @@ //! Operations on ASCII strings and characters +#![experimental] + use collections::Collection; use fmt; use iter::Iterator; diff --git a/src/libstd/bitflags.rs b/src/libstd/bitflags.rs index 7d821983075..834d461f20b 100644 --- a/src/libstd/bitflags.rs +++ b/src/libstd/bitflags.rs @@ -105,6 +105,7 @@ //! - `insert`: inserts the specified flags in-place //! - `remove`: removes the specified flags in-place +#![experimental] #![macro_escape] #[macro_export] diff --git a/src/libstd/c_vec.rs b/src/libstd/c_vec.rs index e8a158ad230..a7d697c8665 100644 --- a/src/libstd/c_vec.rs +++ b/src/libstd/c_vec.rs @@ -33,6 +33,8 @@ //! handled correctly, i.e. that allocated memory is eventually freed //! if necessary. +#![experimental] + use collections::Collection; use kinds::Send; use mem; @@ -102,14 +104,14 @@ impl<T> CVec<T> { /// View the stored data as a slice. pub fn as_slice<'a>(&'a self) -> &'a [T] { unsafe { - mem::transmute(raw::Slice { data: self.base as *T, len: self.len }) + mem::transmute(raw::Slice { data: self.base as *const T, len: self.len }) } } /// View the stored data as a mutable slice. pub fn as_mut_slice<'a>(&'a mut self) -> &'a mut [T] { unsafe { - mem::transmute(raw::Slice { data: self.base as *T, len: self.len }) + mem::transmute(raw::Slice { data: self.base as *const T, len: self.len }) } } diff --git a/src/libstd/collections/hashmap.rs b/src/libstd/collections/hashmap.rs index d06d4ea7177..7c01a0342ed 100644 --- a/src/libstd/collections/hashmap.rs +++ b/src/libstd/collections/hashmap.rs @@ -16,15 +16,13 @@ use collections::{Collection, Mutable, Set, MutableSet, Map, MutableMap}; use default::Default; use fmt::Show; use fmt; -use hash::{Hash, Hasher, sip}; +use hash::{Hash, Hasher, RandomSipHasher}; use iter::{Iterator, FilterMap, Chain, Repeat, Zip, Extendable}; use iter::{range, range_inclusive, FromIterator}; use iter; use mem::replace; use num; use option::{Some, None, Option}; -use rand::Rng; -use rand; use result::{Ok, Err}; mod table { @@ -361,8 +359,8 @@ mod table { *self.hashes.offset(idx) = EMPTY_BUCKET; // Drop the mutable constraint. - let keys = self.keys as *K; - let vals = self.vals as *V; + let keys = self.keys as *const K; + let vals = self.vals as *const V; let k = ptr::read(keys.offset(idx)); let v = ptr::read(vals.offset(idx)); @@ -733,7 +731,7 @@ impl DefaultResizePolicy { /// } /// ``` #[deriving(Clone)] -pub struct HashMap<K, V, H = sip::SipHasher> { +pub struct HashMap<K, V, H = RandomSipHasher> { // All hashes are keyed on these values, to prevent hash collision attacks. hasher: H, @@ -1033,18 +1031,17 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> MutableMap<K, V> for HashMap<K, V, H> } -impl<K: Hash + Eq, V> HashMap<K, V, sip::SipHasher> { +impl<K: Hash + Eq, V> HashMap<K, V, RandomSipHasher> { /// Create an empty HashMap. - pub fn new() -> HashMap<K, V, sip::SipHasher> { + #[inline] + pub fn new() -> HashMap<K, V, RandomSipHasher> { HashMap::with_capacity(INITIAL_CAPACITY) } /// Creates an empty hash map with the given initial capacity. - pub fn with_capacity(capacity: uint) -> HashMap<K, V, sip::SipHasher> { - let mut r = rand::task_rng(); - let r0 = r.gen(); - let r1 = r.gen(); - let hasher = sip::SipHasher::new_with_keys(r0, r1); + #[inline] + pub fn with_capacity(capacity: uint) -> HashMap<K, V, RandomSipHasher> { + let hasher = RandomSipHasher::new(); HashMap::with_capacity_and_hasher(capacity, hasher) } } @@ -1053,6 +1050,7 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> { /// Creates an empty hashmap which will use the given hasher to hash keys. /// /// The creates map has the default initial capacity. + #[inline] pub fn with_hasher(hasher: H) -> HashMap<K, V, H> { HashMap::with_capacity_and_hasher(INITIAL_CAPACITY, hasher) } @@ -1064,6 +1062,7 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> { /// is designed to allow HashMaps to be resistant to attacks that /// cause many collisions and very poor performance. Setting it /// manually using this function can expose a DoS attack vector. + #[inline] pub fn with_capacity_and_hasher(capacity: uint, hasher: H) -> HashMap<K, V, H> { let cap = num::next_power_of_two(max(INITIAL_CAPACITY, capacity)); HashMap { @@ -1489,7 +1488,7 @@ pub type SetMoveItems<K> = /// HashMap where the value is (). As with the `HashMap` type, a `HashSet` /// requires that the elements implement the `Eq` and `Hash` traits. #[deriving(Clone)] -pub struct HashSet<T, H = sip::SipHasher> { +pub struct HashSet<T, H = RandomSipHasher> { map: HashMap<T, (), H> } @@ -1529,15 +1528,17 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S>> MutableSet<T> for HashSet<T, H> { fn remove(&mut self, value: &T) -> bool { self.map.remove(value) } } -impl<T: Hash + Eq> HashSet<T, sip::SipHasher> { +impl<T: Hash + Eq> HashSet<T, RandomSipHasher> { /// Create an empty HashSet - pub fn new() -> HashSet<T, sip::SipHasher> { + #[inline] + pub fn new() -> HashSet<T, RandomSipHasher> { HashSet::with_capacity(INITIAL_CAPACITY) } /// Create an empty HashSet with space for at least `n` elements in /// the hash table. - pub fn with_capacity(capacity: uint) -> HashSet<T, sip::SipHasher> { + #[inline] + pub fn with_capacity(capacity: uint) -> HashSet<T, RandomSipHasher> { HashSet { map: HashMap::with_capacity(capacity) } } } @@ -1547,6 +1548,7 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S>> HashSet<T, H> { /// keys. /// /// The hash set is also created with the default initial capacity. + #[inline] pub fn with_hasher(hasher: H) -> HashSet<T, H> { HashSet::with_capacity_and_hasher(INITIAL_CAPACITY, hasher) } @@ -1558,6 +1560,7 @@ impl<T: Eq + Hash<S>, S, H: Hasher<S>> HashSet<T, H> { /// is designed to allow `HashSet`s to be resistant to attacks that /// cause many collisions and very poor performance. Setting it /// manually using this function can expose a DoS attack vector. + #[inline] pub fn with_capacity_and_hasher(capacity: uint, hasher: H) -> HashSet<T, H> { HashSet { map: HashMap::with_capacity_and_hasher(capacity, hasher) } } diff --git a/src/libstd/collections/lru_cache.rs b/src/libstd/collections/lru_cache.rs index 8ec5146c7b2..08f11581e83 100644 --- a/src/libstd/collections/lru_cache.rs +++ b/src/libstd/collections/lru_cache.rs @@ -49,7 +49,7 @@ use owned::Box; use ptr; use result::{Ok, Err}; -struct KeyRef<K> { k: *K } +struct KeyRef<K> { k: *const K } struct LruEntry<K, V> { next: *mut LruEntry<K, V>, diff --git a/src/libstd/collections/mod.rs b/src/libstd/collections/mod.rs index 9e5288f9541..ccef1c0fd2a 100644 --- a/src/libstd/collections/mod.rs +++ b/src/libstd/collections/mod.rs @@ -12,6 +12,8 @@ * Collection types. */ +#![experimental] + pub use core_collections::{Collection, Mutable, Map, MutableMap}; pub use core_collections::{Set, MutableSet, Deque}; pub use core_collections::{Bitv, BitvSet, BTree, DList, EnumSet}; diff --git a/src/libstd/dynamic_lib.rs b/src/libstd/dynamic_lib.rs index 79e01c8b966..728875ce260 100644 --- a/src/libstd/dynamic_lib.rs +++ b/src/libstd/dynamic_lib.rs @@ -33,7 +33,7 @@ use str; use string::String; use vec::Vec; -pub struct DynamicLibrary { handle: *u8} +pub struct DynamicLibrary { handle: *mut u8 } impl Drop for DynamicLibrary { fn drop(&mut self) { @@ -134,7 +134,7 @@ impl DynamicLibrary { } /// Access the value at the symbol of the dynamic library - pub unsafe fn symbol<T>(&self, symbol: &str) -> Result<*T, String> { + pub unsafe fn symbol<T>(&self, symbol: &str) -> Result<*mut T, String> { // This function should have a lifetime constraint of 'a on // T but that feature is still unimplemented @@ -175,7 +175,7 @@ mod test { let cosine: extern fn(libc::c_double) -> libc::c_double = unsafe { match libm.symbol("cos") { Err(error) => fail!("Could not load function cos: {}", error), - Ok(cosine) => mem::transmute::<*u8, _>(cosine) + Ok(cosine) => mem::transmute::<*mut u8, _>(cosine) } }; @@ -218,14 +218,14 @@ pub mod dl { use str::StrAllocating; use string::String; - pub unsafe fn open_external<T: ToCStr>(filename: T) -> *u8 { + pub unsafe fn open_external<T: ToCStr>(filename: T) -> *mut u8 { filename.with_c_str(|raw_name| { - dlopen(raw_name, Lazy as libc::c_int) as *u8 + dlopen(raw_name, Lazy as libc::c_int) as *mut u8 }) } - pub unsafe fn open_internal() -> *u8 { - dlopen(ptr::null(), Lazy as libc::c_int) as *u8 + pub unsafe fn open_internal() -> *mut u8 { + dlopen(ptr::null(), Lazy as libc::c_int) as *mut u8 } pub fn check_for_errors_in<T>(f: || -> T) -> Result<T, String> { @@ -239,7 +239,7 @@ pub mod dl { let result = f(); - let last_error = dlerror(); + let last_error = dlerror() as *const _; let ret = if ptr::null() == last_error { Ok(result) } else { @@ -252,11 +252,12 @@ pub mod dl { } } - pub unsafe fn symbol(handle: *u8, symbol: *libc::c_char) -> *u8 { - dlsym(handle as *libc::c_void, symbol) as *u8 + pub unsafe fn symbol(handle: *mut u8, + symbol: *const libc::c_char) -> *mut u8 { + dlsym(handle as *mut libc::c_void, symbol) as *mut u8 } - pub unsafe fn close(handle: *u8) { - dlclose(handle as *libc::c_void); () + pub unsafe fn close(handle: *mut u8) { + dlclose(handle as *mut libc::c_void); () } pub enum RTLD { @@ -268,36 +269,41 @@ pub mod dl { #[link_name = "dl"] extern { - fn dlopen(filename: *libc::c_char, flag: libc::c_int) -> *libc::c_void; - fn dlerror() -> *libc::c_char; - fn dlsym(handle: *libc::c_void, symbol: *libc::c_char) -> *libc::c_void; - fn dlclose(handle: *libc::c_void) -> libc::c_int; + fn dlopen(filename: *const libc::c_char, + flag: libc::c_int) -> *mut libc::c_void; + fn dlerror() -> *mut libc::c_char; + fn dlsym(handle: *mut libc::c_void, + symbol: *const libc::c_char) -> *mut libc::c_void; + fn dlclose(handle: *mut libc::c_void) -> libc::c_int; } } #[cfg(target_os = "win32")] pub mod dl { use c_str::ToCStr; + use iter::Iterator; use libc; use os; use ptr; use result::{Ok, Err, Result}; - use str::StrAllocating; + use str::StrSlice; use str; use string::String; + use vec::Vec; - pub unsafe fn open_external<T: ToCStr>(filename: T) -> *u8 { + pub unsafe fn open_external<T: ToCStr>(filename: T) -> *mut u8 { // Windows expects Unicode data let filename_cstr = filename.to_c_str(); let filename_str = str::from_utf8(filename_cstr.as_bytes_no_nul()).unwrap(); - let filename_str = filename_str.to_utf16().append_one(0); - LoadLibraryW(filename_str.as_ptr() as *libc::c_void) as *u8 + let filename_str: Vec<u16> = filename_str.utf16_units().collect(); + let filename_str = filename_str.append_one(0); + LoadLibraryW(filename_str.as_ptr() as *const libc::c_void) as *mut u8 } - pub unsafe fn open_internal() -> *u8 { - let handle = ptr::null(); - GetModuleHandleExW(0 as libc::DWORD, ptr::null(), &handle as **libc::c_void); - handle as *u8 + pub unsafe fn open_internal() -> *mut u8 { + let mut handle = ptr::mut_null(); + GetModuleHandleExW(0 as libc::DWORD, ptr::null(), &mut handle); + handle as *mut u8 } pub fn check_for_errors_in<T>(f: || -> T) -> Result<T, String> { @@ -315,20 +321,22 @@ pub mod dl { } } - pub unsafe fn symbol(handle: *u8, symbol: *libc::c_char) -> *u8 { - GetProcAddress(handle as *libc::c_void, symbol) as *u8 + pub unsafe fn symbol(handle: *mut u8, symbol: *const libc::c_char) -> *mut u8 { + GetProcAddress(handle as *mut libc::c_void, symbol) as *mut u8 } - pub unsafe fn close(handle: *u8) { - FreeLibrary(handle as *libc::c_void); () + pub unsafe fn close(handle: *mut u8) { + FreeLibrary(handle as *mut libc::c_void); () } #[allow(non_snake_case_functions)] extern "system" { fn SetLastError(error: libc::size_t); - fn LoadLibraryW(name: *libc::c_void) -> *libc::c_void; - fn GetModuleHandleExW(dwFlags: libc::DWORD, name: *u16, - handle: **libc::c_void) -> *libc::c_void; - fn GetProcAddress(handle: *libc::c_void, name: *libc::c_char) -> *libc::c_void; - fn FreeLibrary(handle: *libc::c_void); + fn LoadLibraryW(name: *const libc::c_void) -> *mut libc::c_void; + fn GetModuleHandleExW(dwFlags: libc::DWORD, name: *const u16, + handle: *mut *mut libc::c_void) + -> *mut libc::c_void; + fn GetProcAddress(handle: *mut libc::c_void, + name: *const libc::c_char) -> *mut libc::c_void; + fn FreeLibrary(handle: *mut libc::c_void); } } diff --git a/src/libstd/failure.rs b/src/libstd/failure.rs index d1552f0bd10..47ff85e2806 100644 --- a/src/libstd/failure.rs +++ b/src/libstd/failure.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![experimental] + use alloc::owned::Box; use any::{Any, AnyRefExt}; use fmt; diff --git a/src/libstd/fmt.rs b/src/libstd/fmt.rs index ef0c59268c3..5834e576b08 100644 --- a/src/libstd/fmt.rs +++ b/src/libstd/fmt.rs @@ -412,6 +412,8 @@ the `}` character is escaped with `}}`. */ +#![experimental] + use io::Writer; use io; use result::{Ok, Err}; diff --git a/src/libstd/from_str.rs b/src/libstd/from_str.rs index 642bec48b83..1ca72bca20b 100644 --- a/src/libstd/from_str.rs +++ b/src/libstd/from_str.rs @@ -10,6 +10,8 @@ //! The `FromStr` trait for types that can be created from strings +#![experimental] + use option::{Option, Some, None}; use string::String; use str::StrAllocating; diff --git a/src/libstd/gc.rs b/src/libstd/gc.rs index 0f30e7231b1..47b7426633c 100644 --- a/src/libstd/gc.rs +++ b/src/libstd/gc.rs @@ -16,6 +16,7 @@ collector is task-local so `Gc<T>` is not sendable. */ +#![experimental] #![allow(experimental)] use clone::Clone; @@ -24,6 +25,7 @@ use default::Default; use fmt; use hash; use kinds::marker; +use option::Option; use ops::Deref; use raw; @@ -33,7 +35,7 @@ use raw; task annihilation. For now, cycles need to be broken manually by using `Rc<T>` \ with a non-owning `Weak<T>` pointer. A tracing garbage collector is planned."] pub struct Gc<T> { - _ptr: *T, + _ptr: *mut T, marker: marker::NoSend, } @@ -59,6 +61,10 @@ impl<T: PartialEq + 'static> PartialEq for Gc<T> { } impl<T: PartialOrd + 'static> PartialOrd for Gc<T> { #[inline] + fn partial_cmp(&self, other: &Gc<T>) -> Option<Ordering> { + (**self).partial_cmp(&**other) + } + #[inline] fn lt(&self, other: &Gc<T>) -> bool { *(*self) < *(*other) } #[inline] fn le(&self, other: &Gc<T>) -> bool { *(*self) <= *(*other) } @@ -83,7 +89,7 @@ impl<T: Default + 'static> Default for Gc<T> { } } -impl<T: 'static> raw::Repr<*raw::Box<T>> for Gc<T> {} +impl<T: 'static> raw::Repr<*const raw::Box<T>> for Gc<T> {} impl<S: hash::Writer, T: hash::Hash<S> + 'static> hash::Hash<S> for Gc<T> { fn hash(&self, s: &mut S) { @@ -104,6 +110,13 @@ mod tests { use cell::RefCell; #[test] + fn test_managed_clone() { + let a = box(GC) 5i; + let b: Gc<int> = a.clone(); + assert!(a == b); + } + + #[test] fn test_clone() { let x = Gc::new(RefCell::new(5)); let y = x.clone(); diff --git a/src/libstd/hash.rs b/src/libstd/hash.rs new file mode 100644 index 00000000000..2cc7e70747a --- /dev/null +++ b/src/libstd/hash.rs @@ -0,0 +1,102 @@ +// Copyright 2014 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. + +/*! + * Generic hashing support. + * + * This module provides a generic way to compute the hash of a value. The + * simplest way to make a type hashable is to use `#[deriving(Hash)]`: + * + * # Example + * + * ```rust + * use std::hash; + * use std::hash::Hash; + * + * #[deriving(Hash)] + * struct Person { + * id: uint, + * name: String, + * phone: u64, + * } + * + * let person1 = Person { id: 5, name: "Janet".to_string(), phone: 555_666_7777 }; + * let person2 = Person { id: 5, name: "Bob".to_string(), phone: 555_666_7777 }; + * + * assert!(hash::hash(&person1) != hash::hash(&person2)); + * ``` + * + * If you need more control over how a value is hashed, you need to implement + * the trait `Hash`: + * + * ```rust + * use std::hash; + * use std::hash::Hash; + * use std::hash::sip::SipState; + * + * struct Person { + * id: uint, + * name: String, + * phone: u64, + * } + * + * impl Hash for Person { + * fn hash(&self, state: &mut SipState) { + * self.id.hash(state); + * self.phone.hash(state); + * } + * } + * + * let person1 = Person { id: 5, name: "Janet".to_string(), phone: 555_666_7777 }; + * let person2 = Person { id: 5, name: "Bob".to_string(), phone: 555_666_7777 }; + * + * assert!(hash::hash(&person1) == hash::hash(&person2)); + * ``` + */ + +pub use core_collections::hash::{Hash, Hasher, Writer, hash, sip}; + +use default::Default; +use rand::Rng; +use rand; + +/// `RandomSipHasher` computes the SipHash algorithm from a stream of bytes +/// initialized with random keys. +#[deriving(Clone)] +pub struct RandomSipHasher { + hasher: sip::SipHasher, +} + +impl RandomSipHasher { + /// Construct a new `RandomSipHasher` that is initialized with random keys. + #[inline] + pub fn new() -> RandomSipHasher { + let mut r = rand::task_rng(); + let r0 = r.gen(); + let r1 = r.gen(); + RandomSipHasher { + hasher: sip::SipHasher::new_with_keys(r0, r1), + } + } +} + +impl Hasher<sip::SipState> for RandomSipHasher { + #[inline] + fn hash<T: Hash<sip::SipState>>(&self, value: &T) -> u64 { + self.hasher.hash(value) + } +} + +impl Default for RandomSipHasher { + #[inline] + fn default() -> RandomSipHasher { + RandomSipHasher::new() + } +} diff --git a/src/libstd/io/comm_adapters.rs b/src/libstd/io/comm_adapters.rs index c03fbf302d7..cd5887b7add 100644 --- a/src/libstd/io/comm_adapters.rs +++ b/src/libstd/io/comm_adapters.rs @@ -183,7 +183,10 @@ mod test { writer.write_be_u32(42).unwrap(); let wanted = vec![0u8, 0u8, 0u8, 42u8]; - let got = task::try(proc() { rx.recv() }).unwrap(); + let got = match task::try(proc() { rx.recv() }) { + Ok(got) => got, + Err(_) => fail!(), + }; assert_eq!(wanted, got); match writer.write_u8(1) { diff --git a/src/libstd/io/extensions.rs b/src/libstd/io/extensions.rs index 5d9865fded3..277aca2332d 100644 --- a/src/libstd/io/extensions.rs +++ b/src/libstd/io/extensions.rs @@ -166,7 +166,7 @@ pub fn u64_from_be_bytes(data: &[u8], start: uint, size: uint) -> u64 { let ptr = data.as_ptr().offset(start as int); let out = buf.as_mut_ptr(); copy_nonoverlapping_memory(out.offset((8 - size) as int), ptr, size); - from_be64(*(out as *u64)) + from_be64(*(out as *const u64)) } } diff --git a/src/libstd/io/fs.rs b/src/libstd/io/fs.rs index d8e04f18239..e7f26c7bd91 100644 --- a/src/libstd/io/fs.rs +++ b/src/libstd/io/fs.rs @@ -1051,7 +1051,7 @@ mod test { let initial_msg = "food-is-yummy"; let overwrite_msg = "-the-bar!!"; let final_msg = "foo-the-bar!!"; - let seek_idx = 3; + let seek_idx = 3i; let mut read_mem = [0, .. 13]; let tmpdir = tmpdir(); let filename = &tmpdir.join("file_rt_io_file_test_seek_and_write.txt"); @@ -1206,8 +1206,8 @@ mod test { let mut cur = [0u8, .. 2]; for f in files { let stem = f.filestem_str().unwrap(); - let root = stem[0] - ('0' as u8); - let name = stem[1] - ('0' as u8); + let root = stem.as_bytes()[0] - ('0' as u8); + let name = stem.as_bytes()[1] - ('0' as u8); assert!(cur[root as uint] < name); cur[root as uint] = name; } diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 8014759c88a..1d339b03af6 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -216,6 +216,7 @@ responding to errors that may occur while attempting to read the numbers. */ +#![experimental] #![deny(unused_must_use)] use char::Char; diff --git a/src/libstd/io/net/tcp.rs b/src/libstd/io/net/tcp.rs index b79e831ff61..baf53251fbe 100644 --- a/src/libstd/io/net/tcp.rs +++ b/src/libstd/io/net/tcp.rs @@ -1360,4 +1360,44 @@ mod test { rx2.recv(); }) + + iotest!(fn clone_while_reading() { + let addr = next_test_ip6(); + let listen = TcpListener::bind(addr.ip.to_str().as_slice(), addr.port); + let mut accept = listen.listen().unwrap(); + + // Enqueue a task to write to a socket + let (tx, rx) = channel(); + let (txdone, rxdone) = channel(); + let txdone2 = txdone.clone(); + spawn(proc() { + let mut tcp = TcpStream::connect(addr.ip.to_str().as_slice(), + addr.port).unwrap(); + rx.recv(); + tcp.write_u8(0).unwrap(); + txdone2.send(()); + }); + + // Spawn off a reading clone + let tcp = accept.accept().unwrap(); + let tcp2 = tcp.clone(); + let txdone3 = txdone.clone(); + spawn(proc() { + let mut tcp2 = tcp2; + tcp2.read_u8().unwrap(); + txdone3.send(()); + }); + + // Try to ensure that the reading clone is indeed reading + for _ in range(0i, 50) { + ::task::deschedule(); + } + + // clone the handle again while it's reading, then let it finish the + // read. + let _ = tcp.clone(); + tx.send(()); + rxdone.recv(); + rxdone.recv(); + }) } diff --git a/src/libstd/io/net/udp.rs b/src/libstd/io/net/udp.rs index 5f6de52f866..cd78898d46b 100644 --- a/src/libstd/io/net/udp.rs +++ b/src/libstd/io/net/udp.rs @@ -45,12 +45,12 @@ use rt::rtio; /// }; /// /// let mut buf = [0, ..10]; -/// match socket.recvfrom(buf) { +/// match socket.recv_from(buf) { /// Ok((amt, src)) => { /// // Send a reply to the socket we received data from /// let buf = buf.mut_slice_to(amt); /// buf.reverse(); -/// socket.sendto(buf, src); +/// socket.send_to(buf, src); /// } /// Err(e) => println!("couldn't receive a datagram: {}", e) /// } @@ -72,9 +72,9 @@ impl UdpSocket { /// Receives data from the socket. On success, returns the number of bytes /// read and the address from whence the data came. - pub fn recvfrom(&mut self, buf: &mut [u8]) + pub fn recv_from(&mut self, buf: &mut [u8]) -> IoResult<(uint, SocketAddr)> { - match self.obj.recvfrom(buf) { + match self.obj.recv_from(buf) { Ok((amt, rtio::SocketAddr { ip, port })) => { Ok((amt, SocketAddr { ip: super::from_rtio(ip), port: port })) } @@ -82,15 +82,28 @@ impl UdpSocket { } } + #[allow(missing_doc)] + #[deprecated = "renamed to `recv_from`"] + pub fn recvfrom(&mut self, buf: &mut [u8]) + -> IoResult<(uint, SocketAddr)> { + self.recv_from(buf) + } + /// Sends data on the socket to the given address. Returns nothing on /// success. - pub fn sendto(&mut self, buf: &[u8], dst: SocketAddr) -> IoResult<()> { - self.obj.sendto(buf, rtio::SocketAddr { + pub fn send_to(&mut self, buf: &[u8], dst: SocketAddr) -> IoResult<()> { + self.obj.send_to(buf, rtio::SocketAddr { ip: super::to_rtio(dst.ip), port: dst.port, }).map_err(IoError::from_rtio_error) } + #[allow(missing_doc)] + #[deprecated = "renamed to `send_to`"] + pub fn sendto(&mut self, buf: &[u8], dst: SocketAddr) -> IoResult<()> { + self.send_to(buf, dst) + } + /// Creates a `UdpStream`, which allows use of the `Reader` and `Writer` /// traits to receive and send data from the same address. This transfers /// ownership of the socket to the stream. @@ -225,7 +238,7 @@ impl Reader for UdpStream { fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> { let peer = self.connected_to; self.as_socket(|sock| { - match sock.recvfrom(buf) { + match sock.recv_from(buf) { Ok((_nread, src)) if src != peer => Ok(0), Ok((nread, _src)) => Ok(nread), Err(e) => Err(e), @@ -237,7 +250,7 @@ impl Reader for UdpStream { impl Writer for UdpStream { fn write(&mut self, buf: &[u8]) -> IoResult<()> { let connected_to = self.connected_to; - self.as_socket(|sock| sock.sendto(buf, connected_to)) + self.as_socket(|sock| sock.send_to(buf, connected_to)) } } @@ -266,7 +279,7 @@ mod test { match UdpSocket::bind(client_ip) { Ok(ref mut client) => { rx1.recv(); - client.sendto([99], server_ip).unwrap() + client.send_to([99], server_ip).unwrap() } Err(..) => fail!() } @@ -277,7 +290,7 @@ mod test { Ok(ref mut server) => { tx1.send(()); let mut buf = [0]; - match server.recvfrom(buf) { + match server.recv_from(buf) { Ok((nread, src)) => { assert_eq!(nread, 1); assert_eq!(buf[0], 99); @@ -300,7 +313,7 @@ mod test { match UdpSocket::bind(client_ip) { Ok(ref mut client) => { rx.recv(); - client.sendto([99], server_ip).unwrap() + client.send_to([99], server_ip).unwrap() } Err(..) => fail!() } @@ -310,7 +323,7 @@ mod test { Ok(ref mut server) => { tx.send(()); let mut buf = [0]; - match server.recvfrom(buf) { + match server.recv_from(buf) { Ok((nread, src)) => { assert_eq!(nread, 1); assert_eq!(buf[0], 99); @@ -429,9 +442,9 @@ mod test { spawn(proc() { let mut sock2 = sock2; let mut buf = [0, 0]; - assert_eq!(sock2.recvfrom(buf), Ok((1, addr1))); + assert_eq!(sock2.recv_from(buf), Ok((1, addr1))); assert_eq!(buf[0], 1); - sock2.sendto([2], addr1).unwrap(); + sock2.send_to([2], addr1).unwrap(); }); let sock3 = sock1.clone(); @@ -441,12 +454,12 @@ mod test { spawn(proc() { let mut sock3 = sock3; rx1.recv(); - sock3.sendto([1], addr2).unwrap(); + sock3.send_to([1], addr2).unwrap(); tx2.send(()); }); tx1.send(()); let mut buf = [0, 0]; - assert_eq!(sock1.recvfrom(buf), Ok((1, addr2))); + assert_eq!(sock1.recv_from(buf), Ok((1, addr2))); rx2.recv(); }) @@ -460,9 +473,9 @@ mod test { spawn(proc() { let mut sock2 = sock2; - sock2.sendto([1], addr1).unwrap(); + sock2.send_to([1], addr1).unwrap(); rx.recv(); - sock2.sendto([2], addr1).unwrap(); + sock2.send_to([2], addr1).unwrap(); rx.recv(); }); @@ -472,12 +485,12 @@ mod test { spawn(proc() { let mut sock3 = sock3; let mut buf = [0, 0]; - sock3.recvfrom(buf).unwrap(); + sock3.recv_from(buf).unwrap(); tx2.send(()); done.send(()); }); let mut buf = [0, 0]; - sock1.recvfrom(buf).unwrap(); + sock1.recv_from(buf).unwrap(); tx1.send(()); rx.recv(); @@ -497,7 +510,7 @@ mod test { let mut buf = [0, 1]; rx.recv(); - match sock2.recvfrom(buf) { + match sock2.recv_from(buf) { Ok(..) => {} Err(e) => fail!("failed receive: {}", e), } @@ -510,13 +523,13 @@ mod test { let tx2 = tx.clone(); spawn(proc() { let mut sock3 = sock3; - match sock3.sendto([1], addr2) { + match sock3.send_to([1], addr2) { Ok(..) => { let _ = tx2.send_opt(()); } Err(..) => {} } done.send(()); }); - match sock1.sendto([2], addr2) { + match sock1.send_to([2], addr2) { Ok(..) => { let _ = tx.send_opt(()); } Err(..) => {} } @@ -526,7 +539,7 @@ mod test { serv_rx.recv(); }) - iotest!(fn recvfrom_timeout() { + iotest!(fn recv_from_timeout() { let addr1 = next_test_ip4(); let addr2 = next_test_ip4(); let mut a = UdpSocket::bind(addr1).unwrap(); @@ -535,34 +548,34 @@ mod test { let (tx2, rx2) = channel(); spawn(proc() { let mut a = UdpSocket::bind(addr2).unwrap(); - assert_eq!(a.recvfrom([0]), Ok((1, addr1))); - assert_eq!(a.sendto([0], addr1), Ok(())); + assert_eq!(a.recv_from([0]), Ok((1, addr1))); + assert_eq!(a.send_to([0], addr1), Ok(())); rx.recv(); - assert_eq!(a.sendto([0], addr1), Ok(())); + assert_eq!(a.send_to([0], addr1), Ok(())); tx2.send(()); }); // Make sure that reads time out, but writes can continue a.set_read_timeout(Some(20)); - assert_eq!(a.recvfrom([0]).err().unwrap().kind, TimedOut); - assert_eq!(a.recvfrom([0]).err().unwrap().kind, TimedOut); - assert_eq!(a.sendto([0], addr2), Ok(())); + assert_eq!(a.recv_from([0]).err().unwrap().kind, TimedOut); + assert_eq!(a.recv_from([0]).err().unwrap().kind, TimedOut); + assert_eq!(a.send_to([0], addr2), Ok(())); // Cloned handles should be able to block let mut a2 = a.clone(); - assert_eq!(a2.recvfrom([0]), Ok((1, addr2))); + assert_eq!(a2.recv_from([0]), Ok((1, addr2))); // Clearing the timeout should allow for receiving a.set_timeout(None); tx.send(()); - assert_eq!(a2.recvfrom([0]), Ok((1, addr2))); + assert_eq!(a2.recv_from([0]), Ok((1, addr2))); // Make sure the child didn't die rx2.recv(); }) - iotest!(fn sendto_timeout() { + iotest!(fn send_to_timeout() { let addr1 = next_test_ip4(); let addr2 = next_test_ip4(); let mut a = UdpSocket::bind(addr1).unwrap(); @@ -570,7 +583,7 @@ mod test { a.set_write_timeout(Some(1000)); for _ in range(0u, 100) { - match a.sendto([0, ..4*1024], addr2) { + match a.send_to([0, ..4*1024], addr2) { Ok(()) | Err(IoError { kind: ShortWrite(..), .. }) => {}, Err(IoError { kind: TimedOut, .. }) => break, Err(e) => fail!("other error: {}", e), diff --git a/src/libstd/io/test.rs b/src/libstd/io/test.rs index 4d3dde46b57..26e854d9d99 100644 --- a/src/libstd/io/test.rs +++ b/src/libstd/io/test.rs @@ -155,7 +155,7 @@ mod darwin_fd_limit { oldp: *mut libc::c_void, oldlenp: *mut libc::size_t, newp: *mut libc::c_void, newlen: libc::size_t) -> libc::c_int; fn getrlimit(resource: libc::c_int, rlp: *mut rlimit) -> libc::c_int; - fn setrlimit(resource: libc::c_int, rlp: *rlimit) -> libc::c_int; + fn setrlimit(resource: libc::c_int, rlp: *const rlimit) -> libc::c_int; } static CTL_KERN: libc::c_int = 1; static KERN_MAXFILESPERPROC: libc::c_int = 29; diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index b1512440969..145e812ff88 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -95,6 +95,7 @@ //! and `format!`, also available to all Rust code. #![crate_id = "std#0.11.0"] +#![unstable] #![comment = "The Rust standard library"] #![license = "MIT/ASL2"] #![crate_type = "rlib"] @@ -111,7 +112,6 @@ #![no_std] #![allow(deprecated)] -#![allow(unknown_features)] // NOTE: remove after stage0 snapshot #![deny(missing_doc)] // When testing libstd, bring in libuv as the I/O backend so tests can print @@ -167,7 +167,6 @@ pub use core::option; pub use alloc::owned; pub use alloc::rc; -pub use core_collections::hash; pub use core_collections::slice; pub use core_collections::str; pub use core_collections::string; @@ -184,7 +183,7 @@ pub use core_sync::comm; // threading mode than the default by reaching into the auto-generated // '__test' module. #[cfg(test)] #[start] -fn start(argc: int, argv: **u8) -> int { +fn start(argc: int, argv: *const *const u8) -> int { green::start(argc, argv, rustuv::event_loop, __test::main) } @@ -237,6 +236,7 @@ pub mod to_str; /* Common data structures */ pub mod collections; +pub mod hash; /* Tasks and communication */ diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index 4db15d2cbbe..8b79af8c931 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -14,6 +14,7 @@ //! library. Each macro is available for use when linking against the standard //! library. +#![experimental] #![macro_escape] /// The entry point for failure of rust tasks. diff --git a/src/libstd/num/f32.rs b/src/libstd/num/f32.rs index bbf1458da21..2b2ffb9f4e2 100644 --- a/src/libstd/num/f32.rs +++ b/src/libstd/num/f32.rs @@ -10,6 +10,7 @@ //! Operations and constants for 32-bits floats (`f32` type) +#![experimental] #![allow(missing_doc)] #![allow(unsigned_negate)] #![doc(primitive = "f32")] diff --git a/src/libstd/num/f64.rs b/src/libstd/num/f64.rs index cfa8534160b..e156d2ce553 100644 --- a/src/libstd/num/f64.rs +++ b/src/libstd/num/f64.rs @@ -10,6 +10,7 @@ //! Operations and constants for 64-bits floats (`f64` type) +#![experimental] #![allow(missing_doc)] #![doc(primitive = "f64")] diff --git a/src/libstd/num/float_macros.rs b/src/libstd/num/float_macros.rs index 3e403219a4f..519de85edde 100644 --- a/src/libstd/num/float_macros.rs +++ b/src/libstd/num/float_macros.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![experimental] #![macro_escape] #![doc(hidden)] diff --git a/src/libstd/num/int_macros.rs b/src/libstd/num/int_macros.rs index 9b3c9d29cc7..a4200b55a59 100644 --- a/src/libstd/num/int_macros.rs +++ b/src/libstd/num/int_macros.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![experimental] #![macro_escape] #![doc(hidden)] diff --git a/src/libstd/num/mod.rs b/src/libstd/num/mod.rs index 65056652e3f..27ee1e3ce3b 100644 --- a/src/libstd/num/mod.rs +++ b/src/libstd/num/mod.rs @@ -13,6 +13,7 @@ //! These are implemented for the primitive numeric types in `std::{u8, u16, //! u32, u64, uint, i8, i16, i32, i64, int, f32, f64}`. +#![experimental] #![allow(missing_doc)] use option::Option; diff --git a/src/libstd/num/uint_macros.rs b/src/libstd/num/uint_macros.rs index 19e45b292fb..7f2efe034a2 100644 --- a/src/libstd/num/uint_macros.rs +++ b/src/libstd/num/uint_macros.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![experimental] #![macro_escape] #![doc(hidden)] #![allow(unsigned_negate)] diff --git a/src/libstd/os.rs b/src/libstd/os.rs index a77242638eb..6674dd532ae 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -26,6 +26,8 @@ * to write OS-ignorant code by default. */ +#![experimental] + #![allow(missing_doc)] #![allow(non_snake_case_functions)] @@ -276,7 +278,7 @@ pub fn env_as_bytes() -> Vec<(Vec<u8>,Vec<u8>)> { use c_str::CString; extern { - fn rust_env_pairs() -> **c_char; + fn rust_env_pairs() -> *const *const c_char; } let environ = rust_env_pairs(); if environ as uint == 0 { @@ -351,7 +353,7 @@ pub fn getenv_as_bytes(n: &str) -> Option<Vec<u8>> { if s.is_null() { None } else { - Some(Vec::from_slice(CString::new(s, + Some(Vec::from_slice(CString::new(s as *const i8, false).as_bytes_no_nul())) } }) @@ -365,7 +367,8 @@ pub fn getenv(n: &str) -> Option<String> { unsafe { with_env_lock(|| { use os::win32::{fill_utf16_buf_and_decode}; - let n = n.to_utf16().append_one(0); + let n: Vec<u16> = n.utf16_units().collect(); + let n = n.append_one(0); fill_utf16_buf_and_decode(|buf, sz| { libc::GetEnvironmentVariableW(n.as_ptr(), buf, sz) }) @@ -411,8 +414,10 @@ pub fn setenv(n: &str, v: &str) { #[cfg(windows)] fn _setenv(n: &str, v: &str) { - let n = n.to_utf16().append_one(0); - let v = v.to_utf16().append_one(0); + let n: Vec<u16> = n.utf16_units().collect(); + let n = n.append_one(0); + let v: Vec<u16> = v.utf16_units().collect(); + let v = v.append_one(0); unsafe { with_env_lock(|| { libc::SetEnvironmentVariableW(n.as_ptr(), v.as_ptr()); @@ -437,7 +442,8 @@ pub fn unsetenv(n: &str) { #[cfg(windows)] fn _unsetenv(n: &str) { - let n = n.to_utf16().append_one(0); + let n: Vec<u16> = n.utf16_units().collect(); + let n = n.append_one(0); unsafe { with_env_lock(|| { libc::SetEnvironmentVariableW(n.as_ptr(), ptr::null()); @@ -598,19 +604,20 @@ pub fn self_exe_name() -> Option<Path> { unsafe { use libc::funcs::bsd44::*; use libc::consts::os::extra::*; - let mib = vec![CTL_KERN as c_int, - KERN_PROC as c_int, - KERN_PROC_PATHNAME as c_int, -1 as c_int]; + let mut mib = vec![CTL_KERN as c_int, + KERN_PROC as c_int, + KERN_PROC_PATHNAME as c_int, + -1 as c_int]; let mut sz: libc::size_t = 0; - let err = sysctl(mib.as_ptr(), mib.len() as ::libc::c_uint, - ptr::mut_null(), &mut sz, ptr::null(), + let err = sysctl(mib.as_mut_ptr(), mib.len() as ::libc::c_uint, + ptr::mut_null(), &mut sz, ptr::mut_null(), 0u as libc::size_t); if err != 0 { return None; } if sz == 0 { return None; } let mut v: Vec<u8> = Vec::with_capacity(sz as uint); - let err = sysctl(mib.as_ptr(), mib.len() as ::libc::c_uint, - v.as_mut_ptr() as *mut c_void, &mut sz, ptr::null(), - 0u as libc::size_t); + let err = sysctl(mib.as_mut_ptr(), mib.len() as ::libc::c_uint, + v.as_mut_ptr() as *mut c_void, &mut sz, + ptr::mut_null(), 0u as libc::size_t); if err != 0 { return None; } if sz == 0 { return None; } v.set_len(sz as uint - 1); // chop off trailing NUL @@ -803,7 +810,7 @@ pub fn change_dir(p: &Path) -> bool { #[cfg(windows)] fn chdir(p: &Path) -> bool { let p = match p.as_str() { - Some(s) => s.to_utf16().append_one(0), + Some(s) => s.utf16_units().collect::<Vec<u16>>().append_one(0), None => return false, }; unsafe { @@ -827,9 +834,9 @@ pub fn errno() -> int { #[cfg(target_os = "macos")] #[cfg(target_os = "ios")] #[cfg(target_os = "freebsd")] - fn errno_location() -> *c_int { + fn errno_location() -> *const c_int { extern { - fn __error() -> *c_int; + fn __error() -> *const c_int; } unsafe { __error() @@ -838,9 +845,9 @@ pub fn errno() -> int { #[cfg(target_os = "linux")] #[cfg(target_os = "android")] - fn errno_location() -> *c_int { + fn errno_location() -> *const c_int { extern { - fn __errno_location() -> *c_int; + fn __errno_location() -> *const c_int; } unsafe { __errno_location() @@ -913,7 +920,7 @@ pub fn error_string(errnum: uint) -> String { fail!("strerror_r failure"); } - str::raw::from_c_str(p as *c_char).into_string() + str::raw::from_c_str(p as *const c_char).into_string() } } @@ -932,7 +939,7 @@ pub fn error_string(errnum: uint) -> String { langId: DWORD, buf: LPWSTR, nsize: DWORD, - args: *c_void) + args: *const c_void) -> DWORD; } @@ -997,7 +1004,8 @@ pub fn get_exit_status() -> int { } #[cfg(target_os = "macos")] -unsafe fn load_argc_and_argv(argc: int, argv: **c_char) -> Vec<Vec<u8>> { +unsafe fn load_argc_and_argv(argc: int, + argv: *const *const c_char) -> Vec<Vec<u8>> { use c_str::CString; Vec::from_fn(argc as uint, |i| { @@ -1015,7 +1023,7 @@ unsafe fn load_argc_and_argv(argc: int, argv: **c_char) -> Vec<Vec<u8>> { fn real_args_as_bytes() -> Vec<Vec<u8>> { unsafe { let (argc, argv) = (*_NSGetArgc() as int, - *_NSGetArgv() as **c_char); + *_NSGetArgv() as *const *const c_char); load_argc_and_argv(argc, argv) } } @@ -1040,16 +1048,16 @@ fn real_args_as_bytes() -> Vec<Vec<u8>> { #[link(name = "objc")] extern { - fn sel_registerName(name: *libc::c_uchar) -> Sel; + fn sel_registerName(name: *const libc::c_uchar) -> Sel; fn objc_msgSend(obj: NsId, sel: Sel, ...) -> NsId; - fn objc_getClass(class_name: *libc::c_uchar) -> NsId; + fn objc_getClass(class_name: *const libc::c_uchar) -> NsId; } #[link(name = "Foundation", kind = "framework")] extern {} - type Sel = *libc::c_void; - type NsId = *libc::c_void; + type Sel = *const libc::c_void; + type NsId = *const libc::c_void; let mut res = Vec::new(); @@ -1067,7 +1075,8 @@ fn real_args_as_bytes() -> Vec<Vec<u8>> { let cnt: int = mem::transmute(objc_msgSend(args, countSel)); for i in range(0, cnt) { let tmp = objc_msgSend(args, objectAtSel, i); - let utf_c_str: *libc::c_char = mem::transmute(objc_msgSend(tmp, utf8Sel)); + let utf_c_str: *const libc::c_char = + mem::transmute(objc_msgSend(tmp, utf8Sel)); let s = CString::new(utf_c_str, false); if s.is_not_null() { res.push(Vec::from_slice(s.as_bytes_no_nul())) @@ -1114,14 +1123,14 @@ fn real_args() -> Vec<String> { while *ptr.offset(len as int) != 0 { len += 1; } // Push it onto the list. - let opt_s = slice::raw::buf_as_slice(ptr, len, |buf| { + let opt_s = slice::raw::buf_as_slice(ptr as *const _, len, |buf| { str::from_utf16(str::truncate_utf16_at_nul(buf)) }); opt_s.expect("CommandLineToArgvW returned invalid UTF-16") }); unsafe { - LocalFree(szArgList as *c_void); + LocalFree(szArgList as *mut c_void); } return args @@ -1132,19 +1141,20 @@ fn real_args_as_bytes() -> Vec<Vec<u8>> { real_args().move_iter().map(|s| s.into_bytes()).collect() } -type LPCWSTR = *u16; +type LPCWSTR = *const u16; #[cfg(windows)] #[link_name="kernel32"] extern "system" { fn GetCommandLineW() -> LPCWSTR; - fn LocalFree(ptr: *c_void); + fn LocalFree(ptr: *mut c_void); } #[cfg(windows)] #[link_name="shell32"] extern "system" { - fn CommandLineToArgvW(lpCmdLine: LPCWSTR, pNumArgs: *mut c_int) -> **u16; + fn CommandLineToArgvW(lpCmdLine: LPCWSTR, + pNumArgs: *mut c_int) -> *mut *mut u16; } /// Returns the arguments which this program was started with (normally passed @@ -1165,8 +1175,8 @@ pub fn args_as_bytes() -> Vec<Vec<u8>> { #[cfg(target_os = "macos")] extern { // These functions are in crt_externs.h. - pub fn _NSGetArgc() -> *c_int; - pub fn _NSGetArgv() -> ***c_char; + pub fn _NSGetArgc() -> *mut c_int; + pub fn _NSGetArgv() -> *mut *mut *mut c_char; } // Round up `from` to be divisible by `to` @@ -1224,7 +1234,7 @@ pub struct MemoryMap { pub enum MemoryMapKind { /// Virtual memory map. Usually used to change the permissions of a given /// chunk of memory. Corresponds to `VirtualAlloc` on Windows. - MapFile(*u8), + MapFile(*const u8), /// Virtual memory map. Usually used to change the permissions of a given /// chunk of memory, or for allocation. Corresponds to `VirtualAlloc` on /// Windows. @@ -1241,7 +1251,7 @@ pub enum MapOption { MapExecutable, /// Create a map for a specific address range. Corresponds to `MAP_FIXED` on /// POSIX. - MapAddr(*u8), + MapAddr(*const u8), /// Create a memory mapping for a file with a given fd. MapFd(c_int), /// When using `MapFd`, the start of the map is `uint` bytes from the start @@ -1342,7 +1352,7 @@ impl MemoryMap { if min_len == 0 { return Err(ErrZeroLength) } - let mut addr: *u8 = ptr::null(); + let mut addr: *const u8 = ptr::null(); let mut prot = 0; let mut flags = libc::MAP_PRIVATE; let mut fd = -1; @@ -1502,7 +1512,7 @@ impl MemoryMap { _ => Ok(MemoryMap { data: r as *mut u8, len: len, - kind: MapFile(mapping as *u8) + kind: MapFile(mapping as *const u8) }) } } @@ -1812,7 +1822,7 @@ mod tests { #[ignore] fn test_getenv_big() { let mut s = "".to_string(); - let mut i = 0; + let mut i = 0i; while i < 100 { s.push_str("aaaaaaaaaa"); i += 1; @@ -1990,7 +2000,7 @@ mod tests { open(path, O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR) }); lseek_(fd, size); - "x".with_c_str(|x| assert!(write(fd, x as *c_void, 1) == 1)); + "x".with_c_str(|x| assert!(write(fd, x as *const c_void, 1) == 1)); fd }; let chunk = match MemoryMap::new(size / 2, [ diff --git a/src/libstd/path/mod.rs b/src/libstd/path/mod.rs index e55dc165895..7d814df8ebf 100644 --- a/src/libstd/path/mod.rs +++ b/src/libstd/path/mod.rs @@ -35,8 +35,8 @@ code, `Path` should be used to refer to the platform-native path. Creation of a path is typically done with either `Path::new(some_str)` or `Path::new(some_vec)`. This path can be modified with `.push()` and `.pop()` (and other setters). The resulting Path can either be passed to another -API that expects a path, or can be turned into a &[u8] with `.as_vec()` or a -Option<&str> with `.as_str()`. Similarly, attributes of the path can be queried +API that expects a path, or can be turned into a `&[u8]` with `.as_vec()` or a +`Option<&str>` with `.as_str()`. Similarly, attributes of the path can be queried with methods such as `.filename()`. There are also methods that return a new path instead of modifying the receiver, such as `.join()` or `.dir_path()`. @@ -63,6 +63,8 @@ println!("path exists: {}", path.exists()); */ +#![experimental] + use collections::Collection; use c_str::CString; use clone::Clone; diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index ec225a588fc..113b0410875 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -242,14 +242,18 @@ impl GenericPathUnsafe for Path { fn is_vol_abs(path: &str, prefix: Option<PathPrefix>) -> bool { // assume prefix is Some(DiskPrefix) let rest = path.slice_from(prefix_len(prefix)); - !rest.is_empty() && rest[0].is_ascii() && is_sep(rest[0] as char) + !rest.is_empty() && rest.as_bytes()[0].is_ascii() && is_sep(rest.as_bytes()[0] as char) } fn shares_volume(me: &Path, path: &str) -> bool { // path is assumed to have a prefix of Some(DiskPrefix) let repr = me.repr.as_slice(); match me.prefix { - Some(DiskPrefix) => repr[0] == path[0].to_ascii().to_upper().to_byte(), - Some(VerbatimDiskPrefix) => repr[4] == path[0].to_ascii().to_upper().to_byte(), + Some(DiskPrefix) => { + repr.as_bytes()[0] == path.as_bytes()[0].to_ascii().to_upper().to_byte() + } + Some(VerbatimDiskPrefix) => { + repr.as_bytes()[4] == path.as_bytes()[0].to_ascii().to_upper().to_byte() + } _ => false } } @@ -279,7 +283,7 @@ impl GenericPathUnsafe for Path { // if me is "C:" we don't want to add a path separator match me.prefix { Some(DiskPrefix) if me.repr.len() == plen => (), - _ if !(me.repr.len() > plen && me.repr.as_slice()[me.repr.len()-1] == SEP_BYTE) => { + _ if !(me.repr.len() > plen && me.repr.as_bytes()[me.repr.len()-1] == SEP_BYTE) => { s.push_char(SEP); } _ => () @@ -302,7 +306,7 @@ impl GenericPathUnsafe for Path { // absolute path, or cwd-relative and self is not same volume replace_path(self, path, prefix); } - None if !path.is_empty() && is_sep_(self.prefix, path[0]) => { + None if !path.is_empty() && is_sep_(self.prefix, path.as_bytes()[0]) => { // volume-relative path if self.prefix.is_some() { // truncate self down to the prefix, then append @@ -478,7 +482,7 @@ impl GenericPath for Path { match self.prefix { Some(DiskPrefix) => { let rest = self.repr.as_slice().slice_from(self.prefix_len()); - rest.len() > 0 && rest[0] == SEP_BYTE + rest.len() > 0 && rest.as_bytes()[0] == SEP_BYTE } Some(_) => true, None => false @@ -638,11 +642,11 @@ impl Path { let s = match self.prefix { Some(_) => { let plen = self.prefix_len(); - if repr.len() > plen && repr[plen] == SEP_BYTE { + if repr.len() > plen && repr.as_bytes()[plen] == SEP_BYTE { repr.slice_from(plen+1) } else { repr.slice_from(plen) } } - None if repr[0] == SEP_BYTE => repr.slice_from(1), + None if repr.as_bytes()[0] == SEP_BYTE => repr.slice_from(1), None => repr }; let ret = s.split_terminator(SEP).map(Some); @@ -665,14 +669,14 @@ impl Path { match (self.prefix, other.prefix) { (Some(DiskPrefix), Some(VerbatimDiskPrefix)) => { self.is_absolute() && - s_repr[0].to_ascii().eq_ignore_case(o_repr[4].to_ascii()) + s_repr.as_bytes()[0].to_ascii().eq_ignore_case(o_repr.as_bytes()[4].to_ascii()) } (Some(VerbatimDiskPrefix), Some(DiskPrefix)) => { other.is_absolute() && - s_repr[4].to_ascii().eq_ignore_case(o_repr[0].to_ascii()) + s_repr.as_bytes()[4].to_ascii().eq_ignore_case(o_repr.as_bytes()[0].to_ascii()) } (Some(VerbatimDiskPrefix), Some(VerbatimDiskPrefix)) => { - s_repr[4].to_ascii().eq_ignore_case(o_repr[4].to_ascii()) + s_repr.as_bytes()[4].to_ascii().eq_ignore_case(o_repr.as_bytes()[4].to_ascii()) } (Some(UNCPrefix(_,_)), Some(VerbatimUNCPrefix(_,_))) => { s_repr.slice(2, self.prefix_len()) == o_repr.slice(8, other.prefix_len()) @@ -718,12 +722,12 @@ impl Path { let mut comps = comps; match (comps.is_some(),prefix) { (false, Some(DiskPrefix)) => { - if s[0] >= 'a' as u8 && s[0] <= 'z' as u8 { + if s.as_bytes()[0] >= 'a' as u8 && s.as_bytes()[0] <= 'z' as u8 { comps = Some(vec![]); } } (false, Some(VerbatimDiskPrefix)) => { - if s[4] >= 'a' as u8 && s[0] <= 'z' as u8 { + if s.as_bytes()[4] >= 'a' as u8 && s.as_bytes()[0] <= 'z' as u8 { comps = Some(vec![]); } } @@ -778,12 +782,12 @@ impl Path { let mut s = String::with_capacity(n); match prefix { Some(DiskPrefix) => { - s.push_char(prefix_[0].to_ascii().to_upper().to_char()); + s.push_char(prefix_.as_bytes()[0].to_ascii().to_upper().to_char()); s.push_char(':'); } Some(VerbatimDiskPrefix) => { s.push_str(prefix_.slice_to(4)); - s.push_char(prefix_[4].to_ascii().to_upper().to_char()); + s.push_char(prefix_.as_bytes()[4].to_ascii().to_upper().to_char()); s.push_str(prefix_.slice_from(5)); } Some(UNCPrefix(a,b)) => { @@ -845,7 +849,7 @@ impl Path { fn has_nonsemantic_trailing_slash(&self) -> bool { is_verbatim(self) && self.repr.len() > self.prefix_len()+1 && - self.repr.as_slice()[self.repr.len()-1] == SEP_BYTE + self.repr.as_bytes()[self.repr.len()-1] == SEP_BYTE } fn update_normalized<S: Str>(&mut self, s: S) { @@ -861,7 +865,7 @@ impl Path { /// but absolute within that volume. #[inline] pub fn is_vol_relative(path: &Path) -> bool { - path.prefix.is_none() && is_sep_byte(&path.repr.as_slice()[0]) + path.prefix.is_none() && is_sep_byte(&path.repr.as_bytes()[0]) } /// Returns whether the path is considered "cwd-relative", which means a path @@ -991,8 +995,8 @@ fn parse_prefix<'a>(mut path: &'a str) -> Option<PathPrefix> { } else { // \\?\path let idx = path.find('\\'); - if idx == Some(2) && path[1] == ':' as u8 { - let c = path[0]; + if idx == Some(2) && path.as_bytes()[1] == ':' as u8 { + let c = path.as_bytes()[0]; if c.is_ascii() && ::char::is_alphabetic(c as char) { // \\?\C:\ path return Some(VerbatimDiskPrefix); @@ -1014,9 +1018,9 @@ fn parse_prefix<'a>(mut path: &'a str) -> Option<PathPrefix> { } _ => () } - } else if path.len() > 1 && path[1] == ':' as u8 { + } else if path.len() > 1 && path.as_bytes()[1] == ':' as u8 { // C: - let c = path[0]; + let c = path.as_bytes()[0]; if c.is_ascii() && ::char::is_alphabetic(c as char) { return Some(DiskPrefix); } diff --git a/src/libstd/prelude.rs b/src/libstd/prelude.rs index dfe6988624e..61e8b63af35 100644 --- a/src/libstd/prelude.rs +++ b/src/libstd/prelude.rs @@ -37,6 +37,8 @@ //! particularly useful standalone functions, like `from_str`, `range`, and //! `drop`, `spawn`, and `channel`. +#![experimental] + // Reexported core operators #[doc(no_inline)] pub use kinds::{Copy, Send, Sized, Share}; #[doc(no_inline)] pub use ops::{Add, Sub, Mul, Div, Rem, Neg, Not}; diff --git a/src/libstd/rand/mod.rs b/src/libstd/rand/mod.rs index ffe4a94d2a2..0ffaadef0a1 100644 --- a/src/libstd/rand/mod.rs +++ b/src/libstd/rand/mod.rs @@ -73,6 +73,8 @@ println!("{}", tuple) ``` */ +#![experimental] + use cell::RefCell; use clone::Clone; use io::IoResult; @@ -244,7 +246,7 @@ pub fn random<T: Rand>() -> T { task_rng().gen() } -/// Randomly sample up to `n` elements from an iterator. +/// Randomly sample up to `amount` elements from an iterator. /// /// # Example /// @@ -257,11 +259,11 @@ pub fn random<T: Rand>() -> T { /// ``` pub fn sample<T, I: Iterator<T>, R: Rng>(rng: &mut R, mut iter: I, - amt: uint) -> Vec<T> { - let mut reservoir: Vec<T> = iter.by_ref().take(amt).collect(); + amount: uint) -> Vec<T> { + let mut reservoir: Vec<T> = iter.by_ref().take(amount).collect(); for (i, elem) in iter.enumerate() { - let k = rng.gen_range(0, i + 1 + amt); - if k < amt { + let k = rng.gen_range(0, i + 1 + amount); + if k < amount { *reservoir.get_mut(k) = elem; } } diff --git a/src/libstd/rand/os.rs b/src/libstd/rand/os.rs index 1c1aab15361..60e2c4c8949 100644 --- a/src/libstd/rand/os.rs +++ b/src/libstd/rand/os.rs @@ -87,11 +87,12 @@ mod imp { struct SecRandom; - static kSecRandomDefault: *SecRandom = 0 as *SecRandom; + static kSecRandomDefault: *const SecRandom = 0 as *const SecRandom; #[link(name = "Security", kind = "framework")] extern "C" { - fn SecRandomCopyBytes(rnd: *SecRandom, count: size_t, bytes: *mut u8) -> c_int; + fn SecRandomCopyBytes(rnd: *const SecRandom, + count: size_t, bytes: *mut u8) -> c_int; } impl OsRng { diff --git a/src/libstd/rt/backtrace.rs b/src/libstd/rt/backtrace.rs index e3652ffac6e..8f51e834c6a 100644 --- a/src/libstd/rt/backtrace.rs +++ b/src/libstd/rt/backtrace.rs @@ -261,7 +261,8 @@ mod imp { use slice::{MutableVector}; extern { - fn backtrace(buf: *mut *libc::c_void, sz: libc::c_int) -> libc::c_int; + fn backtrace(buf: *mut *const libc::c_void, + sz: libc::c_int) -> libc::c_int; } // while it doesn't requires lock for work as everything is @@ -273,7 +274,7 @@ mod imp { try!(writeln!(w, "stack backtrace:")); // 100 lines should be enough static SIZE: libc::c_int = 100; - let mut buf: [*libc::c_void, ..SIZE] = unsafe {mem::zeroed()}; + let mut buf: [*const libc::c_void, ..SIZE] = unsafe {mem::zeroed()}; let cnt = unsafe { backtrace(buf.as_mut_ptr(), SIZE) as uint}; // skipping the first one as it is write itself @@ -307,7 +308,7 @@ mod imp { let mut cx = Context { writer: w, last_error: None, idx: 0 }; return match unsafe { uw::_Unwind_Backtrace(trace_fn, - &mut cx as *mut Context as *libc::c_void) + &mut cx as *mut Context as *mut libc::c_void) } { uw::_URC_NO_REASON => { match cx.last_error { @@ -318,10 +319,10 @@ mod imp { _ => Ok(()), }; - extern fn trace_fn(ctx: *uw::_Unwind_Context, - arg: *libc::c_void) -> uw::_Unwind_Reason_Code { + extern fn trace_fn(ctx: *mut uw::_Unwind_Context, + arg: *mut libc::c_void) -> uw::_Unwind_Reason_Code { let cx: &mut Context = unsafe { mem::transmute(arg) }; - let ip = unsafe { uw::_Unwind_GetIP(ctx) as *libc::c_void }; + let ip = unsafe { uw::_Unwind_GetIP(ctx) as *mut libc::c_void }; // dladdr() on osx gets whiny when we use FindEnclosingFunction, and // it appears to work fine without it, so we only use // FindEnclosingFunction on non-osx platforms. In doing so, we get a @@ -365,22 +366,22 @@ mod imp { #[cfg(target_os = "macos")] #[cfg(target_os = "ios")] - fn print(w: &mut Writer, idx: int, addr: *libc::c_void) -> IoResult<()> { + fn print(w: &mut Writer, idx: int, addr: *mut libc::c_void) -> IoResult<()> { use intrinsics; #[repr(C)] struct Dl_info { - dli_fname: *libc::c_char, - dli_fbase: *libc::c_void, - dli_sname: *libc::c_char, - dli_saddr: *libc::c_void, + dli_fname: *const libc::c_char, + dli_fbase: *mut libc::c_void, + dli_sname: *const libc::c_char, + dli_saddr: *mut libc::c_void, } extern { - fn dladdr(addr: *libc::c_void, + fn dladdr(addr: *const libc::c_void, info: *mut Dl_info) -> libc::c_int; } let mut info: Dl_info = unsafe { intrinsics::init() }; - if unsafe { dladdr(addr, &mut info) == 0 } { + if unsafe { dladdr(addr as *const libc::c_void, &mut info) == 0 } { output(w, idx,addr, None) } else { output(w, idx, addr, Some(unsafe { @@ -390,7 +391,7 @@ mod imp { } #[cfg(not(target_os = "macos"), not(target_os = "ios"))] - fn print(w: &mut Writer, idx: int, addr: *libc::c_void) -> IoResult<()> { + fn print(w: &mut Writer, idx: int, addr: *mut libc::c_void) -> IoResult<()> { use collections::Collection; use iter::Iterator; use os; @@ -405,17 +406,17 @@ mod imp { type backtrace_syminfo_callback = extern "C" fn(data: *mut libc::c_void, pc: libc::uintptr_t, - symname: *libc::c_char, + symname: *const libc::c_char, symval: libc::uintptr_t, symsize: libc::uintptr_t); type backtrace_error_callback = extern "C" fn(data: *mut libc::c_void, - msg: *libc::c_char, + msg: *const libc::c_char, errnum: libc::c_int); enum backtrace_state {} #[link(name = "backtrace", kind = "static")] extern { - fn backtrace_create_state(filename: *libc::c_char, + fn backtrace_create_state(filename: *const libc::c_char, threaded: libc::c_int, error: backtrace_error_callback, data: *mut libc::c_void) @@ -431,16 +432,16 @@ mod imp { // helper callbacks //////////////////////////////////////////////////////////////////////// - extern fn error_cb(_data: *mut libc::c_void, _msg: *libc::c_char, + extern fn error_cb(_data: *mut libc::c_void, _msg: *const libc::c_char, _errnum: libc::c_int) { // do nothing for now } extern fn syminfo_cb(data: *mut libc::c_void, _pc: libc::uintptr_t, - symname: *libc::c_char, + symname: *const libc::c_char, _symval: libc::uintptr_t, _symsize: libc::uintptr_t) { - let slot = data as *mut *libc::c_char; + let slot = data as *mut *const libc::c_char; unsafe { *slot = symname; } } @@ -502,8 +503,8 @@ mod imp { if state.is_null() { return output(w, idx, addr, None) } - let mut data = 0 as *libc::c_char; - let data_addr = &mut data as *mut *libc::c_char; + let mut data = 0 as *const libc::c_char; + let data_addr = &mut data as *mut *const libc::c_char; let ret = unsafe { backtrace_syminfo(state, addr as libc::uintptr_t, syminfo_cb, error_cb, @@ -517,7 +518,7 @@ mod imp { } // Finally, after all that work above, we can emit a symbol. - fn output(w: &mut Writer, idx: int, addr: *libc::c_void, + fn output(w: &mut Writer, idx: int, addr: *mut libc::c_void, s: Option<CString>) -> IoResult<()> { try!(write!(w, " {:2}: {:2$} - ", idx, addr, super::HEX_WIDTH)); match s.as_ref().and_then(|c| c.as_str()) { @@ -557,23 +558,23 @@ mod imp { pub enum _Unwind_Context {} pub type _Unwind_Trace_Fn = - extern fn(ctx: *_Unwind_Context, - arg: *libc::c_void) -> _Unwind_Reason_Code; + extern fn(ctx: *mut _Unwind_Context, + arg: *mut libc::c_void) -> _Unwind_Reason_Code; extern { // No native _Unwind_Backtrace on iOS #[cfg(not(target_os = "ios", target_arch = "arm"))] pub fn _Unwind_Backtrace(trace: _Unwind_Trace_Fn, - trace_argument: *libc::c_void) + trace_argument: *mut libc::c_void) -> _Unwind_Reason_Code; #[cfg(not(target_os = "android"), not(target_os = "linux", target_arch = "arm"))] - pub fn _Unwind_GetIP(ctx: *_Unwind_Context) -> libc::uintptr_t; + pub fn _Unwind_GetIP(ctx: *mut _Unwind_Context) -> libc::uintptr_t; #[cfg(not(target_os = "android"), not(target_os = "linux", target_arch = "arm"))] - pub fn _Unwind_FindEnclosingFunction(pc: *libc::c_void) - -> *libc::c_void; + pub fn _Unwind_FindEnclosingFunction(pc: *mut libc::c_void) + -> *mut libc::c_void; } // On android, the function _Unwind_GetIP is a macro, and this is the @@ -581,7 +582,7 @@ mod imp { // header file with the definition of _Unwind_GetIP. #[cfg(target_os = "android")] #[cfg(target_os = "linux", target_arch = "arm")] - pub unsafe fn _Unwind_GetIP(ctx: *_Unwind_Context) -> libc::uintptr_t { + pub unsafe fn _Unwind_GetIP(ctx: *mut _Unwind_Context) -> libc::uintptr_t { #[repr(C)] enum _Unwind_VRS_Result { _UVRSR_OK = 0, @@ -608,7 +609,7 @@ mod imp { type _Unwind_Word = libc::c_uint; extern { - fn _Unwind_VRS_Get(ctx: *_Unwind_Context, + fn _Unwind_VRS_Get(ctx: *mut _Unwind_Context, klass: _Unwind_VRS_RegClass, word: _Unwind_Word, repr: _Unwind_VRS_DataRepresentation, @@ -627,8 +628,8 @@ mod imp { // a no-op #[cfg(target_os = "android")] #[cfg(target_os = "linux", target_arch = "arm")] - pub unsafe fn _Unwind_FindEnclosingFunction(pc: *libc::c_void) - -> *libc::c_void + pub unsafe fn _Unwind_FindEnclosingFunction(pc: *mut libc::c_void) + -> *mut libc::c_void { pc } @@ -677,7 +678,7 @@ mod imp { extern "system" fn(libc::HANDLE, u64, *mut u64, *mut SYMBOL_INFO) -> libc::BOOL; type SymInitializeFn = - extern "system" fn(libc::HANDLE, *libc::c_void, + extern "system" fn(libc::HANDLE, *mut libc::c_void, libc::BOOL) -> libc::BOOL; type SymCleanupFn = extern "system" fn(libc::HANDLE) -> libc::BOOL; @@ -685,8 +686,8 @@ mod imp { type StackWalk64Fn = extern "system" fn(libc::DWORD, libc::HANDLE, libc::HANDLE, *mut STACKFRAME64, *mut arch::CONTEXT, - *libc::c_void, *libc::c_void, - *libc::c_void, *libc::c_void) -> libc::BOOL; + *mut libc::c_void, *mut libc::c_void, + *mut libc::c_void, *mut libc::c_void) -> libc::BOOL; static MAX_SYM_NAME: uint = 2000; static IMAGE_FILE_MACHINE_I386: libc::DWORD = 0x014c; @@ -735,7 +736,7 @@ mod imp { AddrFrame: ADDRESS64, AddrStack: ADDRESS64, AddrBStore: ADDRESS64, - FuncTableEntry: *libc::c_void, + FuncTableEntry: *mut libc::c_void, Params: [u64, ..4], Far: libc::BOOL, Virtual: libc::BOOL, @@ -924,7 +925,7 @@ mod imp { macro_rules! sym( ($e:expr, $t:ident) => (unsafe { match lib.symbol($e) { - Ok(f) => mem::transmute::<*u8, $t>(f), + Ok(f) => mem::transmute::<*mut u8, $t>(f), Err(..) => return Ok(()) } }) ) @@ -944,7 +945,7 @@ mod imp { let image = arch::init_frame(&mut frame, &context); // Initialize this process's symbols - let ret = SymInitialize(process, 0 as *libc::c_void, libc::TRUE); + let ret = SymInitialize(process, 0 as *mut libc::c_void, libc::TRUE); if ret != libc::TRUE { return Ok(()) } let _c = Cleanup { handle: process, SymCleanup: SymCleanup }; @@ -952,8 +953,10 @@ mod imp { let mut i = 0i; try!(write!(w, "stack backtrace:\n")); while StackWalk64(image, process, thread, &mut frame, &mut context, - 0 as *libc::c_void, 0 as *libc::c_void, - 0 as *libc::c_void, 0 as *libc::c_void) == libc::TRUE{ + 0 as *mut libc::c_void, + 0 as *mut libc::c_void, + 0 as *mut libc::c_void, + 0 as *mut libc::c_void) == libc::TRUE{ let addr = frame.AddrPC.Offset; if addr == frame.AddrReturn.Offset || addr == 0 || frame.AddrReturn.Offset == 0 { break } diff --git a/src/libstd/rt/mod.rs b/src/libstd/rt/mod.rs index 66e7059422b..4490977bde6 100644 --- a/src/libstd/rt/mod.rs +++ b/src/libstd/rt/mod.rs @@ -51,6 +51,8 @@ Several modules in `core` are clients of `rt`: */ +#![experimental] + // FIXME: this should not be here. #![allow(missing_doc)] @@ -79,7 +81,7 @@ mod util; /// the crate's logging flags, registering GC /// metadata, and storing the process arguments. #[allow(experimental)] -pub fn init(argc: int, argv: **u8) { +pub fn init(argc: int, argv: *const *const u8) { rustrt::init(argc, argv); unsafe { unwind::register(failure::on_fail); } } diff --git a/src/libstd/rtdeps.rs b/src/libstd/rtdeps.rs index f8bfde52261..0ffac99775c 100644 --- a/src/libstd/rtdeps.rs +++ b/src/libstd/rtdeps.rs @@ -12,6 +12,8 @@ //! the standard library This varies per-platform, but these libraries are //! necessary for running libstd. +#![experimental] + // All platforms need to link to rustrt #[link(name = "rust_builtin", kind = "static")] extern {} diff --git a/src/libstd/sync/mod.rs b/src/libstd/sync/mod.rs index 5f45ce25502..cc32818baa4 100644 --- a/src/libstd/sync/mod.rs +++ b/src/libstd/sync/mod.rs @@ -15,6 +15,8 @@ //! and/or blocking at all, but rather provide the necessary tools to build //! other types of concurrent primitives. +#![experimental] + pub use core_sync::{atomics, deque, mpmc_bounded_queue, mpsc_queue, spsc_queue}; pub use core_sync::{Arc, Weak, Mutex, MutexGuard, Condvar, Barrier}; pub use core_sync::{RWLock, RWLockReadGuard, RWLockWriteGuard}; diff --git a/src/libstd/task.rs b/src/libstd/task.rs index dad241002f8..c20cbea0ae7 100644 --- a/src/libstd/task.rs +++ b/src/libstd/task.rs @@ -91,6 +91,8 @@ //! # } //! ``` +#![experimental] + use any::Any; use comm::channel; use io::{Writer, stdio}; @@ -511,10 +513,10 @@ mod test { let (tx, rx) = channel::<uint>(); let x = box 1; - let x_in_parent = (&*x) as *int as uint; + let x_in_parent = (&*x) as *const int as uint; spawnfn(proc() { - let x_in_child = (&*x) as *int as uint; + let x_in_child = (&*x) as *const int as uint; tx.send(x_in_child); }); @@ -630,9 +632,11 @@ mod test { let mut reader = ChanReader::new(rx); let stdout = ChanWriter::new(tx); - TaskBuilder::new().stdout(box stdout as Box<Writer + Send>).try(proc() { - print!("Hello, world!"); - }).unwrap(); + let r = TaskBuilder::new().stdout(box stdout as Box<Writer + Send>) + .try(proc() { + print!("Hello, world!"); + }); + assert!(r.is_ok()); let output = reader.read_to_str().unwrap(); assert_eq!(output, "Hello, world!".to_string()); @@ -647,7 +651,7 @@ fn task_abort_no_kill_runtime() { use std::io::timer; use mem; - let mut tb = TaskBuilder::new(); + let tb = TaskBuilder::new(); let rx = tb.try_future(proc() {}); mem::drop(rx); timer::sleep(1000); diff --git a/src/libstd/to_str.rs b/src/libstd/to_str.rs index 5deb7f151bb..e51e2c4d9ce 100644 --- a/src/libstd/to_str.rs +++ b/src/libstd/to_str.rs @@ -14,6 +14,8 @@ The `ToStr` trait for converting to strings */ +#![experimental] + use fmt; use string::String; |
