diff options
| author | bors <bors@rust-lang.org> | 2016-03-12 13:21:06 -0800 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2016-03-12 13:21:06 -0800 |
| commit | a2c56de7643c3b989c703758f0fb9f426403bca2 (patch) | |
| tree | 6d93e86dd597e0b71632332a141269e6729837ff /src/libstd | |
| parent | 8788ffc670e981a195c771ab3c8530c72eb119d7 (diff) | |
| parent | b53764c73bd722ea22142bace6249d5950066253 (diff) | |
| download | rust-a2c56de7643c3b989c703758f0fb9f426403bca2.tar.gz rust-a2c56de7643c3b989c703758f0fb9f426403bca2.zip | |
Auto merge of #32112 - alexcrichton:fix-issues, r=aturon
std: Fix tracking issues and clean deprecated APIs This PR fixes up a number of discrepancies found with tracking issues (some closed, some needed new ones, etc), and also cleans out all pre-1.8 deprecated APIs. The big beast here was dealing with `std::dynamic_lib`, and via many applications of a large hammer it's now out of the standard library.
Diffstat (limited to 'src/libstd')
29 files changed, 180 insertions, 1491 deletions
diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 051829fbafb..ec5629038a4 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -592,15 +592,6 @@ impl<K, V, S> HashMap<K, V, S> } } - /// Deprecated, renamed to `with_hasher` - #[inline] - #[unstable(feature = "hashmap_hasher", reason = "hasher stuff is unclear", - issue = "27713")] - #[rustc_deprecated(since = "1.7.0", reason = "renamed to with_hasher")] - pub fn with_hash_state(hash_state: S) -> HashMap<K, V, S> { - HashMap::with_hasher(hash_state) - } - /// Creates an empty HashMap with space for at least `capacity` /// elements, using `hasher` to hash the keys. /// @@ -634,17 +625,6 @@ impl<K, V, S> HashMap<K, V, S> } } - /// Deprecated, renamed to `with_capacity_and_hasher` - #[inline] - #[unstable(feature = "hashmap_hasher", reason = "hasher stuff is unclear", - issue = "27713")] - #[rustc_deprecated(since = "1.7.0", - reason = "renamed to with_capacity_and_hasher")] - pub fn with_capacity_and_hash_state(capacity: usize, hash_state: S) - -> HashMap<K, V, S> { - HashMap::with_capacity_and_hasher(capacity, hash_state) - } - /// Returns a reference to the map's hasher. #[unstable(feature = "hashmap_public_hasher", reason = "don't want to make insta-stable", issue = "31262")] diff --git a/src/libstd/collections/hash/mod.rs b/src/libstd/collections/hash/mod.rs index 4a6fcf44926..7a22bec5a3f 100644 --- a/src/libstd/collections/hash/mod.rs +++ b/src/libstd/collections/hash/mod.rs @@ -14,7 +14,6 @@ mod bench; mod table; pub mod map; pub mod set; -pub mod state; trait Recover<Q: ?Sized> { type Key; diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index 5c58cd9dfbf..84153955797 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -200,26 +200,6 @@ impl<T, S> HashSet<T, S> self.map.hasher() } - /// Deprecated, renamed to `with_hasher` - #[inline] - #[unstable(feature = "hashmap_hasher", reason = "hasher stuff is unclear", - issue = "27713")] - #[rustc_deprecated(since = "1.7.0", reason = "renamed to with_hasher")] - pub fn with_hash_state(hash_state: S) -> HashSet<T, S> { - HashSet::with_hasher(hash_state) - } - - /// Deprecated, renamed to `with_capacity_and_hasher` - #[inline] - #[unstable(feature = "hashmap_hasher", reason = "hasher stuff is unclear", - issue = "27713")] - #[rustc_deprecated(since = "1.7.0", - reason = "renamed to with_capacity_and_hasher")] - pub fn with_capacity_and_hash_state(capacity: usize, hash_state: S) - -> HashSet<T, S> { - HashSet::with_capacity_and_hasher(capacity, hash_state) - } - /// Returns the number of elements the set can hold without reallocating. /// /// # Examples diff --git a/src/libstd/collections/hash/state.rs b/src/libstd/collections/hash/state.rs deleted file mode 100644 index 167aca08303..00000000000 --- a/src/libstd/collections/hash/state.rs +++ /dev/null @@ -1,40 +0,0 @@ -// 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. - -#![unstable(feature = "hashmap_hasher", reason = "hasher stuff is unclear", - issue = "27713")] -#![rustc_deprecated(since = "1.7.0", reason = "support moved to std::hash")] -#![allow(deprecated)] - -use clone::Clone; -use default::Default; -use hash; -use marker; - -pub use hash::HashState; - -/// A structure which is a factory for instances of `Hasher` which implement the -/// default trait. -/// -/// This struct is 0-sized and does not need construction. -pub struct DefaultState<H>(marker::PhantomData<H>); - -impl<H: Default + hash::Hasher> HashState for DefaultState<H> { - type Hasher = H; - fn hasher(&self) -> H { Default::default() } -} - -impl<H> Clone for DefaultState<H> { - fn clone(&self) -> DefaultState<H> { DefaultState(marker::PhantomData) } -} - -impl<H> Default for DefaultState<H> { - fn default() -> DefaultState<H> { DefaultState(marker::PhantomData) } -} diff --git a/src/libstd/collections/mod.rs b/src/libstd/collections/mod.rs index 06c14157606..4de442fd3a1 100644 --- a/src/libstd/collections/mod.rs +++ b/src/libstd/collections/mod.rs @@ -442,13 +442,3 @@ pub mod hash_set { #[stable(feature = "rust1", since = "1.0.0")] pub use super::hash::set::*; } - -/// Experimental support for providing custom hash algorithms to a HashMap and -/// HashSet. -#[unstable(feature = "hashmap_hasher", reason = "module was recently added", - issue = "27713")] -#[rustc_deprecated(since = "1.7.0", reason = "support moved to std::hash")] -#[allow(deprecated)] -pub mod hash_state { - pub use super::hash::state::*; -} diff --git a/src/libstd/dynamic_lib.rs b/src/libstd/dynamic_lib.rs deleted file mode 100644 index 08e33fad40e..00000000000 --- a/src/libstd/dynamic_lib.rs +++ /dev/null @@ -1,398 +0,0 @@ -// Copyright 2013-2015 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. - -//! Dynamic library facilities. -//! -//! A simple wrapper over the platform's dynamic library facilities - -#![unstable(feature = "dynamic_lib", - reason = "API has not been scrutinized and is highly likely to \ - either disappear or change", - issue = "27810")] -#![allow(missing_docs)] -#![allow(deprecated)] - -use prelude::v1::*; - -use env; -use ffi::{CString, OsString}; -use path::{Path, PathBuf}; - -#[unstable(feature = "dynamic_lib", - reason = "API has not been scrutinized and is highly likely to \ - either disappear or change", - issue = "27810")] -#[rustc_deprecated(since = "1.5.0", reason = "replaced with 'dylib' on crates.io")] -pub struct DynamicLibrary { - handle: *mut u8 -} - -impl Drop for DynamicLibrary { - fn drop(&mut self) { - match dl::check_for_errors_in(|| { - unsafe { - dl::close(self.handle) - } - }) { - Ok(()) => {}, - Err(str) => panic!("{}", str) - } - } -} - -#[unstable(feature = "dynamic_lib", - reason = "API has not been scrutinized and is highly likely to \ - either disappear or change", - issue = "27810")] -#[rustc_deprecated(since = "1.5.0", reason = "replaced with 'dylib' on crates.io")] -impl DynamicLibrary { - /// Lazily open a dynamic library. When passed None it gives a - /// handle to the calling process - pub fn open(filename: Option<&Path>) -> Result<DynamicLibrary, String> { - let maybe_library = dl::open(filename.map(|path| path.as_os_str())); - - // The dynamic library must not be constructed if there is - // an error opening the library so the destructor does not - // run. - match maybe_library { - Err(err) => Err(err), - Ok(handle) => Ok(DynamicLibrary { handle: handle }) - } - } - - /// Prepends a path to this process's search path for dynamic libraries - pub fn prepend_search_path(path: &Path) { - let mut search_path = DynamicLibrary::search_path(); - search_path.insert(0, path.to_path_buf()); - env::set_var(DynamicLibrary::envvar(), &DynamicLibrary::create_path(&search_path)); - } - - /// From a slice of paths, create a new vector which is suitable to be an - /// environment variable for this platforms dylib search path. - pub fn create_path(path: &[PathBuf]) -> OsString { - let mut newvar = OsString::new(); - for (i, path) in path.iter().enumerate() { - if i > 0 { newvar.push(DynamicLibrary::separator()); } - newvar.push(path); - } - return newvar; - } - - /// Returns the environment variable for this process's dynamic library - /// search path - pub fn envvar() -> &'static str { - if cfg!(windows) { - "PATH" - } else if cfg!(target_os = "macos") { - "DYLD_LIBRARY_PATH" - } else { - "LD_LIBRARY_PATH" - } - } - - fn separator() -> &'static str { - if cfg!(windows) { ";" } else { ":" } - } - - /// Returns the current search path for dynamic libraries being used by this - /// process - pub fn search_path() -> Vec<PathBuf> { - match env::var_os(DynamicLibrary::envvar()) { - Some(var) => env::split_paths(&var).collect(), - None => Vec::new(), - } - } - - /// Accesses the value at the symbol of the dynamic library. - 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 - - let raw_string = CString::new(symbol).unwrap(); - let maybe_symbol_value = dl::check_for_errors_in(|| { - dl::symbol(self.handle, raw_string.as_ptr()) - }); - - // The value must not be constructed if there is an error so - // the destructor does not run. - match maybe_symbol_value { - Err(err) => Err(err), - Ok(symbol_value) => Ok(symbol_value as *mut T) - } - } -} - -#[cfg(all(test, not(target_os = "ios"), not(target_os = "nacl")))] -mod tests { - use super::*; - use prelude::v1::*; - use libc; - use mem; - - #[test] - #[cfg_attr(any(windows, - target_os = "android", // FIXME #10379 - target_env = "musl"), ignore)] - #[allow(deprecated)] - fn test_loading_cosine() { - // The math library does not need to be loaded since it is already - // statically linked in - let libm = match DynamicLibrary::open(None) { - Err(error) => panic!("Could not load self as module: {}", error), - Ok(libm) => libm - }; - - let cosine: extern fn(libc::c_double) -> libc::c_double = unsafe { - match libm.symbol("cos") { - Err(error) => panic!("Could not load function cos: {}", error), - Ok(cosine) => mem::transmute::<*mut u8, _>(cosine) - } - }; - - let argument = 0.0; - let expected_result = 1.0; - let result = cosine(argument); - if result != expected_result { - panic!("cos({}) != {} but equaled {} instead", argument, - expected_result, result) - } - } - - #[test] - #[cfg(any(target_os = "linux", - target_os = "macos", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "bitrig", - target_os = "netbsd", - target_os = "openbsd", - target_os = "solaris"))] - #[allow(deprecated)] - fn test_errors_do_not_crash() { - use path::Path; - - // Open /dev/null as a library to get an error, and make sure - // that only causes an error, and not a crash. - let path = Path::new("/dev/null"); - match DynamicLibrary::open(Some(&path)) { - Err(_) => {} - Ok(_) => panic!("Successfully opened the empty library.") - } - } -} - -#[cfg(any(target_os = "linux", - target_os = "android", - target_os = "macos", - target_os = "ios", - target_os = "freebsd", - target_os = "dragonfly", - target_os = "bitrig", - target_os = "netbsd", - target_os = "openbsd", - target_os = "solaris", - target_os = "emscripten"))] -mod dl { - use prelude::v1::*; - - use ffi::{CStr, OsStr}; - use str; - use libc; - use ptr; - - pub fn open(filename: Option<&OsStr>) -> Result<*mut u8, String> { - check_for_errors_in(|| { - unsafe { - match filename { - Some(filename) => open_external(filename), - None => open_internal(), - } - } - }) - } - - const LAZY: libc::c_int = 1; - - unsafe fn open_external(filename: &OsStr) -> *mut u8 { - let s = filename.to_cstring().unwrap(); - libc::dlopen(s.as_ptr(), LAZY) as *mut u8 - } - - unsafe fn open_internal() -> *mut u8 { - libc::dlopen(ptr::null(), LAZY) as *mut u8 - } - - pub fn check_for_errors_in<T, F>(f: F) -> Result<T, String> where - F: FnOnce() -> T, - { - use sync::StaticMutex; - static LOCK: StaticMutex = StaticMutex::new(); - unsafe { - // dlerror isn't thread safe, so we need to lock around this entire - // sequence - let _guard = LOCK.lock(); - let _old_error = libc::dlerror(); - - let result = f(); - - let last_error = libc::dlerror() as *const _; - let ret = if ptr::null() == last_error { - Ok(result) - } else { - let s = CStr::from_ptr(last_error).to_bytes(); - Err(str::from_utf8(s).unwrap().to_owned()) - }; - - ret - } - } - - pub unsafe fn symbol(handle: *mut u8, - symbol: *const libc::c_char) -> *mut u8 { - libc::dlsym(handle as *mut libc::c_void, symbol) as *mut u8 - } - pub unsafe fn close(handle: *mut u8) { - libc::dlclose(handle as *mut libc::c_void); () - } -} - -#[cfg(target_os = "windows")] -mod dl { - use prelude::v1::*; - - use ffi::OsStr; - use libc; - use os::windows::prelude::*; - use ptr; - use sys::c; - use sys::os; - - pub fn open(filename: Option<&OsStr>) -> Result<*mut u8, String> { - // disable "dll load failed" error dialog. - let mut use_thread_mode = true; - let prev_error_mode = unsafe { - // SEM_FAILCRITICALERRORS 0x01 - let new_error_mode = 1; - let mut prev_error_mode = 0; - // Windows >= 7 supports thread error mode. - let result = c::SetThreadErrorMode(new_error_mode, - &mut prev_error_mode); - if result == 0 { - let err = os::errno(); - if err == c::ERROR_CALL_NOT_IMPLEMENTED as i32 { - use_thread_mode = false; - // SetThreadErrorMode not found. use fallback solution: - // SetErrorMode() Note that SetErrorMode is process-wide so - // this can cause race condition! However, since even - // Windows APIs do not care of such problem (#20650), we - // just assume SetErrorMode race is not a great deal. - prev_error_mode = c::SetErrorMode(new_error_mode); - } - } - prev_error_mode - }; - - unsafe { - c::SetLastError(0); - } - - let result = match filename { - Some(filename) => { - let filename_str: Vec<_> = - filename.encode_wide().chain(Some(0)).collect(); - let result = unsafe { - c::LoadLibraryW(filename_str.as_ptr()) - }; - // beware: Vec/String may change errno during drop! - // so we get error here. - if result == ptr::null_mut() { - let errno = os::errno(); - Err(os::error_string(errno)) - } else { - Ok(result as *mut u8) - } - } - None => { - let mut handle = ptr::null_mut(); - let succeeded = unsafe { - c::GetModuleHandleExW(0 as c::DWORD, ptr::null(), - &mut handle) - }; - if succeeded == c::FALSE { - let errno = os::errno(); - Err(os::error_string(errno)) - } else { - Ok(handle as *mut u8) - } - } - }; - - unsafe { - if use_thread_mode { - c::SetThreadErrorMode(prev_error_mode, ptr::null_mut()); - } else { - c::SetErrorMode(prev_error_mode); - } - } - - result - } - - pub fn check_for_errors_in<T, F>(f: F) -> Result<T, String> where - F: FnOnce() -> T, - { - unsafe { - c::SetLastError(0); - - let result = f(); - - let error = os::errno(); - if 0 == error { - Ok(result) - } else { - Err(format!("Error code {}", error)) - } - } - } - - pub unsafe fn symbol(handle: *mut u8, symbol: *const libc::c_char) -> *mut u8 { - c::GetProcAddress(handle as c::HMODULE, symbol) as *mut u8 - } - pub unsafe fn close(handle: *mut u8) { - c::FreeLibrary(handle as c::HMODULE); - } -} - -#[cfg(target_os = "nacl")] -pub mod dl { - use ffi::OsStr; - use ptr; - use result::Result; - use result::Result::Err; - use libc; - use string::String; - use ops::FnOnce; - use option::Option; - - pub fn open(_filename: Option<&OsStr>) -> Result<*mut u8, String> { - Err(format!("NaCl + Newlib doesn't impl loading shared objects")) - } - - pub fn check_for_errors_in<T, F>(_f: F) -> Result<T, String> - where F: FnOnce() -> T, - { - Err(format!("NaCl doesn't support shared objects")) - } - - pub unsafe fn symbol(_handle: *mut u8, _symbol: *const libc::c_char) -> *mut u8 { - ptr::null_mut() - } - pub unsafe fn close(_handle: *mut u8) { } -} diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs index d979aa264af..46f2d3a6418 100644 --- a/src/libstd/ffi/os_str.rs +++ b/src/libstd/ffi/os_str.rs @@ -9,7 +9,6 @@ // except according to those terms. use borrow::{Borrow, Cow, ToOwned}; -use ffi::CString; use fmt::{self, Debug}; use mem; use string::String; @@ -56,22 +55,6 @@ impl OsString { OsString { inner: Buf::from_string(String::new()) } } - /// Constructs an `OsString` from a byte sequence. - /// - /// # Platform behavior - /// - /// On Unix systems, any byte sequence can be successfully - /// converted into an `OsString`. - /// - /// On Windows system, only UTF-8 byte sequences will successfully - /// convert; non UTF-8 data will produce `None`. - #[unstable(feature = "convert", reason = "recently added", issue = "27704")] - #[rustc_deprecated(reason = "RFC was closed, hides subtle Windows semantics", - since = "1.6.0")] - pub fn from_bytes<B>(bytes: B) -> Option<OsString> where B: Into<Vec<u8>> { - Self::_from_bytes(bytes.into()) - } - #[cfg(unix)] fn _from_bytes(vec: Vec<u8>) -> Option<OsString> { use os::unix::ffi::OsStringExt; @@ -294,41 +277,6 @@ impl OsStr { OsString { inner: self.inner.to_owned() } } - /// Yields this `OsStr` as a byte slice. - /// - /// # Platform behavior - /// - /// On Unix systems, this is a no-op. - /// - /// On Windows systems, this returns `None` unless the `OsStr` is - /// valid Unicode, in which case it produces UTF-8-encoded - /// data. This may entail checking validity. - #[unstable(feature = "convert", reason = "recently added", issue = "27704")] - #[rustc_deprecated(reason = "RFC was closed, hides subtle Windows semantics", - since = "1.6.0")] - pub fn to_bytes(&self) -> Option<&[u8]> { - if cfg!(windows) { - self.to_str().map(|s| s.as_bytes()) - } else { - Some(self.bytes()) - } - } - - /// Creates a `CString` containing this `OsStr` data. - /// - /// Fails if the `OsStr` contains interior nulls. - /// - /// This is a convenience for creating a `CString` from - /// `self.to_bytes()`, and inherits the platform behavior of the - /// `to_bytes` method. - #[unstable(feature = "convert", reason = "recently added", issue = "27704")] - #[rustc_deprecated(reason = "RFC was closed, hides subtle Windows semantics", - since = "1.6.0")] - #[allow(deprecated)] - pub fn to_cstring(&self) -> Option<CString> { - self.to_bytes().and_then(|b| CString::new(b).ok()) - } - /// Checks whether the `OsStr` is empty. #[unstable(feature = "osstring_simple_functions", reason = "recently added", issue = "29453")] diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index 6b88d498b10..b98344b01a7 100644 --- a/src/libstd/fs.rs +++ b/src/libstd/fs.rs @@ -85,19 +85,6 @@ pub struct ReadDir(fs_imp::ReadDir); #[stable(feature = "rust1", since = "1.0.0")] pub struct DirEntry(fs_imp::DirEntry); -/// An iterator that recursively walks over the contents of a directory. -#[unstable(feature = "fs_walk", - reason = "the precise semantics and defaults for a recursive walk \ - may change and this may end up accounting for files such \ - as symlinks differently", - issue = "27707")] -#[rustc_deprecated(reason = "superceded by the walkdir crate", - since = "1.6.0")] -pub struct WalkDir { - cur: Option<ReadDir>, - stack: Vec<io::Result<ReadDir>>, -} - /// Options and flags which can be used to configure how a file is opened. /// /// This builder exposes the ability to configure how a `File` is opened and @@ -1345,7 +1332,7 @@ pub fn remove_dir_all<P: AsRef<Path>>(path: P) -> io::Result<()> { /// use std::fs::{self, DirEntry}; /// use std::path::Path; /// -/// // one possible implementation of fs::walk_dir only visiting files +/// // one possible implementation of walking a directory only visiting files /// fn visit_dirs(dir: &Path, cb: &Fn(&DirEntry)) -> io::Result<()> { /// if try!(fs::metadata(dir)).is_dir() { /// for entry in try!(fs::read_dir(dir)) { @@ -1365,64 +1352,6 @@ pub fn read_dir<P: AsRef<Path>>(path: P) -> io::Result<ReadDir> { fs_imp::readdir(path.as_ref()).map(ReadDir) } -/// Returns an iterator that will recursively walk the directory structure -/// rooted at `path`. -/// -/// The path given will not be iterated over, and this will perform iteration in -/// some top-down order. The contents of unreadable subdirectories are ignored. -/// -/// The iterator will yield instances of `io::Result<DirEntry>`. New errors may -/// be encountered after an iterator is initially constructed. -#[unstable(feature = "fs_walk", - reason = "the precise semantics and defaults for a recursive walk \ - may change and this may end up accounting for files such \ - as symlinks differently", - issue = "27707")] -#[rustc_deprecated(reason = "superceded by the walkdir crate", - since = "1.6.0")] -#[allow(deprecated)] -pub fn walk_dir<P: AsRef<Path>>(path: P) -> io::Result<WalkDir> { - _walk_dir(path.as_ref()) -} - -#[allow(deprecated)] -fn _walk_dir(path: &Path) -> io::Result<WalkDir> { - let start = try!(read_dir(path)); - Ok(WalkDir { cur: Some(start), stack: Vec::new() }) -} - -#[unstable(feature = "fs_walk", issue = "27707")] -#[rustc_deprecated(reason = "superceded by the walkdir crate", - since = "1.6.0")] -#[allow(deprecated)] -impl Iterator for WalkDir { - type Item = io::Result<DirEntry>; - - fn next(&mut self) -> Option<io::Result<DirEntry>> { - loop { - if let Some(ref mut cur) = self.cur { - match cur.next() { - Some(Err(e)) => return Some(Err(e)), - Some(Ok(next)) => { - let path = next.path(); - if path.is_dir() { - self.stack.push(read_dir(&*path)); - } - return Some(Ok(next)) - } - None => {} - } - } - self.cur = None; - match self.stack.pop() { - Some(Err(e)) => return Some(Err(e)), - Some(Ok(next)) => self.cur = Some(next), - None => return None, - } - } - } -} - /// Changes the permissions found on a file or a directory. /// /// # Platform-specific behavior @@ -1866,35 +1795,6 @@ mod tests { } #[test] - #[allow(deprecated)] - fn file_test_walk_dir() { - let tmpdir = tmpdir(); - let dir = &tmpdir.join("walk_dir"); - check!(fs::create_dir(dir)); - - let dir1 = &dir.join("01/02/03"); - check!(fs::create_dir_all(dir1)); - check!(File::create(&dir1.join("04"))); - - let dir2 = &dir.join("11/12/13"); - check!(fs::create_dir_all(dir2)); - check!(File::create(&dir2.join("14"))); - - let files = check!(fs::walk_dir(dir)); - let mut cur = [0; 2]; - for f in files { - let f = f.unwrap().path(); - let stem = f.file_stem().unwrap().to_str().unwrap(); - let root = stem.as_bytes()[0] - b'0'; - let name = stem.as_bytes()[1] - b'0'; - assert!(cur[root as usize] < name); - cur[root as usize] = name; - } - - check!(fs::remove_dir_all(dir)); - } - - #[test] fn mkdir_path_already_exists_error() { let tmpdir = tmpdir(); let dir = &tmpdir.join("mkdir_error_twice"); diff --git a/src/libstd/io/error.rs b/src/libstd/io/error.rs index e3f17c839f1..9a605fc7bbf 100644 --- a/src/libstd/io/error.rs +++ b/src/libstd/io/error.rs @@ -150,12 +150,6 @@ pub enum ErrorKind { #[stable(feature = "rust1", since = "1.0.0")] Other, - #[allow(missing_docs)] - #[unstable(feature = "read_exact_old", reason = "recently added", - issue = "0")] - #[rustc_deprecated(since = "1.6.0", reason = "renamed to UnexpectedEof")] - UnexpectedEOF, - /// An error returned when an operation could not be completed because an /// "end of file" was reached prematurely. /// @@ -311,7 +305,6 @@ impl fmt::Display for Error { #[stable(feature = "rust1", since = "1.0.0")] impl error::Error for Error { - #[allow(deprecated)] // remove with UnexpectedEOF fn description(&self) -> &str { match self.repr { Repr::Os(..) => match self.kind() { @@ -332,7 +325,6 @@ impl error::Error for Error { ErrorKind::WriteZero => "write zero", ErrorKind::Interrupted => "operation interrupted", ErrorKind::Other => "other os error", - ErrorKind::UnexpectedEOF => "unexpected end of file", ErrorKind::UnexpectedEof => "unexpected end of file", ErrorKind::__Nonexhaustive => unreachable!() }, diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 61334f30924..60a720efb79 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -811,49 +811,6 @@ pub trait Read { fn take(self, limit: u64) -> Take<Self> where Self: Sized { Take { inner: self, limit: limit } } - - /// Creates a reader adaptor which will write all read data into the given - /// output stream. - /// - /// Whenever the returned `Read` instance is read it will write the read - /// data to `out`. The current semantics of this implementation imply that - /// a `write` error will not report how much data was initially read. - /// - /// # Examples - /// - /// [`File`][file]s implement `Read`: - /// - /// [file]: ../fs/struct.File.html - /// - /// ``` - /// #![feature(io)] - /// use std::io; - /// use std::io::prelude::*; - /// use std::fs::File; - /// - /// # fn foo() -> io::Result<()> { - /// let mut f = try!(File::open("foo.txt")); - /// let mut buffer1 = Vec::with_capacity(10); - /// let mut buffer2 = Vec::with_capacity(10); - /// - /// // write the output to buffer1 as we read - /// let mut handle = f.tee(&mut buffer1); - /// - /// try!(handle.read(&mut buffer2)); - /// # Ok(()) - /// # } - /// ``` - #[unstable(feature = "io", reason = "the semantics of a partial read/write \ - of where errors happen is currently \ - unclear and may change", - issue = "27802")] - #[rustc_deprecated(reason = "error handling semantics unclear and \ - don't seem to have an ergonomic resolution", - since = "1.6.0")] - #[allow(deprecated)] - fn tee<W: Write>(self, out: W) -> Tee<Self, W> where Self: Sized { - Tee { reader: self, writer: out } - } } /// A trait for objects which are byte-oriented sinks. @@ -1089,47 +1046,6 @@ pub trait Write { /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn by_ref(&mut self) -> &mut Self where Self: Sized { self } - - /// Creates a new writer which will write all data to both this writer and - /// another writer. - /// - /// All data written to the returned writer will both be written to `self` - /// as well as `other`. Note that the error semantics of the current - /// implementation do not precisely track where errors happen. For example - /// an error on the second call to `write` will not report that the first - /// call to `write` succeeded. - /// - /// # Examples - /// - /// ``` - /// #![feature(io)] - /// use std::io::prelude::*; - /// use std::fs::File; - /// - /// # fn foo() -> std::io::Result<()> { - /// let mut buffer1 = try!(File::create("foo.txt")); - /// let mut buffer2 = Vec::new(); - /// - /// // write the output to buffer1 as we read - /// let mut handle = buffer1.broadcast(&mut buffer2); - /// - /// try!(handle.write(b"some bytes")); - /// # Ok(()) - /// # } - /// ``` - #[unstable(feature = "io", reason = "the semantics of a partial read/write \ - of where errors happen is currently \ - unclear and may change", - issue = "27802")] - #[rustc_deprecated(reason = "error handling semantics unclear and \ - don't seem to have an ergonomic resolution", - since = "1.6.0")] - #[allow(deprecated)] - fn broadcast<W: Write>(self, other: W) -> Broadcast<Self, W> - where Self: Sized - { - Broadcast { first: self, second: other } - } } /// The `Seek` trait provides a cursor which can be moved within a stream of @@ -1500,41 +1416,6 @@ pub trait BufRead: Read { } } -/// A `Write` adaptor which will write data to multiple locations. -/// -/// This struct is generally created by calling [`broadcast()`][broadcast] on a -/// writer. Please see the documentation of `broadcast()` for more details. -/// -/// [broadcast]: trait.Write.html#method.broadcast -#[unstable(feature = "io", reason = "awaiting stability of Write::broadcast", - issue = "27802")] -#[rustc_deprecated(reason = "error handling semantics unclear and \ - don't seem to have an ergonomic resolution", - since = "1.6.0")] -pub struct Broadcast<T, U> { - first: T, - second: U, -} - -#[unstable(feature = "io", reason = "awaiting stability of Write::broadcast", - issue = "27802")] -#[rustc_deprecated(reason = "error handling semantics unclear and \ - don't seem to have an ergonomic resolution", - since = "1.6.0")] -#[allow(deprecated)] -impl<T: Write, U: Write> Write for Broadcast<T, U> { - fn write(&mut self, data: &[u8]) -> Result<usize> { - let n = try!(self.first.write(data)); - // FIXME: what if the write fails? (we wrote something) - try!(self.second.write_all(&data[..n])); - Ok(n) - } - - fn flush(&mut self) -> Result<()> { - self.first.flush().and(self.second.flush()) - } -} - /// Adaptor to chain together two readers. /// /// This struct is generally created by calling [`chain()`][chain] on a reader. @@ -1616,37 +1497,6 @@ impl<T: BufRead> BufRead for Take<T> { } } -/// An adaptor which will emit all read data to a specified writer as well. -/// -/// This struct is generally created by calling [`tee()`][tee] on a reader. -/// Please see the documentation of `tee()` for more details. -/// -/// [tee]: trait.Read.html#method.tee -#[unstable(feature = "io", reason = "awaiting stability of Read::tee", - issue = "27802")] -#[rustc_deprecated(reason = "error handling semantics unclear and \ - don't seem to have an ergonomic resolution", - since = "1.6.0")] -pub struct Tee<R, W> { - reader: R, - writer: W, -} - -#[unstable(feature = "io", reason = "awaiting stability of Read::tee", - issue = "27802")] -#[rustc_deprecated(reason = "error handling semantics unclear and \ - don't seem to have an ergonomic resolution", - since = "1.6.0")] -#[allow(deprecated)] -impl<R: Read, W: Write> Read for Tee<R, W> { - fn read(&mut self, buf: &mut [u8]) -> Result<usize> { - let n = try!(self.reader.read(buf)); - // FIXME: what if the write fails? (we read something) - try!(self.writer.write_all(&buf[..n])); - Ok(n) - } -} - /// An iterator over `u8` values of a reader. /// /// This struct is generally created by calling [`bytes()`][bytes] on a reader. diff --git a/src/libstd/io/util.rs b/src/libstd/io/util.rs index e05a0d577ff..fddb095f21e 100644 --- a/src/libstd/io/util.rs +++ b/src/libstd/io/util.rs @@ -197,31 +197,4 @@ mod tests { assert_eq!(repeat(4).take(100).bytes().next().unwrap().unwrap(), 4); assert_eq!(repeat(1).take(10).chain(repeat(2).take(10)).bytes().count(), 20); } - - #[test] - #[allow(deprecated)] - fn tee() { - let mut buf = [0; 10]; - { - let mut ptr: &mut [u8] = &mut buf; - assert_eq!(repeat(4).tee(&mut ptr).take(5).read(&mut [0; 10]).unwrap(), 5); - } - assert_eq!(buf, [4, 4, 4, 4, 4, 0, 0, 0, 0, 0]); - } - - #[test] - #[allow(deprecated)] - fn broadcast() { - let mut buf1 = [0; 10]; - let mut buf2 = [0; 10]; - { - let mut ptr1: &mut [u8] = &mut buf1; - let mut ptr2: &mut [u8] = &mut buf2; - - assert_eq!((&mut ptr1).broadcast(&mut ptr2) - .write(&[1, 2, 3]).unwrap(), 3); - } - assert_eq!(buf1, buf2); - assert_eq!(buf1, [1, 2, 3, 0, 0, 0, 0, 0, 0, 0]); - } } diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 07a6992bbc0..cd0e3a030bd 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -418,7 +418,6 @@ pub mod num; pub mod thread; pub mod collections; -pub mod dynamic_lib; pub mod env; pub mod ffi; pub mod fs; diff --git a/src/libstd/net/mod.rs b/src/libstd/net/mod.rs index d263bf38495..22332b709ce 100644 --- a/src/libstd/net/mod.rs +++ b/src/libstd/net/mod.rs @@ -128,33 +128,3 @@ impl Iterator for LookupHost { pub fn lookup_host(host: &str) -> io::Result<LookupHost> { net_imp::lookup_host(host).map(LookupHost) } - -/// Resolve the given address to a hostname. -/// -/// This function may perform a DNS query to resolve `addr` and may also inspect -/// system configuration to resolve the specified address. If the address -/// cannot be resolved, it is returned in string format. -/// -/// # Examples -/// -/// ```no_run -/// #![feature(lookup_addr)] -/// #![feature(ip_addr)] -/// -/// use std::net::{self, Ipv4Addr, IpAddr}; -/// -/// let ip_addr = "8.8.8.8"; -/// let addr: Ipv4Addr = ip_addr.parse().unwrap(); -/// let hostname = net::lookup_addr(&IpAddr::V4(addr)).unwrap(); -/// -/// println!("{} --> {}", ip_addr, hostname); -/// // Output: 8.8.8.8 --> google-public-dns-a.google.com -/// ``` -#[unstable(feature = "lookup_addr", reason = "recent addition", - issue = "27705")] -#[rustc_deprecated(reason = "ipaddr type is being deprecated", - since = "1.6.0")] -#[allow(deprecated)] -pub fn lookup_addr(addr: &IpAddr) -> io::Result<String> { - net_imp::lookup_addr(addr) -} diff --git a/src/libstd/num/mod.rs b/src/libstd/num/mod.rs index dd0d874ee4b..1886b4fdf59 100644 --- a/src/libstd/num/mod.rs +++ b/src/libstd/num/mod.rs @@ -21,7 +21,7 @@ pub use core::num::{Zero, One}; #[stable(feature = "rust1", since = "1.0.0")] pub use core::num::{FpCategory, ParseIntError, ParseFloatError}; #[stable(feature = "rust1", since = "1.0.0")] -pub use core::num::{wrapping, Wrapping}; +pub use core::num::Wrapping; #[cfg(test)] use cmp::PartialEq; #[cfg(test)] use fmt; diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 94967bfb96a..5309cc3c858 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -100,8 +100,7 @@ #![stable(feature = "rust1", since = "1.0.0")] use ascii::*; -#[allow(deprecated)] -use borrow::{Borrow, IntoCow, ToOwned, Cow}; +use borrow::{Borrow, ToOwned, Cow}; use cmp; use error::Error; use fmt; @@ -781,14 +780,6 @@ impl<'a> Components<'a> { } } } - - /// Examine the next component without consuming it. - #[unstable(feature = "path_components_peek", issue = "27727")] - #[rustc_deprecated(reason = "use peekable() instead", - since = "1.6.0")] - pub fn peek(&self) -> Option<Component<'a>> { - self.clone().next() - } } #[stable(feature = "rust1", since = "1.0.0")] @@ -1218,22 +1209,6 @@ impl Borrow<Path> for PathBuf { } } -#[stable(feature = "rust1", since = "1.0.0")] -#[allow(deprecated)] -impl IntoCow<'static, Path> for PathBuf { - fn into_cow(self) -> Cow<'static, Path> { - Cow::Owned(self) - } -} - -#[stable(feature = "rust1", since = "1.0.0")] -#[allow(deprecated)] -impl<'a> IntoCow<'a, Path> for &'a Path { - fn into_cow(self) -> Cow<'a, Path> { - Cow::Borrowed(self) - } -} - #[stable(feature = "cow_from_path", since = "1.6.0")] impl<'a> From<&'a Path> for Cow<'a, Path> { #[inline] @@ -1474,17 +1449,7 @@ impl Path { !self.is_absolute() } - /// Returns the *prefix* of a path, if any. - /// - /// Prefixes are relevant only for Windows paths, and consist of volumes - /// like `C:`, UNC prefixes like `\\server`, and others described in more - /// detail in `std::os::windows::PathExt`. - #[unstable(feature = "path_prefix", - reason = "uncertain whether to expose this convenience", - issue = "27722")] - #[rustc_deprecated(since = "1.7.0", - reason = "inspect components().next() instead")] - pub fn prefix(&self) -> Option<Prefix> { + fn prefix(&self) -> Option<Prefix> { self.components().prefix } @@ -1568,17 +1533,6 @@ impl Path { /// Returns a path that, when joined onto `base`, yields `self`. /// - /// If `base` is not a prefix of `self` (i.e. `starts_with` - /// returns false), then `relative_from` returns `None`. - #[unstable(feature = "path_relative_from", reason = "see #23284", - issue = "23284")] - #[rustc_deprecated(since = "1.7.0", reason = "renamed to strip_prefix")] - pub fn relative_from<'a, P: ?Sized + AsRef<Path>>(&'a self, base: &'a P) -> Option<&Path> { - self._strip_prefix(base.as_ref()).ok() - } - - /// Returns a path that, when joined onto `base`, yields `self`. - /// /// # Errors /// /// If `base` is not a prefix of `self` (i.e. `starts_with` @@ -2237,27 +2191,6 @@ mod tests { ); #[test] - #[allow(deprecated)] - fn into_cow() { - use borrow::{Cow, IntoCow}; - - let static_path = Path::new("/home/foo"); - let static_cow_path: Cow<'static, Path> = static_path.into_cow(); - let pathbuf = PathBuf::from("/home/foo"); - - { - let path: &Path = &pathbuf; - let borrowed_cow_path: Cow<Path> = path.into_cow(); - - assert_eq!(static_cow_path, borrowed_cow_path); - } - - let owned_cow_path: Cow<'static, Path> = pathbuf.into_cow(); - - assert_eq!(static_cow_path, owned_cow_path); - } - - #[test] fn into() { use borrow::Cow; diff --git a/src/libstd/sync/condvar.rs b/src/libstd/sync/condvar.rs index 0ff3a690702..64468be396f 100644 --- a/src/libstd/sync/condvar.rs +++ b/src/libstd/sync/condvar.rs @@ -167,13 +167,12 @@ impl Condvar { /// returns, regardless of whether the timeout elapsed or not. #[stable(feature = "rust1", since = "1.0.0")] #[rustc_deprecated(since = "1.6.0", reason = "replaced by `std::sync::Condvar::wait_timeout`")] - #[allow(deprecated)] pub fn wait_timeout_ms<'a, T>(&self, guard: MutexGuard<'a, T>, ms: u32) -> LockResult<(MutexGuard<'a, T>, bool)> { - unsafe { - let me: &'static Condvar = &*(self as *const _); - me.inner.wait_timeout_ms(guard, ms) - } + let res = self.wait_timeout(guard, Duration::from_millis(ms as u64)); + poison::map_result(res, |(a, b)| { + (a, !b.timed_out()) + }) } /// Waits on this condition variable for a notification, timing out after a @@ -200,30 +199,6 @@ impl Condvar { } } - /// Waits on this condition variable for a notification, timing out after a - /// specified duration. - /// - /// The semantics of this function are equivalent to `wait_timeout` except - /// that the implementation will repeatedly wait while the duration has not - /// passed and the provided function returns `false`. - #[unstable(feature = "wait_timeout_with", - reason = "unsure if this API is broadly needed or what form it should take", - issue = "27748")] - #[rustc_deprecated(since = "1.8.0", - reason = "wonky signature and questionable \ - implementation didn't justify existence")] - pub fn wait_timeout_with<'a, T, F>(&self, - guard: MutexGuard<'a, T>, - dur: Duration, - f: F) - -> LockResult<(MutexGuard<'a, T>, WaitTimeoutResult)> - where F: FnMut(LockResult<&mut T>) -> bool { - unsafe { - let me: &'static Condvar = &*(self as *const _); - me.inner.wait_timeout_with(guard, dur, f) - } - } - /// Wakes up one blocked thread on this condvar. /// /// If there is a blocked thread on this condition variable, then it will @@ -293,26 +268,6 @@ impl StaticCondvar { #[unstable(feature = "static_condvar", reason = "may be merged with Condvar in the future", issue = "27717")] - #[rustc_deprecated(since = "1.6.0", - reason = "replaced by `std::sync::StaticCondvar::wait_timeout`")] - pub fn wait_timeout_ms<'a, T>(&'static self, guard: MutexGuard<'a, T>, ms: u32) - -> LockResult<(MutexGuard<'a, T>, bool)> { - match self.wait_timeout(guard, Duration::from_millis(ms as u64)) { - Ok((guard, timed_out)) => Ok((guard, !timed_out.timed_out())), - Err(poison) => { - let (guard, timed_out) = poison.into_inner(); - Err(PoisonError::new((guard, !timed_out.timed_out()))) - } - } - } - - /// Waits on this condition variable for a notification, timing out after a - /// specified duration. - /// - /// See `Condvar::wait_timeout`. - #[unstable(feature = "static_condvar", - reason = "may be merged with Condvar in the future", - issue = "27717")] pub fn wait_timeout<'a, T>(&'static self, guard: MutexGuard<'a, T>, timeout: Duration) diff --git a/src/libstd/sync/mod.rs b/src/libstd/sync/mod.rs index 1a42b091831..c20b422d40c 100644 --- a/src/libstd/sync/mod.rs +++ b/src/libstd/sync/mod.rs @@ -38,9 +38,6 @@ pub use sys_common::poison::{PoisonError, TryLockError, TryLockResult, LockResul pub use self::rwlock::{RwLockReadGuard, RwLockWriteGuard}; #[stable(feature = "rust1", since = "1.0.0")] pub use self::rwlock::{RwLock, StaticRwLock, RW_LOCK_INIT}; -#[stable(feature = "rust1", since = "1.0.0")] -#[allow(deprecated)] -pub use self::semaphore::{Semaphore, SemaphoreGuard}; pub mod mpsc; @@ -49,4 +46,3 @@ mod condvar; mod mutex; mod once; mod rwlock; -mod semaphore; diff --git a/src/libstd/sync/semaphore.rs b/src/libstd/sync/semaphore.rs deleted file mode 100644 index dd76444d3ae..00000000000 --- a/src/libstd/sync/semaphore.rs +++ /dev/null @@ -1,226 +0,0 @@ -// 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. - -#![unstable(feature = "semaphore", - reason = "the interaction between semaphores and the acquisition/release \ - of resources is currently unclear", - issue = "27798")] -#![allow(deprecated)] - -use ops::Drop; -use sync::{Mutex, Condvar}; - -/// A counting, blocking, semaphore. -/// -/// Semaphores are a form of atomic counter where access is only granted if the -/// counter is a positive value. Each acquisition will block the calling thread -/// until the counter is positive, and each release will increment the counter -/// and unblock any threads if necessary. -/// -/// # Examples -/// -/// ``` -/// #![feature(semaphore)] -/// -/// use std::sync::Semaphore; -/// -/// // Create a semaphore that represents 5 resources -/// let sem = Semaphore::new(5); -/// -/// // Acquire one of the resources -/// sem.acquire(); -/// -/// // Acquire one of the resources for a limited period of time -/// { -/// let _guard = sem.access(); -/// // ... -/// } // resources is released here -/// -/// // Release our initially acquired resource -/// sem.release(); -/// ``` -#[rustc_deprecated(since = "1.7.0", - reason = "easily confused with system semaphores and not \ - used enough to pull its weight")] -#[unstable(feature = "semaphore", - reason = "the interaction between semaphores and the acquisition/release \ - of resources is currently unclear", - issue = "27798")] -pub struct Semaphore { - lock: Mutex<isize>, - cvar: Condvar, -} - -/// An RAII guard which will release a resource acquired from a semaphore when -/// dropped. -#[rustc_deprecated(since = "1.7.0", - reason = "easily confused with system semaphores and not \ - used enough to pull its weight")] -#[unstable(feature = "semaphore", - reason = "the interaction between semaphores and the acquisition/release \ - of resources is currently unclear", - issue = "27798")] -pub struct SemaphoreGuard<'a> { - sem: &'a Semaphore, -} - -#[rustc_deprecated(since = "1.7.0", - reason = "easily confused with system semaphores and not \ - used enough to pull its weight")] -#[unstable(feature = "semaphore", - reason = "the interaction between semaphores and the acquisition/release \ - of resources is currently unclear", - issue = "27798")] -impl Semaphore { - /// Creates a new semaphore with the initial count specified. - /// - /// The count specified can be thought of as a number of resources, and a - /// call to `acquire` or `access` will block until at least one resource is - /// available. It is valid to initialize a semaphore with a negative count. - pub fn new(count: isize) -> Semaphore { - Semaphore { - lock: Mutex::new(count), - cvar: Condvar::new(), - } - } - - /// Acquires a resource of this semaphore, blocking the current thread until - /// it can do so. - /// - /// This method will block until the internal count of the semaphore is at - /// least 1. - pub fn acquire(&self) { - let mut count = self.lock.lock().unwrap(); - while *count <= 0 { - count = self.cvar.wait(count).unwrap(); - } - *count -= 1; - } - - /// Release a resource from this semaphore. - /// - /// This will increment the number of resources in this semaphore by 1 and - /// will notify any pending waiters in `acquire` or `access` if necessary. - pub fn release(&self) { - *self.lock.lock().unwrap() += 1; - self.cvar.notify_one(); - } - - /// Acquires a resource of this semaphore, returning an RAII guard to - /// release the semaphore when dropped. - /// - /// This function is semantically equivalent to an `acquire` followed by a - /// `release` when the guard returned is dropped. - pub fn access(&self) -> SemaphoreGuard { - self.acquire(); - SemaphoreGuard { sem: self } - } -} - -#[stable(feature = "rust1", since = "1.0.0")] -impl<'a> Drop for SemaphoreGuard<'a> { - fn drop(&mut self) { - self.sem.release(); - } -} - -#[cfg(test)] -mod tests { - use prelude::v1::*; - - use sync::Arc; - use super::Semaphore; - use sync::mpsc::channel; - use thread; - - #[test] - fn test_sem_acquire_release() { - let s = Semaphore::new(1); - s.acquire(); - s.release(); - s.acquire(); - } - - #[test] - fn test_sem_basic() { - let s = Semaphore::new(1); - let _g = s.access(); - } - - #[test] - fn test_sem_as_mutex() { - let s = Arc::new(Semaphore::new(1)); - let s2 = s.clone(); - let _t = thread::spawn(move|| { - let _g = s2.access(); - }); - let _g = s.access(); - } - - #[test] - fn test_sem_as_cvar() { - /* Child waits and parent signals */ - let (tx, rx) = channel(); - let s = Arc::new(Semaphore::new(0)); - let s2 = s.clone(); - let _t = thread::spawn(move|| { - s2.acquire(); - tx.send(()).unwrap(); - }); - s.release(); - let _ = rx.recv(); - - /* Parent waits and child signals */ - let (tx, rx) = channel(); - let s = Arc::new(Semaphore::new(0)); - let s2 = s.clone(); - let _t = thread::spawn(move|| { - s2.release(); - let _ = rx.recv(); - }); - s.acquire(); - tx.send(()).unwrap(); - } - - #[test] - fn test_sem_multi_resource() { - // Parent and child both get in the critical section at the same - // time, and shake hands. - let s = Arc::new(Semaphore::new(2)); - let s2 = s.clone(); - let (tx1, rx1) = channel(); - let (tx2, rx2) = channel(); - let _t = thread::spawn(move|| { - let _g = s2.access(); - let _ = rx2.recv(); - tx1.send(()).unwrap(); - }); - let _g = s.access(); - tx2.send(()).unwrap(); - rx1.recv().unwrap(); - } - - #[test] - fn test_sem_runtime_friendly_blocking() { - let s = Arc::new(Semaphore::new(1)); - let s2 = s.clone(); - let (tx, rx) = channel(); - { - let _g = s.access(); - thread::spawn(move|| { - tx.send(()).unwrap(); - drop(s2.access()); - tx.send(()).unwrap(); - }); - rx.recv().unwrap(); // wait for child to come alive - } - rx.recv().unwrap(); // wait for child to be done - } -} diff --git a/src/libstd/sys/common/net.rs b/src/libstd/sys/common/net.rs index aa92e5be114..42714feb921 100644 --- a/src/libstd/sys/common/net.rs +++ b/src/libstd/sys/common/net.rs @@ -11,15 +11,13 @@ use prelude::v1::*; use cmp; -use ffi::{CStr, CString}; +use ffi::CString; use fmt; use io::{self, Error, ErrorKind}; -use libc::{c_int, c_char, c_void}; +use libc::{c_int, c_void}; use mem; -#[allow(deprecated)] -use net::{SocketAddr, Shutdown, IpAddr, Ipv4Addr, Ipv6Addr}; +use net::{SocketAddr, Shutdown, Ipv4Addr, Ipv6Addr}; use ptr; -use str::from_utf8; use sys::net::{cvt, cvt_r, cvt_gai, Socket, init, wrlen_t}; use sys::net::netc as c; use sys_common::{AsInner, FromInner, IntoInner}; @@ -155,34 +153,6 @@ pub fn lookup_host(host: &str) -> io::Result<LookupHost> { } //////////////////////////////////////////////////////////////////////////////// -// lookup_addr -//////////////////////////////////////////////////////////////////////////////// - -#[allow(deprecated)] -pub fn lookup_addr(addr: &IpAddr) -> io::Result<String> { - init(); - - let saddr = SocketAddr::new(*addr, 0); - let (inner, len) = saddr.into_inner(); - let mut hostbuf = [0 as c_char; c::NI_MAXHOST as usize]; - - let data = unsafe { - try!(cvt_gai(c::getnameinfo(inner, len, - hostbuf.as_mut_ptr(), - c::NI_MAXHOST, - ptr::null_mut(), 0, 0))); - - CStr::from_ptr(hostbuf.as_ptr()) - }; - - match from_utf8(data.to_bytes()) { - Ok(name) => Ok(name.to_owned()), - Err(_) => Err(io::Error::new(io::ErrorKind::Other, - "failed to lookup address information")) - } -} - -//////////////////////////////////////////////////////////////////////////////// // TCP streams //////////////////////////////////////////////////////////////////////////////// diff --git a/src/libstd/sys/common/remutex.rs b/src/libstd/sys/common/remutex.rs index 2e2be63c3cb..1793ad0e445 100644 --- a/src/libstd/sys/common/remutex.rs +++ b/src/libstd/sys/common/remutex.rs @@ -8,9 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![unstable(feature = "reentrant_mutex", reason = "new API", - issue = "27738")] - use prelude::v1::*; use fmt; diff --git a/src/libstd/sys/unix/ext/fs.rs b/src/libstd/sys/unix/ext/fs.rs index bdde25648ed..a1528458860 100644 --- a/src/libstd/sys/unix/ext/fs.rs +++ b/src/libstd/sys/unix/ext/fs.rs @@ -15,90 +15,11 @@ use fs::{self, Permissions, OpenOptions}; use io; use libc; -#[allow(deprecated)] -use os::unix::raw; use path::Path; use sys; use sys_common::{FromInner, AsInner, AsInnerMut}; use sys::platform::fs::MetadataExt as UnixMetadataExt; -#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] -#[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] -#[allow(deprecated)] -pub const USER_READ: raw::mode_t = 0o400; -#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] -#[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] -#[allow(deprecated)] -pub const USER_WRITE: raw::mode_t = 0o200; -#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] -#[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] -#[allow(deprecated)] -pub const USER_EXECUTE: raw::mode_t = 0o100; -#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] -#[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] -#[allow(deprecated)] -pub const USER_RWX: raw::mode_t = 0o700; -#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] -#[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] -#[allow(deprecated)] -pub const GROUP_READ: raw::mode_t = 0o040; -#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] -#[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] -#[allow(deprecated)] -pub const GROUP_WRITE: raw::mode_t = 0o020; -#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] -#[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] -#[allow(deprecated)] -pub const GROUP_EXECUTE: raw::mode_t = 0o010; -#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] -#[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] -#[allow(deprecated)] -pub const GROUP_RWX: raw::mode_t = 0o070; -#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] -#[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] -#[allow(deprecated)] -pub const OTHER_READ: raw::mode_t = 0o004; -#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] -#[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] -#[allow(deprecated)] -pub const OTHER_WRITE: raw::mode_t = 0o002; -#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] -#[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] -#[allow(deprecated)] -pub const OTHER_EXECUTE: raw::mode_t = 0o001; -#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] -#[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] -#[allow(deprecated)] -pub const OTHER_RWX: raw::mode_t = 0o007; -#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] -#[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] -#[allow(deprecated)] -pub const ALL_READ: raw::mode_t = 0o444; -#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] -#[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] -#[allow(deprecated)] -pub const ALL_WRITE: raw::mode_t = 0o222; -#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] -#[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] -#[allow(deprecated)] -pub const ALL_EXECUTE: raw::mode_t = 0o111; -#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] -#[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] -#[allow(deprecated)] -pub const ALL_RWX: raw::mode_t = 0o777; -#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] -#[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] -#[allow(deprecated)] -pub const SETUID: raw::mode_t = 0o4000; -#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] -#[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] -#[allow(deprecated)] -pub const SETGID: raw::mode_t = 0o2000; -#[unstable(feature = "fs_mode", reason = "recently added API", issue = "27712")] -#[rustc_deprecated(since = "1.7.0", reason = "moved to the libc crate instead")] -#[allow(deprecated)] -pub const STICKY_BIT: raw::mode_t = 0o1000; - /// Unix-specific extensions to `Permissions` #[stable(feature = "fs_ext", since = "1.1.0")] pub trait PermissionsExt { diff --git a/src/libstd/sys/windows/backtrace.rs b/src/libstd/sys/windows/backtrace.rs index 80ff0cb0453..3cc3a631b89 100644 --- a/src/libstd/sys/windows/backtrace.rs +++ b/src/libstd/sys/windows/backtrace.rs @@ -26,22 +26,22 @@ use io::prelude::*; -use dynamic_lib::DynamicLibrary; use io; use libc::c_void; use mem; -use path::Path; use ptr; use sync::StaticMutex; use sys::c; +use sys::dynamic_lib::DynamicLibrary; -macro_rules! sym{ ($lib:expr, $e:expr, $t:ident) => (unsafe { - let lib = $lib; - match lib.symbol($e) { - Ok(f) => $crate::mem::transmute::<*mut u8, $t>(f), - Err(..) => return Ok(()) - } -}) } +macro_rules! sym { + ($lib:expr, $e:expr, $t:ident) => ( + match $lib.symbol($e) { + Ok(f) => $crate::mem::transmute::<usize, $t>(f), + Err(..) => return Ok(()) + } + ) +} #[cfg(target_env = "msvc")] #[path = "printing/msvc.rs"] @@ -52,16 +52,16 @@ mod printing; mod printing; type SymInitializeFn = - extern "system" fn(c::HANDLE, *mut c_void, - c::BOOL) -> c::BOOL; + unsafe extern "system" fn(c::HANDLE, *mut c_void, + c::BOOL) -> c::BOOL; type SymCleanupFn = - extern "system" fn(c::HANDLE) -> c::BOOL; + unsafe extern "system" fn(c::HANDLE) -> c::BOOL; type StackWalk64Fn = - extern "system" fn(c::DWORD, c::HANDLE, c::HANDLE, - *mut c::STACKFRAME64, *mut c::CONTEXT, - *mut c_void, *mut c_void, - *mut c_void, *mut c_void) -> c::BOOL; + unsafe extern "system" fn(c::DWORD, c::HANDLE, c::HANDLE, + *mut c::STACKFRAME64, *mut c::CONTEXT, + *mut c_void, *mut c_void, + *mut c_void, *mut c_void) -> c::BOOL; #[cfg(target_arch = "x86")] pub fn init_frame(frame: &mut c::STACKFRAME64, @@ -93,7 +93,9 @@ struct Cleanup { } impl Drop for Cleanup { - fn drop(&mut self) { (self.SymCleanup)(self.handle); } + fn drop(&mut self) { + unsafe { (self.SymCleanup)(self.handle); } + } } pub fn write(w: &mut Write) -> io::Result<()> { @@ -102,52 +104,50 @@ pub fn write(w: &mut Write) -> io::Result<()> { static LOCK: StaticMutex = StaticMutex::new(); let _g = LOCK.lock(); - // Open up dbghelp.dll, we don't link to it explicitly because it can't - // always be found. Additionally, it's nice having fewer dependencies. - let path = Path::new("dbghelp.dll"); - let dbghelp = match DynamicLibrary::open(Some(&path)) { + let dbghelp = match DynamicLibrary::open("dbghelp.dll") { Ok(lib) => lib, Err(..) => return Ok(()), }; - - // Fetch the symbols necessary from dbghelp.dll - let SymInitialize = sym!(&dbghelp, "SymInitialize", SymInitializeFn); - let SymCleanup = sym!(&dbghelp, "SymCleanup", SymCleanupFn); - let StackWalk64 = sym!(&dbghelp, "StackWalk64", StackWalk64Fn); - - // Allocate necessary structures for doing the stack walk - let process = unsafe { c::GetCurrentProcess() }; - let thread = unsafe { c::GetCurrentThread() }; - let mut context: c::CONTEXT = unsafe { mem::zeroed() }; - unsafe { c::RtlCaptureContext(&mut context); } - let mut frame: c::STACKFRAME64 = unsafe { mem::zeroed() }; - let image = init_frame(&mut frame, &context); - - // Initialize this process's symbols - let ret = SymInitialize(process, ptr::null_mut(), c::TRUE); - if ret != c::TRUE { return Ok(()) } - let _c = Cleanup { handle: process, SymCleanup: SymCleanup }; - - // And now that we're done with all the setup, do the stack walking! - // Start from -1 to avoid printing this stack frame, which will - // always be exactly the same. - let mut i = -1; - try!(write!(w, "stack backtrace:\n")); - while StackWalk64(image, process, thread, &mut frame, &mut context, - ptr::null_mut(), - ptr::null_mut(), - ptr::null_mut(), - ptr::null_mut()) == c::TRUE { - let addr = frame.AddrPC.Offset; - if addr == frame.AddrReturn.Offset || addr == 0 || - frame.AddrReturn.Offset == 0 { break } - - i += 1; - - if i >= 0 { - try!(printing::print(w, i, addr-1, &dbghelp, process)); + unsafe { + // Fetch the symbols necessary from dbghelp.dll + let SymInitialize = sym!(dbghelp, "SymInitialize", SymInitializeFn); + let SymCleanup = sym!(dbghelp, "SymCleanup", SymCleanupFn); + let StackWalk64 = sym!(dbghelp, "StackWalk64", StackWalk64Fn); + + // Allocate necessary structures for doing the stack walk + let process = c::GetCurrentProcess(); + let thread = c::GetCurrentThread(); + let mut context: c::CONTEXT = mem::zeroed(); + c::RtlCaptureContext(&mut context); + let mut frame: c::STACKFRAME64 = mem::zeroed(); + let image = init_frame(&mut frame, &context); + + // Initialize this process's symbols + let ret = SymInitialize(process, ptr::null_mut(), c::TRUE); + if ret != c::TRUE { return Ok(()) } + let _c = Cleanup { handle: process, SymCleanup: SymCleanup }; + + // And now that we're done with all the setup, do the stack walking! + // Start from -1 to avoid printing this stack frame, which will + // always be exactly the same. + let mut i = -1; + try!(write!(w, "stack backtrace:\n")); + while StackWalk64(image, process, thread, &mut frame, &mut context, + ptr::null_mut(), + ptr::null_mut(), + ptr::null_mut(), + ptr::null_mut()) == c::TRUE { + let addr = frame.AddrPC.Offset; + if addr == frame.AddrReturn.Offset || addr == 0 || + frame.AddrReturn.Offset == 0 { break } + + i += 1; + + if i >= 0 { + try!(printing::print(w, i, addr - 1, process, &dbghelp)); + } } - } - Ok(()) + Ok(()) + } } diff --git a/src/libstd/sys/windows/c.rs b/src/libstd/sys/windows/c.rs index 002ffc7c868..ab24b9e6fd6 100644 --- a/src/libstd/sys/windows/c.rs +++ b/src/libstd/sys/windows/c.rs @@ -154,8 +154,6 @@ pub const WSAESHUTDOWN: c_int = 10058; pub const WSAETIMEDOUT: c_int = 10060; pub const WSAECONNREFUSED: c_int = 10061; -pub const NI_MAXHOST: DWORD = 1025; - pub const MAX_PROTOCOL_CHAIN: DWORD = 7; pub const TOKEN_READ: DWORD = 0x20008; @@ -1099,18 +1097,11 @@ extern "system" { hints: *const ADDRINFOA, res: *mut *mut ADDRINFOA) -> c_int; pub fn freeaddrinfo(res: *mut ADDRINFOA); - pub fn getnameinfo(sa: *const SOCKADDR, salen: c_int, - host: *mut c_char, hostlen: DWORD, - serv: *mut c_char, servlen: DWORD, - flags: c_int) -> c_int; pub fn LoadLibraryW(name: LPCWSTR) -> HMODULE; - pub fn GetModuleHandleExW(dwFlags: DWORD, name: LPCWSTR, - handle: *mut HMODULE) -> BOOL; + pub fn FreeLibrary(handle: HMODULE) -> BOOL; pub fn GetProcAddress(handle: HMODULE, name: LPCSTR) -> *mut c_void; - pub fn FreeLibrary(handle: HMODULE) -> BOOL; - pub fn SetErrorMode(uMode: c_uint) -> c_uint; pub fn GetModuleHandleW(lpModuleName: LPCWSTR) -> HMODULE; pub fn CryptAcquireContextA(phProv: *mut HCRYPTPROV, pszContainer: LPCSTR, @@ -1177,10 +1168,6 @@ compat_fn! { _dwFlags: DWORD) -> DWORD { SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0 } - pub fn SetThreadErrorMode(_dwNewMode: DWORD, - _lpOldMode: *mut DWORD) -> c_uint { - SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0 - } pub fn SetThreadStackGuarantee(_size: *mut c_ulong) -> BOOL { SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0 } diff --git a/src/libstd/sys/windows/dynamic_lib.rs b/src/libstd/sys/windows/dynamic_lib.rs new file mode 100644 index 00000000000..84cfbe5e721 --- /dev/null +++ b/src/libstd/sys/windows/dynamic_lib.rs @@ -0,0 +1,55 @@ +// Copyright 2016 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. + +use prelude::v1::*; +use os::windows::prelude::*; + +use ffi::{CString, OsStr}; +use io; +use sys::c; + +pub struct DynamicLibrary { + handle: c::HMODULE, +} + +impl DynamicLibrary { + pub fn open(filename: &str) -> io::Result<DynamicLibrary> { + let filename = OsStr::new(filename) + .encode_wide() + .chain(Some(0)) + .collect::<Vec<_>>(); + let result = unsafe { + c::LoadLibraryW(filename.as_ptr()) + }; + if result.is_null() { + Err(io::Error::last_os_error()) + } else { + Ok(DynamicLibrary { handle: result }) + } + } + + pub fn symbol(&self, symbol: &str) -> io::Result<usize> { + let symbol = try!(CString::new(symbol)); + unsafe { + match c::GetProcAddress(self.handle, symbol.as_ptr()) as usize { + 0 => Err(io::Error::last_os_error()), + n => Ok(n), + } + } + } +} + +impl Drop for DynamicLibrary { + fn drop(&mut self) { + unsafe { + c::FreeLibrary(self.handle); + } + } +} diff --git a/src/libstd/sys/windows/mod.rs b/src/libstd/sys/windows/mod.rs index 765e6e09427..384940e4dc4 100644 --- a/src/libstd/sys/windows/mod.rs +++ b/src/libstd/sys/windows/mod.rs @@ -24,6 +24,7 @@ use time::Duration; pub mod backtrace; pub mod c; pub mod condvar; +pub mod dynamic_lib; pub mod ext; pub mod fs; pub mod handle; diff --git a/src/libstd/sys/windows/printing/gnu.rs b/src/libstd/sys/windows/printing/gnu.rs index c1367d5381d..be2d5273c07 100644 --- a/src/libstd/sys/windows/printing/gnu.rs +++ b/src/libstd/sys/windows/printing/gnu.rs @@ -8,18 +8,19 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![allow(deprecated)] - -use dynamic_lib::DynamicLibrary; use io::prelude::*; use io; -use sys::c; use libc::c_void; - +use sys::c; +use sys::dynamic_lib::DynamicLibrary; use sys_common::gnu::libbacktrace; -pub fn print(w: &mut Write, i: isize, addr: u64, _: &DynamicLibrary, _: c::HANDLE) - -> io::Result<()> { +pub fn print(w: &mut Write, + i: isize, + addr: u64, + _process: c::HANDLE, + _dbghelp: &DynamicLibrary) + -> io::Result<()> { let addr = addr as usize as *mut c_void; libbacktrace::print(w, i, addr, addr) } diff --git a/src/libstd/sys/windows/printing/msvc.rs b/src/libstd/sys/windows/printing/msvc.rs index 255c645c3fb..37aaa1f1b0e 100644 --- a/src/libstd/sys/windows/printing/msvc.rs +++ b/src/libstd/sys/windows/printing/msvc.rs @@ -8,60 +8,66 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![allow(deprecated)] - -use dynamic_lib::DynamicLibrary; use ffi::CStr; use io::prelude::*; use io; use libc::{c_ulong, c_int, c_char, c_void}; use mem; use sys::c; +use sys::dynamic_lib::DynamicLibrary; use sys_common::backtrace::{output, output_fileline}; type SymFromAddrFn = - extern "system" fn(c::HANDLE, u64, *mut u64, - *mut c::SYMBOL_INFO) -> c::BOOL; + unsafe extern "system" fn(c::HANDLE, u64, *mut u64, + *mut c::SYMBOL_INFO) -> c::BOOL; type SymGetLineFromAddr64Fn = - extern "system" fn(c::HANDLE, u64, *mut u32, - *mut c::IMAGEHLP_LINE64) -> c::BOOL; + unsafe extern "system" fn(c::HANDLE, u64, *mut u32, + *mut c::IMAGEHLP_LINE64) -> c::BOOL; -pub fn print(w: &mut Write, i: isize, addr: u64, dbghelp: &DynamicLibrary, - process: c::HANDLE) -> io::Result<()> { - let SymFromAddr = sym!(dbghelp, "SymFromAddr", SymFromAddrFn); - let SymGetLineFromAddr64 = sym!(dbghelp, "SymGetLineFromAddr64", SymGetLineFromAddr64Fn); +pub fn print(w: &mut Write, + i: isize, + addr: u64, + process: c::HANDLE, + dbghelp: &DynamicLibrary) + -> io::Result<()> { + unsafe { + let SymFromAddr = sym!(dbghelp, "SymFromAddr", SymFromAddrFn); + let SymGetLineFromAddr64 = sym!(dbghelp, + "SymGetLineFromAddr64", + SymGetLineFromAddr64Fn); - let mut info: c::SYMBOL_INFO = unsafe { mem::zeroed() }; - info.MaxNameLen = c::MAX_SYM_NAME as c_ulong; - // the struct size in C. the value is different to - // `size_of::<SYMBOL_INFO>() - MAX_SYM_NAME + 1` (== 81) - // due to struct alignment. - info.SizeOfStruct = 88; + let mut info: c::SYMBOL_INFO = mem::zeroed(); + info.MaxNameLen = c::MAX_SYM_NAME as c_ulong; + // the struct size in C. the value is different to + // `size_of::<SYMBOL_INFO>() - MAX_SYM_NAME + 1` (== 81) + // due to struct alignment. + info.SizeOfStruct = 88; - let mut displacement = 0u64; - let ret = SymFromAddr(process, addr, &mut displacement, &mut info); + let mut displacement = 0u64; + let ret = SymFromAddr(process, addr, &mut displacement, &mut info); - let name = if ret == c::TRUE { - let ptr = info.Name.as_ptr() as *const c_char; - Some(unsafe { CStr::from_ptr(ptr).to_bytes() }) - } else { - None - }; + let name = if ret == c::TRUE { + let ptr = info.Name.as_ptr() as *const c_char; + Some(CStr::from_ptr(ptr).to_bytes()) + } else { + None + }; - try!(output(w, i, addr as usize as *mut c_void, name)); + try!(output(w, i, addr as usize as *mut c_void, name)); - // Now find out the filename and line number - let mut line: c::IMAGEHLP_LINE64 = unsafe { mem::zeroed() }; - line.SizeOfStruct = ::mem::size_of::<c::IMAGEHLP_LINE64>() as u32; + // Now find out the filename and line number + let mut line: c::IMAGEHLP_LINE64 = mem::zeroed(); + line.SizeOfStruct = ::mem::size_of::<c::IMAGEHLP_LINE64>() as u32; - let mut displacement = 0u32; - let ret = SymGetLineFromAddr64(process, addr, &mut displacement, &mut line); - if ret == c::TRUE { - output_fileline(w, - unsafe { CStr::from_ptr(line.Filename).to_bytes() }, - line.LineNumber as c_int, - false) - } else { - Ok(()) + let mut displacement = 0u32; + let ret = SymGetLineFromAddr64(process, addr, &mut displacement, &mut line); + if ret == c::TRUE { + output_fileline(w, + CStr::from_ptr(line.Filename).to_bytes(), + line.LineNumber as c_int, + false) + } else { + Ok(()) + } } } diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index 6a923c8c094..2cf6c64eab8 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -339,40 +339,6 @@ pub fn panicking() -> bool { unwind::panicking() } -/// Invokes a closure, capturing the cause of panic if one occurs. -/// -/// This function will return `Ok` with the closure's result if the closure -/// does not panic, and will return `Err(cause)` if the closure panics. The -/// `cause` returned is the object with which panic was originally invoked. -/// -/// It is currently undefined behavior to unwind from Rust code into foreign -/// code, so this function is particularly useful when Rust is called from -/// another language (normally C). This can run arbitrary Rust code, capturing a -/// panic and allowing a graceful handling of the error. -/// -/// It is **not** recommended to use this function for a general try/catch -/// mechanism. The `Result` type is more appropriate to use for functions that -/// can fail on a regular basis. -/// -/// The closure provided is required to adhere to the `'static` bound to ensure -/// that it cannot reference data in the parent stack frame, mitigating problems -/// with exception safety. Furthermore, a `Send` bound is also required, -/// providing the same safety guarantees as `thread::spawn` (ensuring the -/// closure is properly isolated from the parent). -#[unstable(feature = "catch_panic", reason = "recent API addition", - issue = "27719")] -#[rustc_deprecated(since = "1.6.0", reason = "renamed to std::panic::recover")] -pub fn catch_panic<F, R>(f: F) -> Result<R> - where F: FnOnce() -> R + Send + 'static -{ - let mut result = None; - unsafe { - let result = &mut result; - try!(unwind::try(move || *result = Some(f()))) - } - Ok(result.unwrap()) -} - /// Puts the current thread to sleep for the specified amount of time. /// /// The thread may sleep longer than the duration specified due to scheduling diff --git a/src/libstd/time/duration.rs b/src/libstd/time/duration.rs index 7ecb3920cc8..7c3240b4a40 100644 --- a/src/libstd/time/duration.rs +++ b/src/libstd/time/duration.rs @@ -9,7 +9,6 @@ // except according to those terms. use ops::{Add, Sub, Mul, Div}; -use time::Instant; const NANOS_PER_SEC: u32 = 1_000_000_000; const NANOS_PER_MILLI: u32 = 1_000_000; @@ -59,21 +58,6 @@ impl Duration { Duration { secs: secs, nanos: nanos } } - /// Runs a closure, returning the duration of time it took to run the - /// closure. - #[unstable(feature = "duration_span", - reason = "unsure if this is the right API or whether it should \ - wait for a more general \"moment in time\" \ - abstraction", - issue = "27799")] - #[rustc_deprecated(reason = "use std::time::Instant instead", - since = "1.6.0")] - pub fn span<F>(f: F) -> Duration where F: FnOnce() { - let start = Instant::now(); - f(); - start.elapsed() - } - /// Creates a new `Duration` from the specified number of seconds. #[stable(feature = "duration", since = "1.3.0")] pub fn from_secs(secs: u64) -> Duration { |
