File tree 2 files changed +46
-1
lines changed
src/test/run-make-fulldeps/foreign-exceptions
2 files changed +46
-1
lines changed Original file line number Diff line number Diff line change @@ -57,4 +57,21 @@ 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
+ }
60
77
}
Original file line number Diff line number Diff line change 4
4
5
5
// For linking libstdc++ on MinGW
6
6
#![ cfg_attr( all( windows, target_env = "gnu" ) , feature( static_nobundle) ) ]
7
-
8
7
#![ feature( unwind_attributes) ]
9
8
10
9
use std:: panic:: { catch_unwind, AssertUnwindSafe } ;
@@ -20,6 +19,8 @@ impl<'a> Drop for DropCheck<'a> {
20
19
extern "C" {
21
20
fn throw_cxx_exception ( ) ;
22
21
22
+ fn swallow_exception ( cb : extern "C" fn ( ) ) ;
23
+
23
24
#[ unwind( allowed) ]
24
25
fn cxx_catch_callback ( cb : extern "C" fn ( ) , ok : * mut bool ) ;
25
26
}
@@ -60,7 +61,34 @@ fn throw_rust_panic() {
60
61
assert ! ( cxx_ok) ;
61
62
}
62
63
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
+
63
90
fn main ( ) {
64
91
unsafe { throw_cxx_exception ( ) } ;
65
92
throw_rust_panic ( ) ;
93
+ check_exception_drop ( ) ;
66
94
}
You can’t perform that action at this time.
0 commit comments