diff options
| author | bors <bors@rust-lang.org> | 2015-03-19 03:19:08 +0000 | 
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-03-19 03:19:08 +0000 | 
| commit | 0084f92302b3352372bfd14ebbf083bae695d16e (patch) | |
| tree | 7aeee112b2593dfc26968c2c3692371d9dc4a5ef /src/libstd/io | |
| parent | 12cb7c6a2847959460ecac75b2c983d071585472 (diff) | |
| parent | 6f930b99b0dbd548abb7bdd9eb9472d166f66811 (diff) | |
| download | rust-0084f92302b3352372bfd14ebbf083bae695d16e.tar.gz rust-0084f92302b3352372bfd14ebbf083bae695d16e.zip  | |
Auto merge of #23502 - Manishearth:rollup, r=Manishearth
Diffstat (limited to 'src/libstd/io')
| -rw-r--r-- | src/libstd/io/stdio.rs | 32 | 
1 files changed, 29 insertions, 3 deletions
diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index 75d047d5c9c..9b36408aa51 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -146,7 +146,7 @@ impl Stdin { /// accessing the underlying data. #[stable(feature = "rust1", since = "1.0.0")] pub fn lock(&self) -> StdinLock { - StdinLock { inner: self.inner.lock().unwrap() } + StdinLock { inner: self.inner.lock().unwrap_or_else(|e| e.into_inner()) } } /// Locks this handle and reads a line of input into the specified buffer. @@ -249,7 +249,7 @@ impl Stdout { /// returned guard also implements the `Write` trait for writing data. #[stable(feature = "rust1", since = "1.0.0")] pub fn lock(&self) -> StdoutLock { - StdoutLock { inner: self.inner.lock().unwrap() } + StdoutLock { inner: self.inner.lock().unwrap_or_else(|e| e.into_inner()) } } } @@ -319,7 +319,7 @@ impl Stderr { /// returned guard also implements the `Write` trait for writing data. #[stable(feature = "rust1", since = "1.0.0")] pub fn lock(&self) -> StderrLock { - StderrLock { inner: self.inner.lock().unwrap() } + StderrLock { inner: self.inner.lock().unwrap_or_else(|e| e.into_inner()) } } } @@ -402,3 +402,29 @@ pub fn _print(args: fmt::Arguments) { panic!("failed printing to stdout: {}", e); } } + +#[cfg(test)] +mod test { + use thread; + use super::*; + + #[test] + fn panic_doesnt_poison() { + thread::spawn(|| { + let _a = stdin(); + let _a = _a.lock(); + let _a = stdout(); + let _a = _a.lock(); + let _a = stderr(); + let _a = _a.lock(); + panic!(); + }).join().unwrap_err(); + + let _a = stdin(); + let _a = _a.lock(); + let _a = stdout(); + let _a = _a.lock(); + let _a = stderr(); + let _a = _a.lock(); + } +}  | 
