@@ -32,73 +32,71 @@ thread_local! {
32
32
}
33
33
34
34
#[ derive( Copy , Clone ) ]
35
- enum Handler {
35
+ enum Hook {
36
36
Default ,
37
37
Custom ( * mut ( Fn ( & PanicInfo ) + ' static + Sync + Send ) ) ,
38
38
}
39
39
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 ;
42
42
static FIRST_PANIC : AtomicBool = AtomicBool :: new ( true ) ;
43
43
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.
46
45
///
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
49
48
/// 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.
51
50
///
52
- /// The handler is provided with a `PanicInfo` struct which contains information
51
+ /// The hook is provided with a `PanicInfo` struct which contains information
53
52
/// about the origin of the panic, including the payload passed to `panic!` and
54
53
/// the source code location from which the panic originated.
55
54
///
56
- /// The panic handler is a global resource.
55
+ /// The panic hook is a global resource.
57
56
///
58
57
/// # Panics
59
58
///
60
59
/// Panics if called from a panicking thread.
61
60
#[ 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 > ) {
63
62
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" ) ;
65
64
}
66
65
67
- let handler = Box :: new ( handler) ;
68
66
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 ) ) ;
72
70
drop ( lock) ;
73
71
74
- if let Handler :: Custom ( ptr) = old_handler {
72
+ if let Hook :: Custom ( ptr) = old_hook {
75
73
Box :: from_raw ( ptr) ;
76
74
}
77
75
}
78
76
}
79
77
80
- /// Unregisters the current panic handler , returning it.
78
+ /// Unregisters the current panic hook , returning it.
81
79
///
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.
83
81
///
84
82
/// # Panics
85
83
///
86
84
/// Panics if called from a panicking thread.
87
85
#[ 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 > {
89
87
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" ) ;
91
89
}
92
90
93
91
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 ;
97
95
drop ( lock) ;
98
96
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
102
100
}
103
101
}
104
102
}
@@ -151,7 +149,7 @@ impl<'a> Location<'a> {
151
149
}
152
150
}
153
151
154
- fn default_handler ( info : & PanicInfo ) {
152
+ fn default_hook ( info : & PanicInfo ) {
155
153
let panics = PANIC_COUNT . with ( |s| s. get ( ) ) ;
156
154
157
155
// 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) {
224
222
} ;
225
223
226
224
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) ,
231
229
}
232
230
}
233
231
0 commit comments