Skip to content

Commit 255f94c

Browse files
committed
Add no_std support in objc_exception
1 parent d343048 commit 255f94c

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

objc_exception/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ edition = "2018"
66

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

objc_exception/extern/exception.m

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
// See https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retain
33
id objc_retain(id value);
44

5-
int RustObjCExceptionTryCatch(void (*try)(void *), void *context, id *error) {
5+
// We return `unsigned char`, since it is guaranteed to be an `u8` on all platforms
6+
unsigned char RustObjCExceptionTryCatch(void (*try)(void *), void *context, id *error) {
67
@try {
78
try(context);
89
if (error) {

objc_exception/src/lib.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
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
// TODO: "C-unwind"
@@ -20,7 +25,7 @@ extern "C" {
2025
r#try: extern "C" fn(*mut c_void),
2126
context: *mut c_void,
2227
error: *mut *mut c_void,
23-
) -> c_int;
28+
) -> u8; // std::os::raw::c_uchar
2429
}
2530

2631
/// An opaque type representing any Objective-C object thrown as an exception.
@@ -100,8 +105,10 @@ where
100105

101106
#[cfg(test)]
102107
mod tests {
108+
use alloc::string::ToString;
109+
use core::ptr;
110+
103111
use super::{r#try, throw};
104-
use std::ptr;
105112

106113
#[test]
107114
fn test_try() {

0 commit comments

Comments
 (0)