diff options
| author | Erick Tryzelaar <erick.tryzelaar@gmail.com> | 2013-03-01 07:01:48 -0800 |
|---|---|---|
| committer | Erick Tryzelaar <erick.tryzelaar@gmail.com> | 2013-03-01 07:01:48 -0800 |
| commit | 85fecd0ba77066e604cec9d3866b76edc626b5d3 (patch) | |
| tree | a375b9e61af4c5e105b58271c9381fdaf58d31b0 /src/libstd | |
| parent | d2c4b6492dbccc1bb60f163ac583467bc63abce6 (diff) | |
| parent | a660bb362ce5a39014fb274367e6361d4deb8a7d (diff) | |
| download | rust-85fecd0ba77066e604cec9d3866b76edc626b5d3.tar.gz rust-85fecd0ba77066e604cec9d3866b76edc626b5d3.zip | |
Merge remote-tracking branch 'remotes/origin/incoming' into incoming
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/arc.rs | 79 | ||||
| -rw-r--r-- | src/libstd/arena.rs | 2 | ||||
| -rw-r--r-- | src/libstd/bitv.rs | 8 | ||||
| -rw-r--r-- | src/libstd/deque.rs | 5 | ||||
| -rw-r--r-- | src/libstd/ebml.rs | 6 | ||||
| -rw-r--r-- | src/libstd/flatpipes.rs | 3 | ||||
| -rw-r--r-- | src/libstd/future.rs | 6 | ||||
| -rw-r--r-- | src/libstd/getopts.rs | 2 | ||||
| -rw-r--r-- | src/libstd/json.rs | 1 | ||||
| -rw-r--r-- | src/libstd/net_tcp.rs | 2 | ||||
| -rw-r--r-- | src/libstd/net_url.rs | 168 | ||||
| -rw-r--r-- | src/libstd/oldmap.rs | 8 | ||||
| -rw-r--r-- | src/libstd/priority_queue.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sha1.rs | 4 | ||||
| -rw-r--r-- | src/libstd/sort.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sync.rs | 25 | ||||
| -rw-r--r-- | src/libstd/test.rs | 24 | ||||
| -rw-r--r-- | src/libstd/time.rs | 19 | ||||
| -rw-r--r-- | src/libstd/treemap.rs | 16 | ||||
| -rw-r--r-- | src/libstd/uv_global_loop.rs | 2 | ||||
| -rw-r--r-- | src/libstd/uv_iotask.rs | 214 | ||||
| -rw-r--r-- | src/libstd/uv_ll.rs | 3 | ||||
| -rw-r--r-- | src/libstd/workcache.rs | 10 |
23 files changed, 269 insertions, 342 deletions
diff --git a/src/libstd/arc.rs b/src/libstd/arc.rs index f258e649122..69c5026cbd1 100644 --- a/src/libstd/arc.rs +++ b/src/libstd/arc.rs @@ -21,7 +21,7 @@ use core::cell::Cell; use core::pipes; use core::prelude::*; use core::private::{SharedMutableState, shared_mutable_state}; -use core::private::{clone_shared_mutable_state, unwrap_shared_mutable_state}; +use core::private::{clone_shared_mutable_state}; use core::private::{get_shared_mutable_state, get_shared_immutable_state}; use core::ptr; use core::task; @@ -30,7 +30,7 @@ use core::util; /// As sync::condvar, a mechanism for unlock-and-descheduling and signalling. pub struct Condvar { is_mutex: bool, failed: &mut bool, cond: &sync::Condvar } -impl &Condvar { +pub impl &Condvar { /// Atomically exit the associated ARC and block until a signal is sent. #[inline(always)] fn wait() { self.wait_on(0) } @@ -104,20 +104,6 @@ pub fn clone<T:Const + Owned>(rc: &ARC<T>) -> ARC<T> { ARC { x: unsafe { clone_shared_mutable_state(&rc.x) } } } -/** - * Retrieve the data back out of the ARC. This function blocks until the - * reference given to it is the last existing one, and then unwrap the data - * instead of destroying it. - * - * If multiple tasks call unwrap, all but the first will fail. Do not call - * unwrap from a task that holds another reference to the same ARC; it is - * guaranteed to deadlock. - */ -pub fn unwrap<T:Const + Owned>(rc: ARC<T>) -> T { - let ARC { x: x } = rc; - unsafe { unwrap_shared_mutable_state(x) } -} - impl<T:Const + Owned> Clone for ARC<T> { fn clone(&self) -> ARC<T> { clone(self) @@ -158,7 +144,7 @@ impl<T:Owned> Clone for MutexARC<T> { } } -impl<T:Owned> &MutexARC<T> { +pub impl<T:Owned> &MutexARC<T> { /** * Access the underlying mutable data with mutual exclusion from other @@ -213,23 +199,6 @@ impl<T:Owned> &MutexARC<T> { } } -/** - * Retrieves the data, blocking until all other references are dropped, - * exactly as arc::unwrap. - * - * Will additionally fail if another task has failed while accessing the arc. - */ -// FIXME(#3724) make this a by-move method on the arc -pub fn unwrap_mutex_arc<T:Owned>(arc: MutexARC<T>) -> T { - let MutexARC { x: x } = arc; - let inner = unsafe { unwrap_shared_mutable_state(x) }; - let MutexARCInner { failed: failed, data: data, _ } = inner; - if failed { - fail!(~"Can't unwrap poisoned MutexARC - another task failed inside!") - } - data -} - // Common code for {mutex.access,rwlock.write}{,_cond}. #[inline(always)] #[doc(hidden)] @@ -301,7 +270,7 @@ pub fn rw_arc_with_condvars<T:Const + Owned>( RWARC { x: unsafe { shared_mutable_state(data) }, cant_nest: () } } -impl<T:Const + Owned> RWARC<T> { +pub impl<T:Const + Owned> RWARC<T> { /// Duplicate a rwlock-protected ARC, as arc::clone. fn clone(&self) -> RWARC<T> { RWARC { x: unsafe { clone_shared_mutable_state(&self.x) }, @@ -310,7 +279,7 @@ impl<T:Const + Owned> RWARC<T> { } -impl<T:Const + Owned> &RWARC<T> { +pub impl<T:Const + Owned> &RWARC<T> { /** * Access the underlying data mutably. Locks the rwlock in write mode; * other readers and writers will block. @@ -411,24 +380,6 @@ impl<T:Const + Owned> &RWARC<T> { } } -/** - * Retrieves the data, blocking until all other references are dropped, - * exactly as arc::unwrap. - * - * Will additionally fail if another task has failed while accessing the arc - * in write mode. - */ -// FIXME(#3724) make this a by-move method on the arc -pub fn unwrap_rw_arc<T:Const + Owned>(arc: RWARC<T>) -> T { - let RWARC { x: x, _ } = arc; - let inner = unsafe { unwrap_shared_mutable_state(x) }; - let RWARCInner { failed: failed, data: data, _ } = inner; - if failed { - fail!(~"Can't unwrap poisoned RWARC - another task failed inside!") - } - data -} - // Borrowck rightly complains about immutably aliasing the rwlock in order to // lock it. This wraps the unsafety, with the justification that the 'lock' // field is never overwritten; only 'failed' and 'data'. @@ -445,7 +396,7 @@ pub enum RWWriteMode<T> = /// The "read permission" token used for RWARC.write_downgrade(). pub enum RWReadMode<T> = (&T, sync::RWlockReadMode); -impl<T:Const + Owned> &RWWriteMode<T> { +pub impl<T:Const + Owned> &RWWriteMode<T> { /// Access the pre-downgrade RWARC in write mode. fn write<U>(blk: fn(x: &mut T) -> U) -> U { match *self { @@ -475,7 +426,7 @@ impl<T:Const + Owned> &RWWriteMode<T> { } } -impl<T:Const + Owned> &RWReadMode<T> { +pub impl<T:Const + Owned> &RWReadMode<T> { /// Access the post-downgrade rwlock in read mode. fn read<U>(blk: fn(x: &T) -> U) -> U { match *self { @@ -497,6 +448,7 @@ mod tests { use arc::*; use arc; + use core::cell::Cell; use core::option::{Some, None}; use core::option; use core::pipes; @@ -585,21 +537,6 @@ mod tests { } } #[test] #[should_fail] #[ignore(cfg(windows))] - pub fn test_mutex_arc_unwrap_poison() { - let arc = MutexARC(1); - let arc2 = ~(&arc).clone(); - let (p, c) = comm::stream(); - do task::spawn || { - do arc2.access |one| { - c.send(()); - assert *one == 2; - } - } - let _ = p.recv(); - let one = unwrap_mutex_arc(arc); - assert one == 1; - } - #[test] #[should_fail] #[ignore(cfg(windows))] pub fn test_rw_arc_poison_wr() { let arc = ~RWARC(1); let arc2 = ~arc.clone(); diff --git a/src/libstd/arena.rs b/src/libstd/arena.rs index 177932aa072..a30ee94a42b 100644 --- a/src/libstd/arena.rs +++ b/src/libstd/arena.rs @@ -161,7 +161,7 @@ unsafe fn un_bitpack_tydesc_ptr(p: uint) -> (*TypeDesc, bool) { (reinterpret_cast(&(p & !1)), p & 1 == 1) } -impl &Arena { +pub impl &Arena { // Functions for the POD part of the arena fn alloc_pod_grow(n_bytes: uint, align: uint) -> *u8 { // Allocate a new chunk. diff --git a/src/libstd/bitv.rs b/src/libstd/bitv.rs index 30d7b825add..cf278b07c9d 100644 --- a/src/libstd/bitv.rs +++ b/src/libstd/bitv.rs @@ -27,7 +27,7 @@ fn small_mask(nbits: uint) -> uint { (1 << nbits) - 1 } -impl SmallBitv { +pub impl SmallBitv { static fn new(bits: uint) -> SmallBitv { SmallBitv {bits: bits} } @@ -124,7 +124,7 @@ fn big_mask(nbits: uint, elem: uint) -> uint { } } -impl BigBitv { +pub impl BigBitv { static fn new(storage: ~[uint]) -> BigBitv { BigBitv {storage: storage} } @@ -256,7 +256,7 @@ priv impl Bitv { } -impl Bitv { +pub impl Bitv { static fn new(nbits: uint, init: bool) -> Bitv { let rep = if nbits <= uint::bits { Small(~SmallBitv::new(if init {!0} else {0})) @@ -591,7 +591,7 @@ pub struct BitvSet { priv bitv: BigBitv } -impl BitvSet { +pub impl BitvSet { /// Creates a new bit vector set with initially no contents static fn new() -> BitvSet { BitvSet{ size: 0, bitv: BigBitv::new(~[0]) } diff --git a/src/libstd/deque.rs b/src/libstd/deque.rs index 0ac76cefd6b..f6fcf6c8d3b 100644 --- a/src/libstd/deque.rs +++ b/src/libstd/deque.rs @@ -37,7 +37,7 @@ impl<T> Mutable for Deque<T> { } } -impl<T> Deque<T> { +pub impl<T> Deque<T> { static pure fn new() -> Deque<T> { Deque{nelts: 0, lo: 0, hi: 0, elts: vec::from_fn(initial_capacity, |_| None)} @@ -116,6 +116,9 @@ fn get<T>(elts: &r/[Option<T>], i: uint) -> &r/T { #[cfg(test)] mod tests { use super::*; + use core::cmp::Eq; + use core::kinds::{Durable, Copy}; + use core::prelude::debug; #[test] fn test_simple() { diff --git a/src/libstd/ebml.rs b/src/libstd/ebml.rs index 84df1785503..7d04f676079 100644 --- a/src/libstd/ebml.rs +++ b/src/libstd/ebml.rs @@ -279,7 +279,7 @@ pub mod reader { } } - impl Decoder { + pub impl Decoder { fn read_opaque<R>(&self, op: fn(Doc) -> R) -> R { do self.push_doc(self.next_doc(EsOpaque)) { op(copy self.parent) @@ -451,7 +451,7 @@ pub mod writer { } // FIXME (#2741): Provide a function to write the standard ebml header. - impl Encoder { + pub impl Encoder { fn start_tag(tag_id: uint) { debug!("Start tag %u", tag_id); @@ -571,7 +571,7 @@ pub mod writer { } } - impl Encoder { + pub impl Encoder { fn emit_opaque(&self, f: fn()) { do self.wr_tag(EsOpaque as uint) { f() diff --git a/src/libstd/flatpipes.rs b/src/libstd/flatpipes.rs index 2ee994bdf32..73dbe4bea57 100644 --- a/src/libstd/flatpipes.rs +++ b/src/libstd/flatpipes.rs @@ -636,6 +636,7 @@ mod test { use DefaultEncoder = json::Encoder; use DefaultDecoder = json::Decoder; + use flatpipes::{Flattener, Unflattener}; use flatpipes::flatteners::*; use flatpipes::bytepipes::*; use flatpipes::pod; @@ -647,7 +648,7 @@ mod test { use core::dvec::DVec; use core::int; - use core::io::BytesReader; + use core::io::{BytesReader, BytesWriter}; use core::io; use core::prelude::*; use core::result; diff --git a/src/libstd/future.rs b/src/libstd/future.rs index 7f48466ed0a..c5775406125 100644 --- a/src/libstd/future.rs +++ b/src/libstd/future.rs @@ -49,14 +49,14 @@ priv enum FutureState<A> { } /// Methods on the `future` type -impl<A:Copy> Future<A> { +pub impl<A:Copy> Future<A> { fn get() -> A { //! Get the value of the future *(self.get_ref()) } } -impl<A> Future<A> { +pub impl<A> Future<A> { pure fn get_ref(&self) -> &self/A { /*! @@ -150,7 +150,7 @@ pub mod test { use future::*; - use core::comm::oneshot; + use core::comm::{oneshot, send_one}; use core::task; #[test] diff --git a/src/libstd/getopts.rs b/src/libstd/getopts.rs index 3726943321c..dd205583259 100644 --- a/src/libstd/getopts.rs +++ b/src/libstd/getopts.rs @@ -445,7 +445,7 @@ pub fn opt_default(mm: &Matches, nm: &str, def: &str) -> Option<~str> { } #[deriving_eq] -enum FailType { +pub enum FailType { ArgumentMissing_, UnrecognizedOption_, OptionMissing_, diff --git a/src/libstd/json.rs b/src/libstd/json.rs index c6e76aa1a68..d1a65517aad 100644 --- a/src/libstd/json.rs +++ b/src/libstd/json.rs @@ -1208,6 +1208,7 @@ mod tests { use core::prelude::*; use json::*; + use serialize; use core::result; use core::hashmap::linear::LinearMap; diff --git a/src/libstd/net_tcp.rs b/src/libstd/net_tcp.rs index 8835cdfb105..dcbf7e60d89 100644 --- a/src/libstd/net_tcp.rs +++ b/src/libstd/net_tcp.rs @@ -820,7 +820,7 @@ pub fn socket_buf(sock: TcpSocket) -> TcpSocketBuf { } /// Convenience methods extending `net::tcp::tcp_socket` -impl TcpSocket { +pub impl TcpSocket { pub fn read_start() -> result::Result<@Port< result::Result<~[u8], TcpErrData>>, TcpErrData> { read_start(&self) diff --git a/src/libstd/net_url.rs b/src/libstd/net_url.rs index 29cb57c01be..08b7b3d6ae5 100644 --- a/src/libstd/net_url.rs +++ b/src/libstd/net_url.rs @@ -730,6 +730,91 @@ impl to_bytes::IterBytes for Url { } } +// Put a few tests outside of the 'test' module so they can test the internal +// functions and those functions don't need 'pub' + +#[test] +fn test_split_char_first() { + let (u,v) = split_char_first(~"hello, sweet world", ','); + assert u == ~"hello"; + assert v == ~" sweet world"; + + let (u,v) = split_char_first(~"hello sweet world", ','); + assert u == ~"hello sweet world"; + assert v == ~""; +} + +#[test] +fn test_get_authority() { + let (u, h, p, r) = get_authority( + "//user:pass@rust-lang.org/something").unwrap(); + assert u == Some(UserInfo::new(~"user", Some(~"pass"))); + assert h == ~"rust-lang.org"; + assert p.is_none(); + assert r == ~"/something"; + + let (u, h, p, r) = get_authority( + "//rust-lang.org:8000?something").unwrap(); + assert u.is_none(); + assert h == ~"rust-lang.org"; + assert p == Some(~"8000"); + assert r == ~"?something"; + + let (u, h, p, r) = get_authority( + "//rust-lang.org#blah").unwrap(); + assert u.is_none(); + assert h == ~"rust-lang.org"; + assert p.is_none(); + assert r == ~"#blah"; + + // ipv6 tests + let (_, h, _, _) = get_authority( + "//2001:0db8:85a3:0042:0000:8a2e:0370:7334#blah").unwrap(); + assert h == ~"2001:0db8:85a3:0042:0000:8a2e:0370:7334"; + + let (_, h, p, _) = get_authority( + "//2001:0db8:85a3:0042:0000:8a2e:0370:7334:8000#blah").unwrap(); + assert h == ~"2001:0db8:85a3:0042:0000:8a2e:0370:7334"; + assert p == Some(~"8000"); + + let (u, h, p, _) = get_authority( + "//us:p@2001:0db8:85a3:0042:0000:8a2e:0370:7334:8000#blah" + ).unwrap(); + assert u == Some(UserInfo::new(~"us", Some(~"p"))); + assert h == ~"2001:0db8:85a3:0042:0000:8a2e:0370:7334"; + assert p == Some(~"8000"); + + // invalid authorities; + assert get_authority("//user:pass@rust-lang:something").is_err(); + assert get_authority("//user@rust-lang:something:/path").is_err(); + assert get_authority( + "//2001:0db8:85a3:0042:0000:8a2e:0370:7334:800a").is_err(); + assert get_authority( + "//2001:0db8:85a3:0042:0000:8a2e:0370:7334:8000:00").is_err(); + + // these parse as empty, because they don't start with '//' + let (_, h, _, _) = get_authority(~"user:pass@rust-lang").unwrap(); + assert h == ~""; + let (_, h, _, _) = get_authority(~"rust-lang.org").unwrap(); + assert h == ~""; +} + +#[test] +fn test_get_path() { + let (p, r) = get_path("/something+%20orother", true).unwrap(); + assert p == ~"/something+ orother"; + assert r == ~""; + let (p, r) = get_path("test@email.com#fragment", false).unwrap(); + assert p == ~"test@email.com"; + assert r == ~"#fragment"; + let (p, r) = get_path(~"/gen/:addr=?q=v", false).unwrap(); + assert p == ~"/gen/:addr="; + assert r == ~"?q=v"; + + //failure cases + assert get_path(~"something?q", true).is_err(); +} + #[cfg(test)] mod tests { use core::prelude::*; @@ -737,92 +822,11 @@ mod tests { use net_url::*; use net_url::UserInfo; + use core::hashmap::linear::LinearMap; use core::result; use core::str; #[test] - pub fn test_split_char_first() { - let (u,v) = split_char_first(~"hello, sweet world", ','); - assert u == ~"hello"; - assert v == ~" sweet world"; - - let (u,v) = split_char_first(~"hello sweet world", ','); - assert u == ~"hello sweet world"; - assert v == ~""; - } - - #[test] - pub fn test_get_authority() { - let (u, h, p, r) = get_authority( - "//user:pass@rust-lang.org/something").unwrap(); - assert u == Some(UserInfo::new(~"user", Some(~"pass"))); - assert h == ~"rust-lang.org"; - assert p.is_none(); - assert r == ~"/something"; - - let (u, h, p, r) = get_authority( - "//rust-lang.org:8000?something").unwrap(); - assert u.is_none(); - assert h == ~"rust-lang.org"; - assert p == Some(~"8000"); - assert r == ~"?something"; - - let (u, h, p, r) = get_authority( - "//rust-lang.org#blah").unwrap(); - assert u.is_none(); - assert h == ~"rust-lang.org"; - assert p.is_none(); - assert r == ~"#blah"; - - // ipv6 tests - let (_, h, _, _) = get_authority( - "//2001:0db8:85a3:0042:0000:8a2e:0370:7334#blah").unwrap(); - assert h == ~"2001:0db8:85a3:0042:0000:8a2e:0370:7334"; - - let (_, h, p, _) = get_authority( - "//2001:0db8:85a3:0042:0000:8a2e:0370:7334:8000#blah").unwrap(); - assert h == ~"2001:0db8:85a3:0042:0000:8a2e:0370:7334"; - assert p == Some(~"8000"); - - let (u, h, p, _) = get_authority( - "//us:p@2001:0db8:85a3:0042:0000:8a2e:0370:7334:8000#blah" - ).unwrap(); - assert u == Some(UserInfo::new(~"us", Some(~"p"))); - assert h == ~"2001:0db8:85a3:0042:0000:8a2e:0370:7334"; - assert p == Some(~"8000"); - - // invalid authorities; - assert get_authority("//user:pass@rust-lang:something").is_err(); - assert get_authority("//user@rust-lang:something:/path").is_err(); - assert get_authority( - "//2001:0db8:85a3:0042:0000:8a2e:0370:7334:800a").is_err(); - assert get_authority( - "//2001:0db8:85a3:0042:0000:8a2e:0370:7334:8000:00").is_err(); - - // these parse as empty, because they don't start with '//' - let (_, h, _, _) = get_authority(~"user:pass@rust-lang").unwrap(); - assert h == ~""; - let (_, h, _, _) = get_authority(~"rust-lang.org").unwrap(); - assert h == ~""; - } - - #[test] - pub fn test_get_path() { - let (p, r) = get_path("/something+%20orother", true).unwrap(); - assert p == ~"/something+ orother"; - assert r == ~""; - let (p, r) = get_path("test@email.com#fragment", false).unwrap(); - assert p == ~"test@email.com"; - assert r == ~"#fragment"; - let (p, r) = get_path(~"/gen/:addr=?q=v", false).unwrap(); - assert p == ~"/gen/:addr="; - assert r == ~"?q=v"; - - //failure cases - assert get_path(~"something?q", true).is_err(); - } - - #[test] pub fn test_url_parse() { let url = ~"http://user:pass@rust-lang.org/doc?s=v#something"; diff --git a/src/libstd/oldmap.rs b/src/libstd/oldmap.rs index 53692cd3be5..1d21f749b32 100644 --- a/src/libstd/oldmap.rs +++ b/src/libstd/oldmap.rs @@ -134,7 +134,9 @@ pub mod chained { } self.chains = new_chains; } + } + pub impl<K:Eq + IterBytes + Hash,V> T<K, V> { pure fn each_entry(blk: fn(@Entry<K,V>) -> bool) { // n.b. we can't use vec::iter() here because self.chains // is stored in a mutable location. @@ -168,7 +170,7 @@ pub mod chained { } } - impl<K:Eq + IterBytes + Hash,V> T<K, V> { + pub impl<K:Eq + IterBytes + Hash,V> T<K, V> { pure fn contains_key(&self, k: &K) -> bool { let hash = k.hash_keyed(0,0) as uint; match self.search_tbl(k, hash) { @@ -252,7 +254,7 @@ pub mod chained { } } - impl<K:Eq + IterBytes + Hash + Copy,V:Copy> T<K, V> { + pub impl<K:Eq + IterBytes + Hash + Copy,V:Copy> T<K, V> { pure fn find(&self, k: &K) -> Option<V> { match self.search_tbl(k, k.hash_keyed(0,0) as uint) { NotFound => None, @@ -325,7 +327,7 @@ pub mod chained { } } - impl<K:Eq + IterBytes + Hash + Copy + ToStr,V:ToStr + Copy> T<K, V> { + pub impl<K:Eq + IterBytes + Hash + Copy + ToStr,V:ToStr + Copy> T<K, V> { fn to_writer(wr: io::Writer) { if self.count == 0u { wr.write_str(~"{}"); diff --git a/src/libstd/priority_queue.rs b/src/libstd/priority_queue.rs index f642bf52f65..4b92bd7543a 100644 --- a/src/libstd/priority_queue.rs +++ b/src/libstd/priority_queue.rs @@ -48,7 +48,7 @@ impl<T:Ord> Mutable for PriorityQueue<T> { fn clear(&mut self) { self.data.truncate(0) } } -impl <T:Ord> PriorityQueue<T> { +pub impl <T:Ord> PriorityQueue<T> { /// Returns the greatest item in the queue - fails if empty pure fn top(&self) -> &self/T { &self.data[0] } diff --git a/src/libstd/sha1.rs b/src/libstd/sha1.rs index 69c3de5ff62..e8c1413e90a 100644 --- a/src/libstd/sha1.rs +++ b/src/libstd/sha1.rs @@ -63,7 +63,7 @@ const k3: u32 = 0xCA62C1D6u32; /// Construct a `sha` object -pub fn sha1() -> Sha1 { +pub fn sha1() -> @Sha1 { struct Sha1State { h: ~[u32], len_low: u32, @@ -269,7 +269,7 @@ pub fn sha1() -> Sha1 { computed: false, work_buf: @mut vec::from_elem(work_buf_len, 0u32) }; - let mut sh = (st) as Sha1; + let mut sh = @st as @Sha1; sh.reset(); return sh; } diff --git a/src/libstd/sort.rs b/src/libstd/sort.rs index 75f38da5a19..43fab9df163 100644 --- a/src/libstd/sort.rs +++ b/src/libstd/sort.rs @@ -404,7 +404,7 @@ fn MergeState<T>() -> MergeState<T> { } } -impl<T:Copy + Ord> MergeState<T> { +pub impl<T:Copy + Ord> MergeState<T> { fn push_run(&self, run_base: uint, run_len: uint) { let tmp = RunState{base: run_base, len: run_len}; self.runs.push(tmp); diff --git a/src/libstd/sync.rs b/src/libstd/sync.rs index 1ff51e8bff0..39d3fd569a6 100644 --- a/src/libstd/sync.rs +++ b/src/libstd/sync.rs @@ -100,7 +100,7 @@ fn new_sem_and_signal(count: int, num_condvars: uint) } #[doc(hidden)] -impl<Q:Owned> &Sem<Q> { +pub impl<Q:Owned> &Sem<Q> { fn acquire() { let mut waiter_nobe = None; unsafe { @@ -136,7 +136,7 @@ impl<Q:Owned> &Sem<Q> { } // FIXME(#3154) move both copies of this into Sem<Q>, and unify the 2 structs #[doc(hidden)] -impl &Sem<()> { +pub impl &Sem<()> { fn access<U>(blk: fn() -> U) -> U { let mut release = None; unsafe { @@ -149,7 +149,7 @@ impl &Sem<()> { } } #[doc(hidden)] -impl &Sem<~[Waitqueue]> { +pub impl &Sem<~[Waitqueue]> { fn access<U>(blk: fn() -> U) -> U { let mut release = None; unsafe { @@ -192,7 +192,7 @@ pub struct Condvar { priv sem: &Sem<~[Waitqueue]> } impl Drop for Condvar { fn finalize(&self) {} } -impl &Condvar { +pub impl &Condvar { /** * Atomically drop the associated lock, and block until a signal is sent. * @@ -344,7 +344,7 @@ fn check_cvar_bounds<U>(out_of_bounds: Option<uint>, id: uint, act: &str, } #[doc(hidden)] -impl &Sem<~[Waitqueue]> { +pub impl &Sem<~[Waitqueue]> { // The only other place that condvars get built is rwlock_write_mode. fn access_cond<U>(blk: fn(c: &Condvar) -> U) -> U { do self.access { blk(&Condvar { sem: self }) } @@ -370,7 +370,7 @@ impl Clone for Semaphore { } } -impl &Semaphore { +pub impl &Semaphore { /** * Acquire a resource represented by the semaphore. Blocks if necessary * until resource(s) become available. @@ -399,7 +399,7 @@ impl &Semaphore { * A task which fails while holding a mutex will unlock the mutex as it * unwinds. */ -struct Mutex { priv sem: Sem<~[Waitqueue]> } +pub struct Mutex { priv sem: Sem<~[Waitqueue]> } /// Create a new mutex, with one associated condvar. pub fn Mutex() -> Mutex { mutex_with_condvars(1) } @@ -418,7 +418,7 @@ impl Clone for Mutex { fn clone(&self) -> Mutex { Mutex { sem: Sem((*self.sem).clone()) } } } -impl &Mutex { +pub impl &Mutex { /// Run a function with ownership of the mutex. fn lock<U>(blk: fn() -> U) -> U { (&self.sem).access(blk) } @@ -447,7 +447,7 @@ struct RWlockInner { * A task which fails while holding an rwlock will unlock the rwlock as it * unwinds. */ -struct RWlock { +pub struct RWlock { priv order_lock: Semaphore, priv access_lock: Sem<~[Waitqueue]>, priv state: Exclusive<RWlockInner> @@ -467,7 +467,7 @@ pub fn rwlock_with_condvars(num_condvars: uint) -> RWlock { read_count: 0 }) } } -impl &RWlock { +pub impl &RWlock { /// Create a new handle to the rwlock. fn clone() -> RWlock { RWlock { order_lock: (&(self.order_lock)).clone(), @@ -688,7 +688,7 @@ impl Drop for RWlockWriteMode { fn finalize(&self) {} } pub struct RWlockReadMode { priv lock: &RWlock } impl Drop for RWlockReadMode { fn finalize(&self) {} } -impl &RWlockWriteMode { +pub impl &RWlockWriteMode { /// Access the pre-downgrade rwlock in write mode. fn write<U>(blk: fn() -> U) -> U { blk() } /// Access the pre-downgrade rwlock in write mode with a condvar. @@ -696,7 +696,7 @@ impl &RWlockWriteMode { blk(&Condvar { sem: &self.lock.access_lock }) } } -impl &RWlockReadMode { +pub impl &RWlockReadMode { /// Access the post-downgrade rwlock in read mode. fn read<U>(blk: fn() -> U) -> U { blk() } } @@ -712,6 +712,7 @@ mod tests { use sync::*; use core::cast; + use core::cell::Cell; use core::option; use core::pipes; use core::ptr; diff --git a/src/libstd/test.rs b/src/libstd/test.rs index bfeaf8400bc..49a8dff4a96 100644 --- a/src/libstd/test.rs +++ b/src/libstd/test.rs @@ -46,34 +46,10 @@ extern mod rustrt { // colons. This way if some test runner wants to arrange the tests // hierarchically it may. -#[cfg(stage0)] -pub enum TestName { - // Stage0 doesn't understand sendable &static/str yet - StaticTestName(&static/[u8]), - DynTestName(~str) -} - -#[cfg(stage0)] -impl ToStr for TestName { - pure fn to_str(&self) -> ~str { - match self { - &StaticTestName(s) => str::from_bytes(s), - &DynTestName(s) => s.to_str() - } - } -} - -#[cfg(stage1)] -#[cfg(stage2)] -#[cfg(stage3)] pub enum TestName { StaticTestName(&static/str), DynTestName(~str) } - -#[cfg(stage1)] -#[cfg(stage2)] -#[cfg(stage3)] impl ToStr for TestName { pure fn to_str(&self) -> ~str { match self { diff --git a/src/libstd/time.rs b/src/libstd/time.rs index c8379d3ef44..6e80665d80e 100644 --- a/src/libstd/time.rs +++ b/src/libstd/time.rs @@ -47,7 +47,7 @@ pub struct Timespec { sec: i64, nsec: i32 } * -1.2 seconds before the epoch is represented by `Timespec { sec: -2_i64, * nsec: 800_000_000_i32 }`. */ -impl Timespec { +pub impl Timespec { static pure fn new(sec: i64, nsec: i32) -> Timespec { assert nsec >= 0 && nsec < NSEC_PER_SEC; Timespec { sec: sec, nsec: nsec } @@ -208,7 +208,7 @@ pub pure fn strftime(format: &str, tm: &Tm) -> ~str { unsafe { do_strftime(format, tm) } } -impl Tm { +pub impl Tm { /// Convert time to the seconds from January 1, 1970 fn to_timespec() -> Timespec { unsafe { @@ -892,6 +892,7 @@ mod tests { use core::float; use core::os; use core::result; + use core::result::{Err, Ok}; use core::str; use core::u64; use core::uint; @@ -902,15 +903,13 @@ mod tests { const some_future_date: i64 = 1577836800i64; // 2020-01-01T00:00:00Z let tv1 = get_time(); - log(debug, ~"tv1=" + uint::to_str(tv1.sec as uint) + ~" sec + " - + uint::to_str(tv1.nsec as uint) + ~" nsec"); + debug!("tv1=%? sec + %? nsec", tv1.sec as uint, tv1.nsec as uint); assert tv1.sec > some_recent_date; assert tv1.nsec < 1000000000i32; let tv2 = get_time(); - log(debug, ~"tv2=" + uint::to_str(tv2.sec as uint) + ~" sec + " - + uint::to_str(tv2.nsec as uint) + ~" nsec"); + debug!("tv2=%? sec + %? nsec", tv2.sec as uint, tv2.nsec as uint); assert tv2.sec >= tv1.sec; assert tv2.sec < some_future_date; @@ -924,16 +923,16 @@ mod tests { let s0 = precise_time_s(); let ns1 = precise_time_ns(); - log(debug, ~"s0=" + float::to_str_digits(s0, 9u) + ~" sec"); + debug!("s0=%s sec", float::to_str_digits(s0, 9u)); assert s0 > 0.; let ns0 = (s0 * 1000000000.) as u64; - log(debug, ~"ns0=" + u64::to_str(ns0) + ~" ns"); + debug!("ns0=%? ns", ns0); - log(debug, ~"ns1=" + u64::to_str(ns1) + ~" ns"); + debug!("ns1=%? ns", ns0); assert ns1 >= ns0; let ns2 = precise_time_ns(); - log(debug, ~"ns2=" + u64::to_str(ns2) + ~" ns"); + debug!("ns2=%? ns", ns0); assert ns2 >= ns1; } diff --git a/src/libstd/treemap.rs b/src/libstd/treemap.rs index 0e593ba42d1..88e4ade4b82 100644 --- a/src/libstd/treemap.rs +++ b/src/libstd/treemap.rs @@ -177,7 +177,7 @@ impl<K:Ord,V> Map<K, V> for TreeMap<K, V> { } } -impl <K:Ord,V> TreeMap<K, V> { +pub impl <K:Ord,V> TreeMap<K, V> { /// Create an empty TreeMap static pure fn new() -> TreeMap<K, V> { TreeMap{root: None, length: 0} } @@ -207,8 +207,8 @@ pub struct TreeMapIterator<K, V> { /// Advance the iterator to the next node (in order) and return a /// tuple with a reference to the key and value. If there are no /// more nodes, return `None`. -fn map_next<K: Ord, V>(iter: &mut TreeMapIterator/&r<K, V>) - -> Option<(&r/K, &r/V)> { +pub fn map_next<K: Ord, V>(iter: &mut TreeMapIterator/&r<K, V>) + -> Option<(&r/K, &r/V)> { while !iter.stack.is_empty() || iter.node.is_some() { match *iter.node { Some(ref x) => { @@ -226,7 +226,7 @@ fn map_next<K: Ord, V>(iter: &mut TreeMapIterator/&r<K, V>) } /// Advance the iterator through the map -fn map_advance<K: Ord, V>(iter: &mut TreeMapIterator/&r<K, V>, +pub fn map_advance<K: Ord, V>(iter: &mut TreeMapIterator/&r<K, V>, f: fn((&r/K, &r/V)) -> bool) { loop { match map_next(iter) { @@ -480,7 +480,7 @@ impl<T:Ord> Set<T> for TreeSet<T> { } } -impl <T:Ord> TreeSet<T> { +pub impl <T:Ord> TreeSet<T> { /// Create an empty TreeSet static pure fn new() -> TreeSet<T> { TreeSet{map: TreeMap::new()} } @@ -518,7 +518,7 @@ struct TreeNode<K, V> { level: uint } -impl <K:Ord,V> TreeNode<K, V> { +pub impl <K:Ord,V> TreeNode<K, V> { #[inline(always)] static pure fn new(key: K, value: V) -> TreeNode<K, V> { TreeNode{key: key, value: value, left: None, right: None, level: 1} @@ -683,7 +683,11 @@ fn remove<K:Ord,V>(node: &mut Option<~TreeNode<K, V>>, key: &K) -> bool { #[cfg(test)] mod test_treemap { use super::*; + use core::cmp::{Ord, Eq}; + use core::option::{Some, Option, None}; + use core::rand; use core::str; + use core::vec; #[test] fn find_empty() { diff --git a/src/libstd/uv_global_loop.rs b/src/libstd/uv_global_loop.rs index 401cecf8811..37d9b3221b2 100644 --- a/src/libstd/uv_global_loop.rs +++ b/src/libstd/uv_global_loop.rs @@ -123,9 +123,11 @@ fn spawn_loop() -> IoTask { mod test { use core::prelude::*; + use get_gl = get; use uv::iotask; use uv::ll; use uv_global_loop::*; + use uv_iotask::IoTask; use core::iter; use core::libc; diff --git a/src/libstd/uv_iotask.rs b/src/libstd/uv_iotask.rs index 52956f152fe..14726a0854d 100644 --- a/src/libstd/uv_iotask.rs +++ b/src/libstd/uv_iotask.rs @@ -202,124 +202,120 @@ extern fn tear_down_close_cb(handle: *ll::uv_async_t) { } #[cfg(test)] -mod test { - use core::prelude::*; - - use uv::ll; - use uv_iotask::*; - - use core::iter; - use core::libc; - use core::ptr; - use core::task; - use core::pipes::{stream, Chan, SharedChan, Port}; - - extern fn async_close_cb(handle: *ll::uv_async_t) { - unsafe { - log(debug, fmt!("async_close_cb handle %?", handle)); - let exit_ch = &(*(ll::get_data_for_uv_handle(handle) - as *AhData)).exit_ch; - let exit_ch = exit_ch.clone(); - exit_ch.send(()); - } - } - extern fn async_handle_cb(handle: *ll::uv_async_t, status: libc::c_int) { - unsafe { - log(debug, - fmt!("async_handle_cb handle %? status %?",handle,status)); - ll::close(handle, async_close_cb); - } - } - struct AhData { - iotask: IoTask, - exit_ch: SharedChan<()> +extern fn async_close_cb(handle: *ll::uv_async_t) { + unsafe { + log(debug, fmt!("async_close_cb handle %?", handle)); + let exit_ch = &(*(ll::get_data_for_uv_handle(handle) + as *AhData)).exit_ch; + let exit_ch = exit_ch.clone(); + exit_ch.send(()); } - fn impl_uv_iotask_async(iotask: &IoTask) { - unsafe { - let async_handle = ll::async_t(); - let ah_ptr = ptr::addr_of(&async_handle); - let (exit_po, exit_ch) = stream::<()>(); - let ah_data = AhData { - iotask: iotask.clone(), - exit_ch: SharedChan(exit_ch) - }; - let ah_data_ptr: *AhData = unsafe { - ptr::to_unsafe_ptr(&ah_data) - }; - debug!("about to interact"); - do interact(iotask) |loop_ptr| { - unsafe { - debug!("interacting"); - ll::async_init(loop_ptr, ah_ptr, async_handle_cb); - ll::set_data_for_uv_handle( - ah_ptr, ah_data_ptr as *libc::c_void); - ll::async_send(ah_ptr); - } - }; - debug!("waiting for async close"); - exit_po.recv(); - } +} + +#[cfg(test)] +extern fn async_handle_cb(handle: *ll::uv_async_t, status: libc::c_int) { + unsafe { + log(debug, + fmt!("async_handle_cb handle %? status %?",handle,status)); + ll::close(handle, async_close_cb); } +} + +#[cfg(test)] +struct AhData { + iotask: IoTask, + exit_ch: SharedChan<()> +} - // this fn documents the bear minimum neccesary to roll your own - // high_level_loop - unsafe fn spawn_test_loop(exit_ch: ~Chan<()>) -> IoTask { - let (iotask_port, iotask_ch) = stream::<IoTask>(); - do task::spawn_sched(task::ManualThreads(1u)) { - debug!("about to run a test loop"); - run_loop(&iotask_ch); - exit_ch.send(()); +#[cfg(test)] +fn impl_uv_iotask_async(iotask: &IoTask) { + unsafe { + let async_handle = ll::async_t(); + let ah_ptr = ptr::addr_of(&async_handle); + let (exit_po, exit_ch) = stream::<()>(); + let ah_data = AhData { + iotask: iotask.clone(), + exit_ch: SharedChan(exit_ch) + }; + let ah_data_ptr: *AhData = unsafe { + ptr::to_unsafe_ptr(&ah_data) }; - return iotask_port.recv(); + debug!("about to interact"); + do interact(iotask) |loop_ptr| { + unsafe { + debug!("interacting"); + ll::async_init(loop_ptr, ah_ptr, async_handle_cb); + ll::set_data_for_uv_handle( + ah_ptr, ah_data_ptr as *libc::c_void); + ll::async_send(ah_ptr); + } + }; + debug!("waiting for async close"); + exit_po.recv(); } +} - extern fn lifetime_handle_close(handle: *libc::c_void) { - unsafe { - log(debug, fmt!("lifetime_handle_close ptr %?", handle)); - } - } +// this fn documents the bear minimum neccesary to roll your own +// high_level_loop +#[cfg(test)] +unsafe fn spawn_test_loop(exit_ch: ~Chan<()>) -> IoTask { + let (iotask_port, iotask_ch) = stream::<IoTask>(); + do task::spawn_sched(task::ManualThreads(1u)) { + debug!("about to run a test loop"); + run_loop(&iotask_ch); + exit_ch.send(()); + }; + return iotask_port.recv(); +} - extern fn lifetime_async_callback(handle: *libc::c_void, - status: libc::c_int) { - log(debug, fmt!("lifetime_handle_close ptr %? status %?", - handle, status)); +#[cfg(test)] +extern fn lifetime_handle_close(handle: *libc::c_void) { + unsafe { + log(debug, fmt!("lifetime_handle_close ptr %?", handle)); } +} - #[test] - fn test_uv_iotask_async() { - unsafe { - let (exit_po, exit_ch) = stream::<()>(); - let iotask = &spawn_test_loop(~exit_ch); - - debug!("spawned iotask"); - - // using this handle to manage the lifetime of the - // high_level_loop, as it will exit the first time one of - // the impl_uv_hl_async() is cleaned up with no one ref'd - // handles on the loop (Which can happen under - // race-condition type situations.. this ensures that the - // loop lives until, at least, all of the - // impl_uv_hl_async() runs have been called, at least. - let (work_exit_po, work_exit_ch) = stream::<()>(); - let work_exit_ch = SharedChan(work_exit_ch); - for iter::repeat(7u) { - let iotask_clone = iotask.clone(); - let work_exit_ch_clone = work_exit_ch.clone(); - do task::spawn_sched(task::ManualThreads(1u)) { - debug!("async"); - impl_uv_iotask_async(&iotask_clone); - debug!("done async"); - work_exit_ch_clone.send(()); - }; - }; - for iter::repeat(7u) { - debug!("waiting"); - work_exit_po.recv(); +#[cfg(test)] +extern fn lifetime_async_callback(handle: *libc::c_void, + status: libc::c_int) { + log(debug, fmt!("lifetime_handle_close ptr %? status %?", + handle, status)); +} + +#[test] +fn test_uv_iotask_async() { + unsafe { + let (exit_po, exit_ch) = stream::<()>(); + let iotask = &spawn_test_loop(~exit_ch); + + debug!("spawned iotask"); + + // using this handle to manage the lifetime of the + // high_level_loop, as it will exit the first time one of + // the impl_uv_hl_async() is cleaned up with no one ref'd + // handles on the loop (Which can happen under + // race-condition type situations.. this ensures that the + // loop lives until, at least, all of the + // impl_uv_hl_async() runs have been called, at least. + let (work_exit_po, work_exit_ch) = stream::<()>(); + let work_exit_ch = SharedChan(work_exit_ch); + for iter::repeat(7u) { + let iotask_clone = iotask.clone(); + let work_exit_ch_clone = work_exit_ch.clone(); + do task::spawn_sched(task::ManualThreads(1u)) { + debug!("async"); + impl_uv_iotask_async(&iotask_clone); + debug!("done async"); + work_exit_ch_clone.send(()); }; - log(debug, ~"sending teardown_loop msg.."); - exit(iotask); - exit_po.recv(); - log(debug, ~"after recv on exit_po.. exiting.."); - } + }; + for iter::repeat(7u) { + debug!("waiting"); + work_exit_po.recv(); + }; + log(debug, ~"sending teardown_loop msg.."); + exit(iotask); + exit_po.recv(); + log(debug, ~"after recv on exit_po.. exiting.."); } } diff --git a/src/libstd/uv_ll.rs b/src/libstd/uv_ll.rs index dd54620c83d..b7111bfb023 100644 --- a/src/libstd/uv_ll.rs +++ b/src/libstd/uv_ll.rs @@ -1199,6 +1199,7 @@ pub mod test { use uv_ll::*; + use core::comm::{SharedChan, stream}; use core::libc; use core::ptr; use core::str; @@ -1687,7 +1688,7 @@ pub mod test { // this is the impl for a test that is (maybe) ran on a // per-platform/arch basis below - fn impl_uv_tcp_server_and_request() { + pub fn impl_uv_tcp_server_and_request() { unsafe { let bind_ip = ~"0.0.0.0"; let request_ip = ~"127.0.0.1"; diff --git a/src/libstd/workcache.rs b/src/libstd/workcache.rs index c85aa78d983..592ac40e082 100644 --- a/src/libstd/workcache.rs +++ b/src/libstd/workcache.rs @@ -132,7 +132,7 @@ impl cmp::Ord for WorkKey { } } -impl WorkKey { +pub impl WorkKey { static fn new(kind: &str, name: &str) -> WorkKey { WorkKey { kind: kind.to_owned(), name: name.to_owned() } } @@ -168,7 +168,7 @@ struct Database { mut db_dirty: bool } -impl Database { +pub impl Database { fn prepare(&mut self, fn_name: &str, declared_inputs: &WorkMap) -> Option<(WorkMap, WorkMap, ~str)> { @@ -199,7 +199,7 @@ struct Logger { a: () } -impl Logger { +pub impl Logger { fn info(i: &str) { io::println(~"workcache: " + i.to_owned()); } @@ -254,7 +254,7 @@ fn digest_file(path: &Path) -> ~str { sha.result_str() } -impl Context { +pub impl Context { static fn new(db: @Mut<Database>, lg: @Mut<Logger>, @@ -356,7 +356,7 @@ impl TPrep for @Mut<Prep> { } } -impl<T:Owned + Encodable<json::Encoder> + Decodable<json::Decoder>> Work<T> { +pub impl<T:Owned+Encodable<json::Encoder>+Decodable<json::Decoder>> Work<T> { static fn new(p: @Mut<Prep>, e: Either<T,PortOne<(Exec,T)>>) -> Work<T> { Work { prep: p, res: Some(e) } } |
