From c836ff46215b743c0f681d3e4d799cde1832cde3 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sun, 13 Apr 2014 14:39:04 -0700 Subject: std: Impl Deref/DerefMut for a borrowed task --- src/libstd/rt/local_heap.rs | 3 +-- src/libstd/rt/local_ptr.rs | 18 ++++++++++-------- src/libstd/rt/task.rs | 10 ++++------ 3 files changed, 15 insertions(+), 16 deletions(-) (limited to 'src/libstd/rt') diff --git a/src/libstd/rt/local_heap.rs b/src/libstd/rt/local_heap.rs index b9d0d829374..caf0d9028c5 100644 --- a/src/libstd/rt/local_heap.rs +++ b/src/libstd/rt/local_heap.rs @@ -319,8 +319,7 @@ pub unsafe fn local_free(ptr: *u8) { } pub fn live_allocs() -> *mut Box { - let mut task = Local::borrow(None::); - task.get().heap.live_allocs + Local::borrow(None::).heap.live_allocs } #[cfg(test)] diff --git a/src/libstd/rt/local_ptr.rs b/src/libstd/rt/local_ptr.rs index e3f64f40c0d..6b61af1d9a2 100644 --- a/src/libstd/rt/local_ptr.rs +++ b/src/libstd/rt/local_ptr.rs @@ -18,7 +18,7 @@ #![allow(dead_code)] use cast; -use ops::Drop; +use ops::{Drop, Deref, DerefMut}; use ptr::RawPtr; #[cfg(windows)] // mingw-w32 doesn't like thread_local things @@ -48,13 +48,15 @@ impl Drop for Borrowed { } } -impl Borrowed { - pub fn get<'a>(&'a mut self) -> &'a mut T { - unsafe { - let val_ptr: &mut ~T = cast::transmute(&mut self.val); - let val_ptr: &'a mut T = *val_ptr; - val_ptr - } +impl Deref for Borrowed { + fn deref<'a>(&'a self) -> &'a T { + unsafe { &*(self.val as *T) } + } +} + +impl DerefMut for Borrowed { + fn deref_mut<'a>(&'a mut self) -> &'a mut T { + unsafe { &mut *(self.val as *mut T) } } } diff --git a/src/libstd/rt/task.rs b/src/libstd/rt/task.rs index a112ed77f09..a3664b45a41 100644 --- a/src/libstd/rt/task.rs +++ b/src/libstd/rt/task.rs @@ -127,8 +127,8 @@ impl Task { #[allow(unused_must_use)] fn close_outputs() { let mut task = Local::borrow(None::); - let stderr = task.get().stderr.take(); - let stdout = task.get().stdout.take(); + let stderr = task.stderr.take(); + let stdout = task.stdout.take(); drop(task); match stdout { Some(mut w) => { w.flush(); }, None => {} } match stderr { Some(mut w) => { w.flush(); }, None => {} } @@ -159,8 +159,7 @@ impl Task { // be intertwined, and miraculously work for now... let mut task = Local::borrow(None::); let storage_map = { - let task = task.get(); - let LocalStorage(ref mut optmap) = task.storage; + let &LocalStorage(ref mut optmap) = &mut task.storage; optmap.take() }; drop(task); @@ -332,8 +331,7 @@ impl BlockedTask { } /// Converts one blocked task handle to a list of many handles to the same. - pub fn make_selectable(self, num_handles: uint) -> Take - { + pub fn make_selectable(self, num_handles: uint) -> Take { let arc = match self { Owned(task) => { let flag = unsafe { AtomicUint::new(cast::transmute(task)) }; -- cgit 1.4.1-3-g733a5 From c8f5b701dcf0b7dc4d78ef0d29f10e4f080b2517 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 15 Apr 2014 18:18:08 -0700 Subject: std: Remove pub use globs --- src/libstd/os.rs | 32 +++++++++++++++++++++----------- src/libstd/rt/local_ptr.rs | 6 ++++-- 2 files changed, 25 insertions(+), 13 deletions(-) (limited to 'src/libstd/rt') diff --git a/src/libstd/os.rs b/src/libstd/os.rs index a16113cb48f..25f503174bc 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -1294,37 +1294,47 @@ impl Drop for MemoryMap { /// Various useful system-specific constants. pub mod consts { #[cfg(unix)] - pub use os::consts::unix::*; + pub use os::consts::unix::FAMILY; #[cfg(windows)] - pub use os::consts::windows::*; + pub use os::consts::windows::FAMILY; #[cfg(target_os = "macos")] - pub use os::consts::macos::*; + pub use os::consts::macos::{SYSNAME, DLL_PREFIX, DLL_SUFFIX, DLL_EXTENSION}; + #[cfg(target_os = "macos")] + pub use os::consts::macos::{EXE_SUFFIX, EXE_EXTENSION}; #[cfg(target_os = "freebsd")] - pub use os::consts::freebsd::*; + pub use os::consts::freebsd::{SYSNAME, DLL_PREFIX, DLL_SUFFIX, DLL_EXTENSION}; + #[cfg(target_os = "freebsd")] + pub use os::consts::freebsd::{EXE_SUFFIX, EXE_EXTENSION}; #[cfg(target_os = "linux")] - pub use os::consts::linux::*; + pub use os::consts::linux::{SYSNAME, DLL_PREFIX, DLL_SUFFIX, DLL_EXTENSION}; + #[cfg(target_os = "linux")] + pub use os::consts::linux::{EXE_SUFFIX, EXE_EXTENSION}; #[cfg(target_os = "android")] - pub use os::consts::android::*; + pub use os::consts::android::{SYSNAME, DLL_PREFIX, DLL_SUFFIX, DLL_EXTENSION}; + #[cfg(target_os = "android")] + pub use os::consts::android::{EXE_SUFFIX, EXE_EXTENSION}; #[cfg(target_os = "win32")] - pub use os::consts::win32::*; + pub use os::consts::win32::{SYSNAME, DLL_PREFIX, DLL_SUFFIX, DLL_EXTENSION}; + #[cfg(target_os = "win32")] + pub use os::consts::win32::{EXE_SUFFIX, EXE_EXTENSION}; #[cfg(target_arch = "x86")] - pub use os::consts::x86::*; + pub use os::consts::x86::{ARCH}; #[cfg(target_arch = "x86_64")] - pub use os::consts::x86_64::*; + pub use os::consts::x86_64::{ARCH}; #[cfg(target_arch = "arm")] - pub use os::consts::arm::*; + pub use os::consts::arm::{ARCH}; #[cfg(target_arch = "mips")] - pub use os::consts::mips::*; + pub use os::consts::mips::{ARCH}; /// Constants for Unix systems. pub mod unix { diff --git a/src/libstd/rt/local_ptr.rs b/src/libstd/rt/local_ptr.rs index 6b61af1d9a2..ff82be97489 100644 --- a/src/libstd/rt/local_ptr.rs +++ b/src/libstd/rt/local_ptr.rs @@ -23,10 +23,12 @@ use ptr::RawPtr; #[cfg(windows)] // mingw-w32 doesn't like thread_local things #[cfg(target_os = "android")] // see #10686 -pub use self::native::*; +pub use self::native::{init, cleanup, put, take, try_take, unsafe_take, exists, + unsafe_borrow, try_unsafe_borrow}; #[cfg(not(windows), not(target_os = "android"))] -pub use self::compiled::*; +pub use self::compiled::{init, cleanup, put, take, try_take, unsafe_take, exists, + unsafe_borrow, try_unsafe_borrow}; /// Encapsulates a borrowed value. When this value goes out of scope, the /// pointer is returned. -- cgit 1.4.1-3-g733a5