From ef788d51dd17cac158752f120347a9eaa5d89d98 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 14 May 2014 17:49:14 -0700 Subject: std: Modify TempDir to not fail on drop. Closes #12628 After discussion with Alex, we think the proper policy is for dtors to not fail. This is consistent with C++. BufferedWriter already does this, so this patch modifies TempDir to not fail in the dtor, adding a `close` method for handling errors on destruction. --- src/libstd/io/buffered.rs | 21 ++++++++++++++++++++- src/libstd/io/tempfile.rs | 36 +++++++++++++++++++++++++++--------- 2 files changed, 47 insertions(+), 10 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index a8e7b324bd7..68cbdd2e0aa 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -209,7 +209,7 @@ impl Writer for BufferedWriter { impl Drop for BufferedWriter { fn drop(&mut self) { if self.inner.is_some() { - // FIXME(#12628): should this error be ignored? + // dtors should not fail, so we ignore a failed flush let _ = self.flush_buf(); } } @@ -370,6 +370,7 @@ mod test { use io; use prelude::*; use super::*; + use super::super::{IoResult, EndOfFile}; use super::super::mem::{MemReader, MemWriter, BufReader}; use self::test::Bencher; use str::StrSlice; @@ -584,6 +585,24 @@ mod test { assert_eq!(it.next(), None); } + #[test] + #[should_fail] + fn dont_fail_in_drop_on_failed_flush() { + struct FailFlushWriter; + + impl Writer for FailFlushWriter { + fn write(&mut self, _buf: &[u8]) -> IoResult<()> { Ok(()) } + fn flush(&mut self) -> IoResult<()> { Err(io::standard_error(EndOfFile)) } + } + + let writer = FailFlushWriter; + let _writer = BufferedWriter::new(writer); + + // Trigger failure. If writer fails *again* due to the flush + // error then the process will abort. + fail!(); + } + #[bench] fn bench_buffered_reader(b: &mut Bencher) { b.iter(|| { diff --git a/src/libstd/io/tempfile.rs b/src/libstd/io/tempfile.rs index 8c28caa988a..b4fb95c8af7 100644 --- a/src/libstd/io/tempfile.rs +++ b/src/libstd/io/tempfile.rs @@ -10,7 +10,7 @@ //! Temporary files and directories -use io::fs; +use io::{fs, IoResult}; use io; use iter::{Iterator, range}; use libc; @@ -18,13 +18,14 @@ use ops::Drop; use option::{Option, None, Some}; use os; use path::{Path, GenericPath}; -use result::{Ok, Err, ResultUnwrap}; +use result::{Ok, Err}; use sync::atomics; /// A wrapper for a path to temporary directory implementing automatic /// scope-based deletion. pub struct TempDir { - path: Option + path: Option, + disarmed: bool } impl TempDir { @@ -48,7 +49,7 @@ impl TempDir { let p = tmpdir.join(filename); match fs::mkdir(&p, io::UserRWX) { Err(..) => {} - Ok(()) => return Some(TempDir { path: Some(p) }) + Ok(()) => return Some(TempDir { path: Some(p), disarmed: false }) } } None @@ -75,15 +76,32 @@ impl TempDir { pub fn path<'a>(&'a self) -> &'a Path { self.path.get_ref() } + + /// Close and remove the temporary directory + /// + /// Although `TempDir` removes the directory on drop, in the destructor + /// any errors are ignored. To detect errors cleaning up the temporary + /// directory, call `close` instead. + pub fn close(mut self) -> IoResult<()> { + self.cleanup_dir() + } + + fn cleanup_dir(&mut self) -> IoResult<()> { + assert!(!self.disarmed); + self.disarmed = true; + match self.path { + Some(ref p) => { + fs::rmdir_recursive(p) + } + None => Ok(()) + } + } } impl Drop for TempDir { fn drop(&mut self) { - for path in self.path.iter() { - if path.exists() { - // FIXME: is failing the right thing to do? - fs::rmdir_recursive(path).unwrap(); - } + if !self.disarmed { + let _ = self.cleanup_dir(); } } } -- cgit 1.4.1-3-g733a5 From d547de998d33e5b688533f4159ea997c940d9431 Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Wed, 14 May 2014 14:57:27 -0700 Subject: Make Vec.truncate() resilient against failure in Drop If a vector element fails in Drop, Vec needs to make sure it doesn't try to re-drop any elements it already dropped. --- src/libstd/vec.rs | 45 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 528ab72762a..57f8d78948f 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -635,14 +635,14 @@ impl Vec { /// ``` pub fn truncate(&mut self, len: uint) { unsafe { - let mut i = len; // drop any extra elements - while i < self.len { - ptr::read(self.as_slice().unsafe_ref(i)); - i += 1; + while len < self.len { + // decrement len before the read(), so a failure on Drop doesn't + // re-drop the just-failed value. + self.len -= 1; + ptr::read(self.as_slice().unsafe_ref(self.len)); } } - self.len = len; } /// Work with `self` as a mutable slice. @@ -1862,4 +1862,39 @@ mod tests { assert_eq!(b[0].x, 42); assert_eq!(b[1].x, 84); } + + #[test] + fn test_vec_truncate_drop() { + static mut drops: uint = 0; + struct Elem(int); + impl Drop for Elem { + fn drop(&mut self) { + unsafe { drops += 1; } + } + } + + let mut v = vec![Elem(1), Elem(2), Elem(3), Elem(4), Elem(5)]; + assert_eq!(unsafe { drops }, 0); + v.truncate(3); + assert_eq!(unsafe { drops }, 2); + v.truncate(0); + assert_eq!(unsafe { drops }, 5); + } + + #[test] + #[should_fail] + fn test_vec_truncate_fail() { + struct BadElem(int); + impl Drop for BadElem { + fn drop(&mut self) { + let BadElem(ref mut x) = *self; + if *x == 0xbadbeef { + fail!("BadElem failure: 0xbadbeef") + } + } + } + + let mut v = vec![BadElem(1), BadElem(2), BadElem(0xbadbeef), BadElem(4)]; + v.truncate(0); + } } -- cgit 1.4.1-3-g733a5 From 912a9675c0b7f9e8c836983e525b180c48693925 Mon Sep 17 00:00:00 2001 From: Aaron Turon Date: Wed, 14 May 2014 14:39:16 -0700 Subject: Make `from_bits` in `bitflags!` safe; add `from_bits_truncate` Previously, the `from_bits` function in the `std::bitflags::bitflags` macro was marked as unsafe, as it did not check that the bits being converted actually corresponded to flags. This patch changes the function to check against the full set of possible flags and return an `Option` which is `None` if a non-flag bit is set. It also adds a `from_bits_truncate` function which simply zeros any bits not corresponding to a flag. This addresses the concern raised in https://github.com/mozilla/rust/pull/13897 --- src/libnative/io/file_unix.rs | 4 +--- src/libnative/io/file_win32.rs | 4 +--- src/librustuv/file.rs | 4 +--- src/libstd/bitflags.rs | 37 ++++++++++++++++++++++++++++++------- 4 files changed, 33 insertions(+), 16 deletions(-) (limited to 'src/libstd') diff --git a/src/libnative/io/file_unix.rs b/src/libnative/io/file_unix.rs index c2b69483fa1..046d2875d55 100644 --- a/src/libnative/io/file_unix.rs +++ b/src/libnative/io/file_unix.rs @@ -493,9 +493,7 @@ fn mkstat(stat: &libc::stat) -> io::FileStat { io::FileStat { size: stat.st_size as u64, kind: kind, - perm: unsafe { - io::FilePermission::from_bits(stat.st_mode as u32) & io::AllPermissions - }, + perm: io::FilePermission::from_bits_truncate(stat.st_mode as u32), created: mktime(stat.st_ctime as u64, stat.st_ctime_nsec as u64), modified: mktime(stat.st_mtime as u64, stat.st_mtime_nsec as u64), accessed: mktime(stat.st_atime as u64, stat.st_atime_nsec as u64), diff --git a/src/libnative/io/file_win32.rs b/src/libnative/io/file_win32.rs index d721e1d67f1..3222c912dd0 100644 --- a/src/libnative/io/file_win32.rs +++ b/src/libnative/io/file_win32.rs @@ -492,9 +492,7 @@ fn mkstat(stat: &libc::stat) -> io::FileStat { io::FileStat { size: stat.st_size as u64, kind: kind, - perm: unsafe { - io::FilePermission::from_bits(stat.st_mode as u32) & io::AllPermissions - }, + perm: io::FilePermission::from_bits_truncate(stat.st_mode as u32), created: stat.st_ctime as u64, modified: stat.st_mtime as u64, accessed: stat.st_atime as u64, diff --git a/src/librustuv/file.rs b/src/librustuv/file.rs index 06271e61ce7..12636a3c490 100644 --- a/src/librustuv/file.rs +++ b/src/librustuv/file.rs @@ -285,9 +285,7 @@ impl FsRequest { FileStat { size: stat.st_size as u64, kind: kind, - perm: unsafe { - io::FilePermission::from_bits(stat.st_mode as u32) & io::AllPermissions - }, + perm: io::FilePermission::from_bits_truncate(stat.st_mode as u32), created: to_msec(stat.st_birthtim), modified: to_msec(stat.st_mtim), accessed: to_msec(stat.st_atim), diff --git a/src/libstd/bitflags.rs b/src/libstd/bitflags.rs index 32f9bc1173b..163ccd22552 100644 --- a/src/libstd/bitflags.rs +++ b/src/libstd/bitflags.rs @@ -136,10 +136,20 @@ macro_rules! bitflags( self.bits } - /// Convert from underlying bit representation. Unsafe because the - /// bits are not guaranteed to represent valid flags. - pub unsafe fn from_bits(bits: $T) -> $BitFlags { - $BitFlags { bits: bits } + /// Convert from underlying bit representation, unless that + /// representation contains bits that do not correspond to a flag. + pub fn from_bits(bits: $T) -> ::std::option::Option<$BitFlags> { + if (bits & !$BitFlags::all().bits()) != 0 { + ::std::option::None + } else { + ::std::option::Some($BitFlags { bits: bits }) + } + } + + /// Convert from underlying bit representation, dropping any bits + /// that do not correspond to flags. + pub fn from_bits_truncate(bits: $T) -> $BitFlags { + $BitFlags { bits: bits } & $BitFlags::all() } /// Returns `true` if no flags are currently stored. @@ -209,6 +219,7 @@ macro_rules! bitflags( #[cfg(test)] mod tests { + use option::{Some, None}; use ops::{BitOr, BitAnd, Sub, Not}; bitflags!( @@ -231,9 +242,21 @@ mod tests { #[test] fn test_from_bits() { - assert!(unsafe { Flags::from_bits(0x00000000) } == Flags::empty()); - assert!(unsafe { Flags::from_bits(0x00000001) } == FlagA); - assert!(unsafe { Flags::from_bits(0x00000111) } == FlagABC); + assert!(Flags::from_bits(0) == Some(Flags::empty())); + assert!(Flags::from_bits(0x1) == Some(FlagA)); + assert!(Flags::from_bits(0x10) == Some(FlagB)); + assert!(Flags::from_bits(0x11) == Some(FlagA | FlagB)); + assert!(Flags::from_bits(0x1000) == None); + } + + #[test] + fn test_from_bits_truncate() { + assert!(Flags::from_bits_truncate(0) == Flags::empty()); + assert!(Flags::from_bits_truncate(0x1) == FlagA); + assert!(Flags::from_bits_truncate(0x10) == FlagB); + assert!(Flags::from_bits_truncate(0x11) == (FlagA | FlagB)); + assert!(Flags::from_bits_truncate(0x1000) == Flags::empty()); + assert!(Flags::from_bits_truncate(0x1001) == FlagA); } #[test] -- cgit 1.4.1-3-g733a5 From 8211539114df8b6e3a9b8b251fa57cb5a77d2f14 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 14 May 2014 14:24:41 -0700 Subject: Register new snapshots --- src/libcore/lib.rs | 3 -- src/libcore/owned.rs | 101 --------------------------------------------------- src/libstd/lib.rs | 7 +--- src/snapshots.txt | 8 ++++ 4 files changed, 10 insertions(+), 109 deletions(-) delete mode 100644 src/libcore/owned.rs (limited to 'src/libstd') diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 4eab7e9d45d..9e3a92981e5 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -116,9 +116,6 @@ pub mod slice; pub mod str; pub mod tuple; -#[cfg(stage0, not(test))] -pub mod owned; - // FIXME: this module should not exist. Once owned allocations are no longer a // language type, this module can move outside to the owned allocation // crate. diff --git a/src/libcore/owned.rs b/src/libcore/owned.rs deleted file mode 100644 index 3af12c5154c..00000000000 --- a/src/libcore/owned.rs +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright 2012 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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Operations on unique pointer types - -use any::{Any, AnyRefExt}; -use clone::Clone; -use cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering}; -use default::Default; -use intrinsics; -use mem; -use raw::TraitObject; -use result::{Ok, Err, Result}; - -/// A value that represents the global exchange heap. This is the default -/// place that the `box` keyword allocates into when no place is supplied. -/// -/// The following two examples are equivalent: -/// -/// let foo = box(HEAP) Bar::new(...); -/// let foo = box Bar::new(...); -#[lang="exchange_heap"] -pub static HEAP: () = (); - -/// A type that represents a uniquely-owned value. -#[lang="owned_box"] -pub struct Box(*T); - -impl Default for Box { - fn default() -> Box { box Default::default() } -} - -impl Clone for Box { - /// Return a copy of the owned box. - #[inline] - fn clone(&self) -> Box { box {(**self).clone()} } - - /// Perform copy-assignment from `source` by reusing the existing allocation. - #[inline] - fn clone_from(&mut self, source: &Box) { - (**self).clone_from(&(**source)); - } -} - -// box pointers -impl Eq for Box { - #[inline] - fn eq(&self, other: &Box) -> bool { *(*self) == *(*other) } - #[inline] - fn ne(&self, other: &Box) -> bool { *(*self) != *(*other) } -} -impl Ord for Box { - #[inline] - fn lt(&self, other: &Box) -> bool { *(*self) < *(*other) } - #[inline] - fn le(&self, other: &Box) -> bool { *(*self) <= *(*other) } - #[inline] - fn ge(&self, other: &Box) -> bool { *(*self) >= *(*other) } - #[inline] - fn gt(&self, other: &Box) -> bool { *(*self) > *(*other) } -} -impl TotalOrd for Box { - #[inline] - fn cmp(&self, other: &Box) -> Ordering { (**self).cmp(*other) } -} -impl TotalEq for Box {} - -/// Extension methods for an owning `Any` trait object -pub trait AnyOwnExt { - /// Returns the boxed value if it is of type `T`, or - /// `Err(Self)` if it isn't. - fn move(self) -> Result, Self>; -} - -impl AnyOwnExt for Box { - #[inline] - fn move(self) -> Result, Box> { - if self.is::() { - unsafe { - // Get the raw representation of the trait object - let to: TraitObject = - *mem::transmute::<&Box, &TraitObject>(&self); - - // Prevent destructor on self being run - intrinsics::forget(self); - - // Extract the data pointer - Ok(mem::transmute(to.data)) - } - } else { - Err(self) - } - } -} diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index a37f9a516fd..87c4ef1046f 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -133,16 +133,13 @@ extern crate core; #[cfg(test)] pub use ops = realstd::ops; #[cfg(test)] pub use cmp = realstd::cmp; #[cfg(test)] pub use ty = realstd::ty; -#[cfg(not(stage0), test)] pub use owned = realstd::owned; +#[cfg(test)] pub use owned = realstd::owned; #[cfg(not(test))] pub use cmp = core::cmp; #[cfg(not(test))] pub use kinds = core::kinds; #[cfg(not(test))] pub use ops = core::ops; #[cfg(not(test))] pub use ty = core::ty; -#[cfg(stage0, test)] pub use owned = realstd::owned; -#[cfg(stage0, not(test))] pub use owned = core::owned; - pub use core::any; pub use core::bool; pub use core::cell; @@ -209,7 +206,7 @@ pub mod ascii; pub mod rc; pub mod gc; -#[cfg(not(stage0), not(test))] +#[cfg(not(test))] pub mod owned; /* Common traits */ diff --git a/src/snapshots.txt b/src/snapshots.txt index e88ae02c1c6..4c62d519d78 100644 --- a/src/snapshots.txt +++ b/src/snapshots.txt @@ -1,3 +1,11 @@ +S 2014-05-15 6a2b3d1 + freebsd-x86_64 afc98b59cb819025fecdb9d145ca4463f857a477 + linux-i386 d6f7a404412ea34db3d19814ca21fe6fa662b02f + linux-x86_64 3dfb54406a7ea75565a7ea3071daad885cb91775 + macos-i386 bebb937551d601ad908c9e4eaa196cc7a977c503 + macos-x86_64 08346ed401ad2891c7d2ba0aac0960f6e77bb78b + winnt-i386 ad8e5b8292a00f60f1f7dc2e35bd18abeb5b858d + S 2014-05-11 72fc4a5 freebsd-x86_64 82db6355b0b7c8023c8845a74e2f224da2831b50 linux-i386 91901299d5f86f5b67377d940073908a1f0e4e82 -- cgit 1.4.1-3-g733a5 From e043644cea119ea701a293a01b6d4c5c0f13f450 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Wed, 14 May 2014 15:54:19 -0400 Subject: use sched_yield on linux and freebsd pthread_yield is non-standard, while sched_yield is POSIX The Linux documentation recommends using the standard function. This is the only feature we're currently using that's present in glibc but not in musl. --- src/libstd/rt/thread.rs | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/rt/thread.rs b/src/libstd/rt/thread.rs index 4f0d7d35ce8..e25fa4734d5 100644 --- a/src/libstd/rt/thread.rs +++ b/src/libstd/rt/thread.rs @@ -273,13 +273,8 @@ mod imp { assert_eq!(pthread_detach(native), 0); } - #[cfg(target_os = "macos")] - #[cfg(target_os = "android")] pub unsafe fn yield_now() { assert_eq!(sched_yield(), 0); } - #[cfg(not(target_os = "macos"), not(target_os = "android"))] - pub unsafe fn yield_now() { assert_eq!(pthread_yield(), 0); } - // glibc >= 2.15 has a __pthread_get_minstack() function that returns // PTHREAD_STACK_MIN plus however many bytes are needed for thread-local // storage. We need that information to avoid blowing up when a small stack @@ -326,12 +321,7 @@ mod imp { fn pthread_attr_setdetachstate(attr: *mut libc::pthread_attr_t, state: libc::c_int) -> libc::c_int; fn pthread_detach(thread: libc::pthread_t) -> libc::c_int; - - #[cfg(target_os = "macos")] - #[cfg(target_os = "android")] fn sched_yield() -> libc::c_int; - #[cfg(not(target_os = "macos"), not(target_os = "android"))] - fn pthread_yield() -> libc::c_int; } } -- cgit 1.4.1-3-g733a5 From 7f88cfde18942fc93c3f5952e51c03171446778c Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Thu, 8 May 2014 19:11:43 +0200 Subject: Add `IntoMaybeOwned` impl for `StrBuf` to ease conversion to `MaybeOwned`. --- src/libstd/str.rs | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/libstd') diff --git a/src/libstd/str.rs b/src/libstd/str.rs index fa4cf8e4427..aee5fe9ff96 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -564,6 +564,11 @@ impl<'a> IntoMaybeOwned<'a> for ~str { fn into_maybe_owned(self) -> MaybeOwned<'a> { Owned(self) } } +impl<'a> IntoMaybeOwned<'a> for StrBuf { + #[inline] + fn into_maybe_owned(self) -> MaybeOwned<'a> { Owned(self.into_owned()) } +} + impl<'a> IntoMaybeOwned<'a> for &'a str { #[inline] fn into_maybe_owned(self) -> MaybeOwned<'a> { Slice(self) } -- cgit 1.4.1-3-g733a5 From 514fc308b0bcf903260f1e40fd0b18ba91539d35 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 14 May 2014 01:13:29 -0700 Subject: std: Remove run_in_bare_thread --- src/libgreen/sched.rs | 6 +++--- src/librustuv/lib.rs | 6 +++--- src/librustuv/uvio.rs | 6 +++--- src/libstd/rt/local.rs | 22 ++++++++++---------- src/libstd/unstable/mod.rs | 31 ---------------------------- src/test/run-pass/foreign-call-no-runtime.rs | 6 +++--- 6 files changed, 23 insertions(+), 54 deletions(-) (limited to 'src/libstd') diff --git a/src/libgreen/sched.rs b/src/libgreen/sched.rs index 8c294fa2928..5bc96dd6e8e 100644 --- a/src/libgreen/sched.rs +++ b/src/libgreen/sched.rs @@ -1137,11 +1137,11 @@ mod test { fn test_schedule_home_states() { use sleeper_list::SleeperList; use super::{Shutdown, Scheduler, SchedHandle}; - use std::unstable::run_in_bare_thread; + use std::unstable::Thread; use std::rt::thread::Thread; use std::sync::deque::BufferPool; - run_in_bare_thread(proc() { + Thread::start(proc() { let sleepers = SleeperList::new(); let mut pool = BufferPool::new(); let (normal_worker, normal_stealer) = pool.deque(); @@ -1260,7 +1260,7 @@ mod test { normal_thread.join(); special_thread.join(); - }); + }).join(); } //#[test] diff --git a/src/librustuv/lib.rs b/src/librustuv/lib.rs index c9bff2e80bf..96b66f616f6 100644 --- a/src/librustuv/lib.rs +++ b/src/librustuv/lib.rs @@ -472,7 +472,7 @@ fn local_loop() -> &'static mut uvio::UvIoFactory { #[cfg(test)] mod test { use std::mem::transmute; - use std::unstable::run_in_bare_thread; + use std::rt::Thread; use super::{slice_to_uv_buf, Loop}; @@ -496,10 +496,10 @@ mod test { #[test] fn loop_smoke_test() { - run_in_bare_thread(proc() { + Thread::start(proc() { let mut loop_ = Loop::new(); loop_.run(); loop_.close(); - }); + }).join(); } } diff --git a/src/librustuv/uvio.rs b/src/librustuv/uvio.rs index 1b8175448fc..88e05f815b2 100644 --- a/src/librustuv/uvio.rs +++ b/src/librustuv/uvio.rs @@ -27,7 +27,7 @@ use std::rt::rtio; use std::rt::rtio::{ProcessConfig, IoFactory, EventLoop}; use ai = std::io::net::addrinfo; -#[cfg(test)] use std::unstable::run_in_bare_thread; +#[cfg(test)] use std::rt::Thread; use super::{uv_error_to_io_error, Loop}; @@ -116,7 +116,7 @@ impl EventLoop for UvEventLoop { #[test] fn test_callback_run_once() { - run_in_bare_thread(proc() { + Thread::start(proc() { let mut event_loop = UvEventLoop::new(); let mut count = 0; let count_ptr: *mut int = &mut count; @@ -125,7 +125,7 @@ fn test_callback_run_once() { }); event_loop.run(); assert_eq!(count, 1); - }); + }).join(); } pub struct UvIoFactory { diff --git a/src/libstd/rt/local.rs b/src/libstd/rt/local.rs index 05d1f1764b5..9f0ed804480 100644 --- a/src/libstd/rt/local.rs +++ b/src/libstd/rt/local.rs @@ -53,24 +53,24 @@ impl Local> for Task { #[cfg(test)] mod test { use option::{None, Option}; - use unstable::run_in_bare_thread; + use rt::thread::Thread; use super::*; use owned::Box; use rt::task::Task; #[test] fn thread_local_task_smoke_test() { - run_in_bare_thread(proc() { + Thread::start(proc() { let task = box Task::new(); Local::put(task); let task: Box = Local::take(); cleanup_task(task); - }); + }).join(); } #[test] fn thread_local_task_two_instances() { - run_in_bare_thread(proc() { + Thread::start(proc() { let task = box Task::new(); Local::put(task); let task: Box = Local::take(); @@ -79,12 +79,12 @@ mod test { Local::put(task); let task: Box = Local::take(); cleanup_task(task); - }); + }).join(); } #[test] fn borrow_smoke_test() { - run_in_bare_thread(proc() { + Thread::start(proc() { let task = box Task::new(); Local::put(task); @@ -93,12 +93,12 @@ mod test { } let task: Box = Local::take(); cleanup_task(task); - }); + }).join(); } #[test] fn borrow_with_return() { - run_in_bare_thread(proc() { + Thread::start(proc() { let task = box Task::new(); Local::put(task); @@ -108,12 +108,12 @@ mod test { let task: Box = Local::take(); cleanup_task(task); - }); + }).join(); } #[test] fn try_take() { - run_in_bare_thread(proc() { + Thread::start(proc() { let task = box Task::new(); Local::put(task); @@ -122,7 +122,7 @@ mod test { assert!(u.is_none()); cleanup_task(t); - }); + }).join(); } fn cleanup_task(mut t: Box) { diff --git a/src/libstd/unstable/mod.rs b/src/libstd/unstable/mod.rs index 8b07850263f..f464f70772d 100644 --- a/src/libstd/unstable/mod.rs +++ b/src/libstd/unstable/mod.rs @@ -11,7 +11,6 @@ #![doc(hidden)] use libc::uintptr_t; -use kinds::Send; pub use core::finally; @@ -21,36 +20,6 @@ pub mod simd; pub mod sync; pub mod mutex; -/** - -Start a new thread outside of the current runtime context and wait -for it to terminate. - -The executing thread has no access to a task pointer and will be using -a normal large stack. -*/ -pub fn run_in_bare_thread(f: proc():Send) { - use rt::thread::Thread; - Thread::start(f).join() -} - -#[test] -fn test_run_in_bare_thread() { - let i = 100; - run_in_bare_thread(proc() { - assert_eq!(i, 100); - }); -} - -#[test] -fn test_run_in_bare_thread_exchange() { - // Does the exchange heap work without the runtime? - let i = box 100; - run_in_bare_thread(proc() { - assert!(i == box 100); - }); -} - /// Dynamically inquire about whether we're running under V. /// You should usually not use this unless your test definitely /// can't run correctly un-altered. Valgrind is there to help diff --git a/src/test/run-pass/foreign-call-no-runtime.rs b/src/test/run-pass/foreign-call-no-runtime.rs index b56847b2da0..989c09146b7 100644 --- a/src/test/run-pass/foreign-call-no-runtime.rs +++ b/src/test/run-pass/foreign-call-no-runtime.rs @@ -11,7 +11,7 @@ extern crate libc; use std::mem; -use std::unstable::run_in_bare_thread; +use std::rt::thread::Thread; #[link(name = "rustrt")] extern { @@ -21,10 +21,10 @@ extern { pub fn main() { unsafe { - run_in_bare_thread(proc() { + Thread::start(proc() { let i = &100; rust_dbg_call(callback, mem::transmute(i)); - }); + }).join(); } } -- cgit 1.4.1-3-g733a5 From 50331595fca761eba8b034a6e73143b01b330c04 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 14 May 2014 01:36:12 -0700 Subject: std: Delete unused file --- src/libstd/io/flate.rs | 52 -------------------------------------------------- 1 file changed, 52 deletions(-) delete mode 100644 src/libstd/io/flate.rs (limited to 'src/libstd') diff --git a/src/libstd/io/flate.rs b/src/libstd/io/flate.rs deleted file mode 100644 index 0cf00b2c1a9..00000000000 --- a/src/libstd/io/flate.rs +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2013 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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Some various other I/O types - -// FIXME(#3660): should move to libextra - -use prelude::*; -use super::*; - -/// A Writer decorator that compresses using the 'deflate' scheme -pub struct DeflateWriter { - priv inner_writer: W -} - -impl DeflateWriter { - pub fn new(inner_writer: W) -> DeflateWriter { - DeflateWriter { - inner_writer: inner_writer - } - } -} - -impl Writer for DeflateWriter { - fn write(&mut self, _buf: &[u8]) { fail!() } - - fn flush(&mut self) { fail!() } -} - -/// A Reader decorator that decompresses using the 'deflate' scheme -pub struct InflateReader { - priv inner_reader: R -} - -impl InflateReader { - pub fn new(inner_reader: R) -> InflateReader { - InflateReader { - inner_reader: inner_reader - } - } -} - -impl Reader for InflateReader { - fn read(&mut self, _buf: &mut [u8]) -> Option { fail!() } -} -- cgit 1.4.1-3-g733a5