File tree 7 files changed +17
-46
lines changed
test/run-make-fulldeps/foreign-exceptions
7 files changed +17
-46
lines changed Original file line number Diff line number Diff line change @@ -80,6 +80,7 @@ pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
80
80
extern "C" fn exception_cleanup ( ptr : * mut libc:: c_void ) {
81
81
unsafe {
82
82
ptr:: drop_in_place ( ptr as * mut Exception ) ;
83
+ super :: __rust_drop_panic ( ) ;
83
84
}
84
85
}
85
86
}
Original file line number Diff line number Diff line change @@ -78,6 +78,7 @@ pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
78
78
) {
79
79
unsafe {
80
80
let _: Box < Exception > = Box :: from_raw ( exception as * mut Exception ) ;
81
+ super :: __rust_drop_panic ( ) ;
81
82
}
82
83
}
83
84
}
Original file line number Diff line number Diff line change @@ -61,6 +61,12 @@ cfg_if::cfg_if! {
61
61
}
62
62
}
63
63
64
+ extern "C" {
65
+ /// Handler in libstd called when a panic object is dropped outside of
66
+ /// `catch_unwind`.
67
+ fn __rust_drop_panic ( ) -> !;
68
+ }
69
+
64
70
mod dwarf;
65
71
66
72
// Entry point for catching an exception, implemented using the `try` intrinsic
Original file line number Diff line number Diff line change @@ -229,6 +229,7 @@ macro_rules! define_cleanup {
229
229
unsafe extern $abi fn exception_cleanup( e: * mut [ u64 ; 2 ] ) {
230
230
if ( * e) [ 0 ] != 0 {
231
231
cleanup( * e) ;
232
+ super :: __rust_drop_panic( ) ;
232
233
}
233
234
}
234
235
#[ unwind( allowed) ]
Original file line number Diff line number Diff line change @@ -55,6 +55,14 @@ extern "C" {
55
55
fn __rust_start_panic ( payload : usize ) -> u32 ;
56
56
}
57
57
58
+ /// This function is called by the panic runtime if FFI code catches a Rust
59
+ /// panic but doesn't rethrow it. We don't support this case since it messes
60
+ /// with our panic count.
61
+ #[ rustc_std_internal_symbol]
62
+ extern "C" fn __rust_drop_panic ( ) -> ! {
63
+ rtabort ! ( "Rust panics must be rethrown" ) ;
64
+ }
65
+
58
66
#[ derive( Copy , Clone ) ]
59
67
enum Hook {
60
68
Default ,
Original file line number Diff line number Diff line change @@ -57,21 +57,4 @@ extern "C" {
57
57
throw ;
58
58
}
59
59
}
60
-
61
- void swallow_exception (void (*cb)()) {
62
- try {
63
- // Do a rethrow to ensure that the exception is only dropped once.
64
- // This is necessary since we don't support copying exceptions.
65
- try {
66
- cb ();
67
- } catch (...) {
68
- println (" rethrowing Rust panic" );
69
- throw ;
70
- };
71
- } catch (rust_panic e) {
72
- assert (false && " shouldn't be able to catch a rust panic" );
73
- } catch (...) {
74
- println (" swallowing foreign exception in catch (...)" );
75
- }
76
- }
77
60
}
Original file line number Diff line number Diff line change @@ -19,8 +19,6 @@ impl<'a> Drop for DropCheck<'a> {
19
19
extern "C" {
20
20
fn throw_cxx_exception ( ) ;
21
21
22
- fn swallow_exception ( cb : extern "C" fn ( ) ) ;
23
-
24
22
#[ unwind( allowed) ]
25
23
fn cxx_catch_callback ( cb : extern "C" fn ( ) , ok : * mut bool ) ;
26
24
}
@@ -61,34 +59,7 @@ fn throw_rust_panic() {
61
59
assert ! ( cxx_ok) ;
62
60
}
63
61
64
- fn check_exception_drop ( ) {
65
- static mut DROP_COUNT : usize = 0 ;
66
-
67
- struct CountDrop ;
68
- impl Drop for CountDrop {
69
- fn drop ( & mut self ) {
70
- println ! ( "CountDrop::drop" ) ;
71
- unsafe {
72
- DROP_COUNT += 1 ;
73
- }
74
- }
75
- }
76
-
77
-
78
- #[ unwind( allowed) ]
79
- extern "C" fn callback ( ) {
80
- println ! ( "throwing rust panic #2" ) ;
81
- panic ! ( CountDrop ) ;
82
- }
83
-
84
- unsafe {
85
- swallow_exception ( callback) ;
86
- assert_eq ! ( DROP_COUNT , 1 ) ;
87
- }
88
- }
89
-
90
62
fn main ( ) {
91
63
unsafe { throw_cxx_exception ( ) } ;
92
64
throw_rust_panic ( ) ;
93
- check_exception_drop ( ) ;
94
65
}
You can’t perform that action at this time.
0 commit comments