@@ -32,73 +32,71 @@ thread_local! {
3232}
3333
3434#[ derive( Copy , Clone ) ]
35- enum Handler {
35+ enum Hook {
3636 Default ,
3737 Custom ( * mut ( Fn ( & PanicInfo ) + ' static + Sync + Send ) ) ,
3838}
3939
40- static HANDLER_LOCK : StaticRwLock = StaticRwLock :: new ( ) ;
41- static mut HANDLER : Handler = Handler :: Default ;
40+ static HOOK_LOCK : StaticRwLock = StaticRwLock :: new ( ) ;
41+ static mut HOOK : Hook = Hook :: Default ;
4242static FIRST_PANIC : AtomicBool = AtomicBool :: new ( true ) ;
4343
44- /// Registers a custom panic handler, replacing any that was previously
45- /// registered.
44+ /// Registers a custom panic hook, replacing any that was previously registered.
4645///
47- /// The panic handler is invoked when a thread panics, but before it begins
48- /// unwinding the stack. The default handler prints a message to standard error
46+ /// The panic hook is invoked when a thread panics, but before it begins
47+ /// unwinding the stack. The default hook prints a message to standard error
4948/// and generates a backtrace if requested, but this behavior can be customized
50- /// with the `set_handler ` and `take_handler ` functions.
49+ /// with the `set_hook ` and `take_hook ` functions.
5150///
52- /// The handler is provided with a `PanicInfo` struct which contains information
51+ /// The hook is provided with a `PanicInfo` struct which contains information
5352/// about the origin of the panic, including the payload passed to `panic!` and
5453/// the source code location from which the panic originated.
5554///
56- /// The panic handler is a global resource.
55+ /// The panic hook is a global resource.
5756///
5857/// # Panics
5958///
6059/// Panics if called from a panicking thread.
6160#[ unstable( feature = "panic_handler" , reason = "awaiting feedback" , issue = "30449" ) ]
62- pub fn set_handler < F > ( handler : F ) where F : Fn ( & PanicInfo ) + ' static + Sync + Send {
61+ pub fn set_hook ( hook : Box < Fn ( & PanicInfo ) + ' static + Sync + Send > ) {
6362 if thread:: panicking ( ) {
64- panic ! ( "cannot modify the panic handler from a panicking thread" ) ;
63+ panic ! ( "cannot modify the panic hook from a panicking thread" ) ;
6564 }
6665
67- let handler = Box :: new ( handler) ;
6866 unsafe {
69- let lock = HANDLER_LOCK . write ( ) ;
70- let old_handler = HANDLER ;
71- HANDLER = Handler :: Custom ( Box :: into_raw ( handler ) ) ;
67+ let lock = HOOK_LOCK . write ( ) ;
68+ let old_hook = HOOK ;
69+ HOOK = Hook :: Custom ( Box :: into_raw ( hook ) ) ;
7270 drop ( lock) ;
7371
74- if let Handler :: Custom ( ptr) = old_handler {
72+ if let Hook :: Custom ( ptr) = old_hook {
7573 Box :: from_raw ( ptr) ;
7674 }
7775 }
7876}
7977
80- /// Unregisters the current panic handler , returning it.
78+ /// Unregisters the current panic hook , returning it.
8179///
82- /// If no custom handler is registered, the default handler will be returned.
80+ /// If no custom hook is registered, the default hook will be returned.
8381///
8482/// # Panics
8583///
8684/// Panics if called from a panicking thread.
8785#[ unstable( feature = "panic_handler" , reason = "awaiting feedback" , issue = "30449" ) ]
88- pub fn take_handler ( ) -> Box < Fn ( & PanicInfo ) + ' static + Sync + Send > {
86+ pub fn take_hook ( ) -> Box < Fn ( & PanicInfo ) + ' static + Sync + Send > {
8987 if thread:: panicking ( ) {
90- panic ! ( "cannot modify the panic handler from a panicking thread" ) ;
88+ panic ! ( "cannot modify the panic hook from a panicking thread" ) ;
9189 }
9290
9391 unsafe {
94- let lock = HANDLER_LOCK . write ( ) ;
95- let handler = HANDLER ;
96- HANDLER = Handler :: Default ;
92+ let lock = HOOK_LOCK . write ( ) ;
93+ let hook = HOOK ;
94+ HOOK = Hook :: Default ;
9795 drop ( lock) ;
9896
99- match handler {
100- Handler :: Default => Box :: new ( default_handler ) ,
101- Handler :: Custom ( ptr) => { Box :: from_raw ( ptr) } // FIXME #30530
97+ match hook {
98+ Hook :: Default => Box :: new ( default_hook ) ,
99+ Hook :: Custom ( ptr) => { Box :: from_raw ( ptr) } // FIXME #30530
102100 }
103101 }
104102}
@@ -151,7 +149,7 @@ impl<'a> Location<'a> {
151149 }
152150}
153151
154- fn default_handler ( info : & PanicInfo ) {
152+ fn default_hook ( info : & PanicInfo ) {
155153 let panics = PANIC_COUNT . with ( |s| s. get ( ) ) ;
156154
157155 // If this is a double panic, make sure that we print a backtrace
@@ -224,10 +222,10 @@ pub fn on_panic(obj: &(Any+Send), file: &'static str, line: u32) {
224222 } ;
225223
226224 unsafe {
227- let _lock = HANDLER_LOCK . read ( ) ;
228- match HANDLER {
229- Handler :: Default => default_handler ( & info) ,
230- Handler :: Custom ( ptr) => ( * ptr) ( & info) ,
225+ let _lock = HOOK_LOCK . read ( ) ;
226+ match HOOK {
227+ Hook :: Default => default_hook ( & info) ,
228+ Hook :: Custom ( ptr) => ( * ptr) ( & info) ,
231229 }
232230 }
233231
0 commit comments