diff options
| author | bors <bors@rust-lang.org> | 2016-03-26 01:13:31 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2016-03-26 01:13:31 -0700 |
| commit | d322f990b04e3b598afd6a47c09a0277f73031aa (patch) | |
| tree | aa4db313962bedd35e235ad3913408133d0e0848 /src/libstd | |
| parent | 8d2d2be6c61c17da8027a72da91f87a0e2487f74 (diff) | |
| parent | 6c10866b0241b6f37f1f5e30eaed3ac316b63ea4 (diff) | |
Auto merge of #32496 - Manishearth:rollup, r=Manishearth
Rollup of 11 pull requests - Successful merges: #32131, #32199, #32257, #32325, #32435, #32447, #32448, #32456, #32469, #32476, #32482 - Failed merges: #32240
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/num/f32.rs | 7 | ||||
| -rw-r--r-- | src/libstd/num/f64.rs | 7 | ||||
| -rw-r--r-- | src/libstd/process.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/unix/thread.rs | 27 | ||||
| -rw-r--r-- | src/libstd/sys/windows/thread.rs | 3 | ||||
| -rw-r--r-- | src/libstd/thread/mod.rs | 21 | ||||
| -rw-r--r-- | src/libstd/time/duration.rs | 30 | ||||
| -rw-r--r-- | src/libstd/time/mod.rs | 30 |
8 files changed, 98 insertions, 29 deletions
diff --git a/src/libstd/num/f32.rs b/src/libstd/num/f32.rs index e78d46b22e9..6fc26bb7eed 100644 --- a/src/libstd/num/f32.rs +++ b/src/libstd/num/f32.rs @@ -1152,9 +1152,10 @@ impl f32 { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn asinh(self) -> f32 { - match self { - NEG_INFINITY => NEG_INFINITY, - x => (x + ((x * x) + 1.0).sqrt()).ln(), + if self == NEG_INFINITY { + NEG_INFINITY + } else { + (self + ((self * self) + 1.0).sqrt()).ln() } } diff --git a/src/libstd/num/f64.rs b/src/libstd/num/f64.rs index cea5a9edd68..93e5969a275 100644 --- a/src/libstd/num/f64.rs +++ b/src/libstd/num/f64.rs @@ -1023,9 +1023,10 @@ impl f64 { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn asinh(self) -> f64 { - match self { - NEG_INFINITY => NEG_INFINITY, - x => (x + ((x * x) + 1.0).sqrt()).ln(), + if self == NEG_INFINITY { + NEG_INFINITY + } else { + (self + ((self * self) + 1.0).sqrt()).ln() } } diff --git a/src/libstd/process.rs b/src/libstd/process.rs index e86026758aa..c1ef60852a7 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -339,7 +339,7 @@ impl Command { /// ``` #[stable(feature = "process", since = "1.0.0")] pub fn status(&mut self) -> io::Result<ExitStatus> { - self.inner.spawn(imp::Stdio::Inherit, false).map(Child::from_inner) + self.inner.spawn(imp::Stdio::Inherit, true).map(Child::from_inner) .and_then(|mut p| p.wait()) } } diff --git a/src/libstd/sys/unix/thread.rs b/src/libstd/sys/unix/thread.rs index 793a2ecae89..6d966a0f694 100644 --- a/src/libstd/sys/unix/thread.rs +++ b/src/libstd/sys/unix/thread.rs @@ -13,7 +13,7 @@ use prelude::v1::*; use alloc::boxed::FnBox; use cmp; #[cfg(not(any(target_env = "newlib", target_os = "solaris")))] -use ffi::CString; +use ffi::CStr; use io; use libc; use mem; @@ -84,15 +84,12 @@ impl Thread { #[cfg(any(target_os = "linux", target_os = "android", target_os = "emscripten"))] - pub fn set_name(name: &str) { + pub fn set_name(name: &CStr) { const PR_SET_NAME: libc::c_int = 15; - let cname = CString::new(name).unwrap_or_else(|_| { - panic!("thread name may not contain interior null bytes") - }); // pthread wrapper only appeared in glibc 2.12, so we use syscall // directly. unsafe { - libc::prctl(PR_SET_NAME, cname.as_ptr() as libc::c_ulong, 0, 0, 0); + libc::prctl(PR_SET_NAME, name.as_ptr() as libc::c_ulong, 0, 0, 0); } } @@ -100,32 +97,30 @@ impl Thread { target_os = "dragonfly", target_os = "bitrig", target_os = "openbsd"))] - pub fn set_name(name: &str) { - let cname = CString::new(name).unwrap(); + pub fn set_name(name: &CStr) { unsafe { - libc::pthread_set_name_np(libc::pthread_self(), cname.as_ptr()); + libc::pthread_set_name_np(libc::pthread_self(), name.as_ptr()); } } #[cfg(any(target_os = "macos", target_os = "ios"))] - pub fn set_name(name: &str) { - let cname = CString::new(name).unwrap(); + pub fn set_name(name: &CStr) { unsafe { - libc::pthread_setname_np(cname.as_ptr()); + libc::pthread_setname_np(name.as_ptr()); } } #[cfg(target_os = "netbsd")] - pub fn set_name(name: &str) { + pub fn set_name(name: &CStr) { + use ffi::CString; let cname = CString::new(&b"%s"[..]).unwrap(); - let carg = CString::new(name).unwrap(); unsafe { libc::pthread_setname_np(libc::pthread_self(), cname.as_ptr(), - carg.as_ptr() as *mut libc::c_void); + name.as_ptr() as *mut libc::c_void); } } #[cfg(any(target_env = "newlib", target_os = "solaris"))] - pub fn set_name(_name: &str) { + pub fn set_name(_name: &CStr) { // Newlib and Illumos has no way to set a thread name. } diff --git a/src/libstd/sys/windows/thread.rs b/src/libstd/sys/windows/thread.rs index b18772c0c24..0383e92c79e 100644 --- a/src/libstd/sys/windows/thread.rs +++ b/src/libstd/sys/windows/thread.rs @@ -12,6 +12,7 @@ use prelude::v1::*; use alloc::boxed::FnBox; use io; +use ffi::CStr; use mem; use libc::c_void; use ptr; @@ -54,7 +55,7 @@ impl Thread { } } - pub fn set_name(_name: &str) { + pub fn set_name(_name: &CStr) { // Windows threads are nameless // The names in MSVC debugger are obtained using a "magic" exception, // which requires a use of MS C++ extensions. diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index f3139aaf98d..b3549dc1264 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -166,6 +166,8 @@ use any::Any; use cell::UnsafeCell; use fmt; use io; +use str; +use ffi::{CStr, CString}; use sync::{Mutex, Condvar, Arc}; use sys::thread as imp; use sys_common::thread_info; @@ -267,7 +269,7 @@ impl Builder { let their_packet = my_packet.clone(); let main = move || { - if let Some(name) = their_thread.name() { + if let Some(name) = their_thread.cname() { imp::Thread::set_name(name); } unsafe { @@ -450,7 +452,7 @@ pub fn park_timeout(dur: Duration) { /// The internal representation of a `Thread` handle struct Inner { - name: Option<String>, + name: Option<CString>, // Guaranteed to be UTF-8 lock: Mutex<bool>, // true when there is a buffered unpark cvar: Condvar, } @@ -465,9 +467,12 @@ pub struct Thread { impl Thread { // Used only internally to construct a thread object without spawning fn new(name: Option<String>) -> Thread { + let cname = name.map(|n| CString::new(n).unwrap_or_else(|_| { + panic!("thread name may not contain interior null bytes") + })); Thread { inner: Arc::new(Inner { - name: name, + name: cname, lock: Mutex::new(false), cvar: Condvar::new(), }) @@ -489,6 +494,10 @@ impl Thread { /// Gets the thread's name. #[stable(feature = "rust1", since = "1.0.0")] pub fn name(&self) -> Option<&str> { + self.cname().map(|s| unsafe { str::from_utf8_unchecked(s.to_bytes()) } ) + } + + fn cname(&self) -> Option<&CStr> { self.inner.name.as_ref().map(|s| &**s) } } @@ -623,6 +632,12 @@ mod tests { } #[test] + #[should_panic] + fn test_invalid_named_thread() { + let _ = Builder::new().name("ada l\0velace".to_string()).spawn(|| {}); + } + + #[test] fn test_run_basic() { let (tx, rx) = channel(); thread::spawn(move|| { diff --git a/src/libstd/time/duration.rs b/src/libstd/time/duration.rs index 7c3240b4a40..945eb6a42e5 100644 --- a/src/libstd/time/duration.rs +++ b/src/libstd/time/duration.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ops::{Add, Sub, Mul, Div}; +use ops::{Add, Sub, Mul, Div, AddAssign, SubAssign, MulAssign, DivAssign}; const NANOS_PER_SEC: u32 = 1_000_000_000; const NANOS_PER_MILLI: u32 = 1_000_000; @@ -105,6 +105,13 @@ impl Add for Duration { } } +#[stable(feature = "time_augmented_assignment", since = "1.9.0")] +impl AddAssign for Duration { + fn add_assign(&mut self, rhs: Duration) { + *self = *self + rhs; + } +} + #[stable(feature = "duration", since = "1.3.0")] impl Sub for Duration { type Output = Duration; @@ -124,6 +131,13 @@ impl Sub for Duration { } } +#[stable(feature = "time_augmented_assignment", since = "1.9.0")] +impl SubAssign for Duration { + fn sub_assign(&mut self, rhs: Duration) { + *self = *self - rhs; + } +} + #[stable(feature = "duration", since = "1.3.0")] impl Mul<u32> for Duration { type Output = Duration; @@ -141,6 +155,13 @@ impl Mul<u32> for Duration { } } +#[stable(feature = "time_augmented_assignment", since = "1.9.0")] +impl MulAssign<u32> for Duration { + fn mul_assign(&mut self, rhs: u32) { + *self = *self * rhs; + } +} + #[stable(feature = "duration", since = "1.3.0")] impl Div<u32> for Duration { type Output = Duration; @@ -155,6 +176,13 @@ impl Div<u32> for Duration { } } +#[stable(feature = "time_augmented_assignment", since = "1.9.0")] +impl DivAssign<u32> for Duration { + fn div_assign(&mut self, rhs: u32) { + *self = *self / rhs; + } +} + #[cfg(test)] mod tests { use super::Duration; diff --git a/src/libstd/time/mod.rs b/src/libstd/time/mod.rs index 0c32feebecb..bc50b0d3a70 100644 --- a/src/libstd/time/mod.rs +++ b/src/libstd/time/mod.rs @@ -24,7 +24,7 @@ use error::Error; use fmt; -use ops::{Add, Sub}; +use ops::{Add, Sub, AddAssign, SubAssign}; use sys::time; use sys_common::FromInner; @@ -172,6 +172,13 @@ impl Add<Duration> for Instant { } } +#[stable(feature = "time_augmented_assignment", since = "1.9.0")] +impl AddAssign<Duration> for Instant { + fn add_assign(&mut self, other: Duration) { + *self = *self + other; + } +} + #[stable(feature = "time2", since = "1.8.0")] impl Sub<Duration> for Instant { type Output = Instant; @@ -181,6 +188,13 @@ impl Sub<Duration> for Instant { } } +#[stable(feature = "time_augmented_assignment", since = "1.9.0")] +impl SubAssign<Duration> for Instant { + fn sub_assign(&mut self, other: Duration) { + *self = *self - other; + } +} + #[stable(feature = "time2", since = "1.8.0")] impl Sub<Instant> for Instant { type Output = Duration; @@ -254,6 +268,13 @@ impl Add<Duration> for SystemTime { } } +#[stable(feature = "time_augmented_assignment", since = "1.9.0")] +impl AddAssign<Duration> for SystemTime { + fn add_assign(&mut self, other: Duration) { + *self = *self + other; + } +} + #[stable(feature = "time2", since = "1.8.0")] impl Sub<Duration> for SystemTime { type Output = SystemTime; @@ -263,6 +284,13 @@ impl Sub<Duration> for SystemTime { } } +#[stable(feature = "time_augmented_assignment", since = "1.9.0")] +impl SubAssign<Duration> for SystemTime { + fn sub_assign(&mut self, other: Duration) { + *self = *self - other; + } +} + #[stable(feature = "time2", since = "1.8.0")] impl fmt::Debug for SystemTime { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
