Skip to content

Commit 458ed98

Browse files
committed
Add no_std support
1 parent c86ad3a commit 458ed98

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ authors = ["Steven Sheldon"]
55

66
description = "Rust interface for Objective-C's throw and try/catch statements."
77
keywords = ["objective-c", "osx", "ios"]
8+
categories = ["development-tools::ffi", "no-std"]
89
repository = "http://github.com/SSheldon/rust-objc-exception"
910
documentation = "http://ssheldon.github.io/rust-objc/objc_exception/"
1011
license = "MIT"

extern/exception.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ void RustObjCExceptionThrow(id exception) {
55
@throw exception;
66
}
77

8-
int RustObjCExceptionTryCatch(void (*try)(void *), void *context, id *error) {
8+
// We return `unsigned char`, since it is guaranteed to be an `u8` on all platforms
9+
unsigned char RustObjCExceptionTryCatch(void (*try)(void *), void *context, id *error) {
910
@try {
1011
try(context);
1112
if (error) {

src/lib.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
//! Rust interface for Objective-C's `@throw` and `@try`/`@catch` statements.
22
3-
use std::mem;
4-
use std::os::raw::{c_int, c_void};
5-
use std::ptr;
3+
#![no_std]
4+
5+
#[cfg(test)]
6+
extern crate alloc;
7+
8+
use core::ffi::c_void;
9+
use core::mem;
10+
use core::ptr;
611

712
#[link(name = "objc", kind = "dylib")]
813
extern { }
914

1015
extern {
1116
fn RustObjCExceptionThrow(exception: *mut c_void);
1217
fn RustObjCExceptionTryCatch(try: extern fn(*mut c_void),
13-
context: *mut c_void, error: *mut *mut c_void) -> c_int;
18+
context: *mut c_void, error: *mut *mut c_void) -> u8; // std::os::raw::c_uchar
1419
}
1520

1621
/// An opaque type representing any Objective-C object thrown as an exception.
@@ -74,7 +79,9 @@ pub unsafe fn try<F, R>(closure: F) -> Result<R, *mut Exception>
7479

7580
#[cfg(test)]
7681
mod tests {
77-
use std::ptr;
82+
use alloc::string::ToString;
83+
use core::ptr;
84+
7885
use super::{throw, try};
7986

8087
#[test]

0 commit comments

Comments
 (0)