@@ -25,11 +25,19 @@ use crate::rc::{Id, Shared};
25
25
use crate :: runtime:: Object ;
26
26
27
27
extern "C" {
28
+ #[ cfg( not( feature = "unstable_c_unwind" ) ) ]
28
29
fn rust_objc_try_catch_exception (
29
30
f : extern "C" fn ( * mut c_void ) ,
30
31
context : * mut c_void ,
31
32
error : * mut * mut ffi:: objc_object ,
32
33
) -> c_uchar ;
34
+
35
+ #[ cfg( feature = "unstable_c_unwind" ) ]
36
+ fn rust_objc_try_catch_exception (
37
+ f : extern "C-unwind" fn ( * mut c_void ) ,
38
+ context : * mut c_void ,
39
+ error : * mut * mut objc_object ,
40
+ ) -> c_uchar ;
33
41
}
34
42
35
43
/// Throws an Objective-C exception.
@@ -57,14 +65,38 @@ pub unsafe fn throw(exception: Option<&Id<Object, Shared>>) -> ! {
57
65
}
58
66
59
67
unsafe fn try_no_ret < F : FnOnce ( ) > ( closure : F ) -> Result < ( ) , Option < Id < Object , Shared > > > {
60
- extern "C" fn try_objc_execute_closure < F : FnOnce ( ) > ( closure : & mut Option < F > ) {
61
- // This is always passed Some, so it's safe to unwrap
62
- let closure = closure. take ( ) . unwrap ( ) ;
63
- closure ( ) ;
64
- }
68
+ #[ cfg( not( feature = "unstable_c_unwind" ) ) ]
69
+ let f = {
70
+ extern "C" fn try_objc_execute_closure < F > ( closure : & mut Option < F > )
71
+ where
72
+ F : FnOnce ( ) ,
73
+ {
74
+ // This is always passed Some, so it's safe to unwrap
75
+ let closure = closure. take ( ) . unwrap ( ) ;
76
+ closure ( ) ;
77
+ }
78
+
79
+ let f: extern "C" fn ( & mut Option < F > ) = try_objc_execute_closure;
80
+ let f: extern "C" fn ( * mut c_void ) = unsafe { mem:: transmute ( f) } ;
81
+ f
82
+ } ;
83
+
84
+ #[ cfg( feature = "unstable_c_unwind" ) ]
85
+ let f = {
86
+ extern "C-unwind" fn try_objc_execute_closure < F > ( closure : & mut Option < F > )
87
+ where
88
+ F : FnOnce ( ) ,
89
+ {
90
+ // This is always passed Some, so it's safe to unwrap
91
+ let closure = closure. take ( ) . unwrap ( ) ;
92
+ closure ( ) ;
93
+ }
94
+
95
+ let f: extern "C-unwind" fn ( & mut Option < F > ) = try_objc_execute_closure;
96
+ let f: extern "C-unwind" fn ( * mut c_void ) = unsafe { mem:: transmute ( f) } ;
97
+ f
98
+ } ;
65
99
66
- let f: extern "C" fn ( & mut Option < F > ) = try_objc_execute_closure;
67
- let f: extern "C" fn ( * mut c_void ) = unsafe { mem:: transmute ( f) } ;
68
100
// Wrap the closure in an Option so it can be taken
69
101
let mut closure = Some ( closure) ;
70
102
let context = & mut closure as * mut _ as * mut c_void ;
0 commit comments