From 2b02714c41e89706ae469a95b64bf17ff1db79b7 Mon Sep 17 00:00:00 2001 From: Steven Sheldon Date: Thu, 12 Nov 2015 00:01:32 -0800 Subject: [PATCH] Replaced c_void in the public API with an opaque Exception type. --- src/lib.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index e851eb2..6f8e491 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,16 +13,19 @@ extern { context: *mut c_void, error: *mut *mut c_void) -> c_int; } +/// An opaque type representing any Objective-C object thrown as an exception. +pub enum Exception { } + /// Throws an Objective-C exception. /// The argument must be a pointer to an Objective-C object. /// /// Unsafe because this unwinds from Objective-C. -pub unsafe fn throw(exception: *mut c_void) -> ! { - RustObjCExceptionThrow(exception); +pub unsafe fn throw(exception: *mut Exception) -> ! { + RustObjCExceptionThrow(exception as *mut _); unreachable!(); } -unsafe fn try_no_ret(closure: F) -> Result<(), *mut c_void> +unsafe fn try_no_ret(closure: F) -> Result<(), *mut Exception> where F: FnOnce() { extern fn try_objc_execute_closure(closure: &mut Option) where F: FnOnce() { @@ -42,7 +45,7 @@ unsafe fn try_no_ret(closure: F) -> Result<(), *mut c_void> if success == 0 { Ok(()) } else { - Err(exception) + Err(exception as *mut _) } } @@ -55,7 +58,7 @@ unsafe fn try_no_ret(closure: F) -> Result<(), *mut c_void> /// /// Unsafe because this encourages unwinding through the closure from /// Objective-C, which is not safe. -pub unsafe fn try(closure: F) -> Result +pub unsafe fn try(closure: F) -> Result where F: FnOnce() -> R { let mut value = None; let result = {