Skip to content

Commit 2b02714

Browse files
committed
Replaced c_void in the public API with an opaque Exception type.
1 parent 810459b commit 2b02714

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/lib.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,19 @@ extern {
1313
context: *mut c_void, error: *mut *mut c_void) -> c_int;
1414
}
1515

16+
/// An opaque type representing any Objective-C object thrown as an exception.
17+
pub enum Exception { }
18+
1619
/// Throws an Objective-C exception.
1720
/// The argument must be a pointer to an Objective-C object.
1821
///
1922
/// Unsafe because this unwinds from Objective-C.
20-
pub unsafe fn throw(exception: *mut c_void) -> ! {
21-
RustObjCExceptionThrow(exception);
23+
pub unsafe fn throw(exception: *mut Exception) -> ! {
24+
RustObjCExceptionThrow(exception as *mut _);
2225
unreachable!();
2326
}
2427

25-
unsafe fn try_no_ret<F>(closure: F) -> Result<(), *mut c_void>
28+
unsafe fn try_no_ret<F>(closure: F) -> Result<(), *mut Exception>
2629
where F: FnOnce() {
2730
extern fn try_objc_execute_closure<F>(closure: &mut Option<F>)
2831
where F: FnOnce() {
@@ -42,7 +45,7 @@ unsafe fn try_no_ret<F>(closure: F) -> Result<(), *mut c_void>
4245
if success == 0 {
4346
Ok(())
4447
} else {
45-
Err(exception)
48+
Err(exception as *mut _)
4649
}
4750
}
4851

@@ -55,7 +58,7 @@ unsafe fn try_no_ret<F>(closure: F) -> Result<(), *mut c_void>
5558
///
5659
/// Unsafe because this encourages unwinding through the closure from
5760
/// Objective-C, which is not safe.
58-
pub unsafe fn try<F, R>(closure: F) -> Result<R, *mut c_void>
61+
pub unsafe fn try<F, R>(closure: F) -> Result<R, *mut Exception>
5962
where F: FnOnce() -> R {
6063
let mut value = None;
6164
let result = {

0 commit comments

Comments
 (0)