diff options
| author | Andrea Canciani <ranma42@gmail.com> | 2015-09-24 23:49:38 +0200 |
|---|---|---|
| committer | Andrea Canciani <ranma42@gmail.com> | 2015-09-24 23:49:38 +0200 |
| commit | c7b84909b00dcf5f762778b4aa9783770c69416d (patch) | |
| tree | 0a437b3fff3d718e04267f2523266fcf039d1432 /src/libstd/sys/common | |
| parent | 44d1b149d2831192503a7797b98f108a3b5b1032 (diff) | |
| download | rust-c7b84909b00dcf5f762778b4aa9783770c69416d.tar.gz rust-c7b84909b00dcf5f762778b4aa9783770c69416d.zip | |
Explicitly count the number of panics
Move the panic handling logic from the `unwind` module to `panicking` and use a panic counter to distinguish between normal state, panics and double panics.
Diffstat (limited to 'src/libstd/sys/common')
| -rw-r--r-- | src/libstd/sys/common/unwind/mod.rs | 22 |
1 files changed, 4 insertions, 18 deletions
diff --git a/src/libstd/sys/common/unwind/mod.rs b/src/libstd/sys/common/unwind/mod.rs index 8148bb6b7b8..c06d7886a75 100644 --- a/src/libstd/sys/common/unwind/mod.rs +++ b/src/libstd/sys/common/unwind/mod.rs @@ -64,9 +64,8 @@ use prelude::v1::*; use any::Any; use boxed; -use cell::Cell; use cmp; -use panicking; +use panicking::{self,PANIC_COUNT}; use fmt; use intrinsics; use mem; @@ -92,8 +91,6 @@ pub mod imp; #[path = "gcc.rs"] #[doc(hidden)] pub mod imp; -thread_local! { static PANICKING: Cell<bool> = Cell::new(false) } - /// Invoke a closure, capturing the cause of panic if one occurs. /// /// This function will return `Ok(())` if the closure did not panic, and will @@ -131,9 +128,9 @@ pub unsafe fn try<F: FnOnce()>(f: F) -> Result<(), Box<Any + Send>> { // care of exposing correctly. unsafe fn inner_try(f: fn(*mut u8), data: *mut u8) -> Result<(), Box<Any + Send>> { - PANICKING.with(|s| { + PANIC_COUNT.with(|s| { let prev = s.get(); - s.set(false); + s.set(0); let ep = intrinsics::try(f, data); s.set(prev); if ep.is_null() { @@ -161,7 +158,7 @@ pub unsafe fn try<F: FnOnce()>(f: F) -> Result<(), Box<Any + Send>> { /// Determines whether the current thread is unwinding because of panic. pub fn panicking() -> bool { - PANICKING.with(|s| s.get()) + PANIC_COUNT.with(|s| s.get() != 0) } // An uninlined, unmangled function upon which to slap yer breakpoints @@ -234,17 +231,6 @@ fn begin_unwind_inner(msg: Box<Any + Send>, // First, invoke the default panic handler. panicking::on_panic(&*msg, file, line); - if panicking() { - // If a thread panics while it's already unwinding then we - // have limited options. Currently our preference is to - // just abort. In the future we may consider resuming - // unwinding or otherwise exiting the thread cleanly. - super::util::dumb_print(format_args!("thread panicked while panicking. \ - aborting.")); - unsafe { intrinsics::abort() } - } - PANICKING.with(|s| s.set(true)); - // Finally, perform the unwinding. rust_panic(msg); } |
