Skip to content

Commit 4b70749

Browse files
committed
objc-sys: Merge exception-macos-x86.rs into exception.rs
1 parent bf500bb commit 4b70749

File tree

5 files changed

+41
-42
lines changed

5 files changed

+41
-42
lines changed

objc-sys/build.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ fn main() {
6767
// println!("cargo:rustc-cfg=libobjc2_strict_apple_compat");
6868

6969
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
70+
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
7071

7172
let mut apple = env::var_os("CARGO_FEATURE_APPLE").is_some();
7273
let mut gnustep = env::var_os("CARGO_FEATURE_GNUSTEP_1_7").is_some();
@@ -138,12 +139,21 @@ fn main() {
138139
};
139140
println!("cargo:rustc-cfg={}", runtime_cfg);
140141

142+
if let Apple(runtime) = &runtime {
143+
// A few things are defined differently depending on the __OBJC2__
144+
// variable, which is set for all platforms except 32-bit macOS.
145+
if let (MacOS(_), "x86") = (runtime, &*target_arch) {
146+
println!("cargo:rustc-cfg=apple_old");
147+
} else {
148+
println!("cargo:rustc-cfg=apple_new");
149+
}
150+
}
151+
141152
let clang_runtime = match &runtime {
142153
Apple(runtime) => {
143154
// The fragile runtime is expected on i686-apple-darwin, see:
144155
// https://github.com/llvm/llvm-project/blob/release/13.x/clang/lib/Driver/ToolChains/Darwin.h#L228-L231
145156
// https://github.com/llvm/llvm-project/blob/release/13.x/clang/lib/Driver/ToolChains/Clang.cpp#L3639-L3640
146-
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
147157
let clang_runtime_str = match (runtime, &*target_arch) {
148158
(MacOS(_), "x86") => "macosx-fragile",
149159
(MacOS(_), _) => "macosx",

objc-sys/src/exception-macos-x86.rs

Lines changed: 0 additions & 18 deletions
This file was deleted.

objc-sys/src/exception.rs

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,27 @@
44
//! think it's fine...
55
#[cfg(any(not(objfw), feature = "unstable-exception"))]
66
use core::ffi::c_void;
7-
#[cfg(apple)]
7+
#[cfg(apple_new)]
88
use std::os::raw::c_int;
99
#[cfg(feature = "unstable-exception")]
1010
use std::os::raw::c_uchar;
1111

12-
#[cfg(apple)]
12+
#[cfg(apple_new)]
1313
use crate::objc_class;
1414
use crate::objc_object;
1515

1616
/// Remember that this is non-null!
17-
#[cfg(apple)]
17+
#[cfg(apple_new)]
1818
pub type objc_exception_matcher =
1919
unsafe extern "C" fn(catch_type: *mut objc_class, exception: *mut objc_object) -> c_int;
2020

2121
/// Remember that this is non-null!
22-
#[cfg(apple)]
22+
#[cfg(apple_new)]
2323
pub type objc_exception_preprocessor =
2424
unsafe extern "C" fn(exception: *mut objc_object) -> *mut objc_object;
2525

2626
/// Remember that this is non-null!
27-
#[cfg(apple)]
27+
#[cfg(apple_new)]
2828
pub type objc_uncaught_exception_handler = unsafe extern "C" fn(exception: *mut objc_object);
2929

3030
#[cfg(objfw)]
@@ -34,40 +34,52 @@ pub type objc_uncaught_exception_handler =
3434
/// Only available on macOS.
3535
///
3636
/// Remember that this is non-null!
37-
#[cfg(all(apple, target_os = "macos"))]
37+
#[cfg(all(apple_new, target_os = "macos"))]
3838
pub type objc_exception_handler =
3939
unsafe extern "C" fn(unused: *mut objc_object, context: *mut c_void);
4040

4141
extern_c! {
42-
#[cfg(not(objfw))]
42+
#[cfg(any(gnustep, apple_new))]
4343
pub fn objc_begin_catch(exc_buf: *mut c_void) -> *mut objc_object;
44-
#[cfg(not(objfw))]
44+
#[cfg(any(gnustep, apple_new))]
4545
pub fn objc_end_catch();
4646
/// See [`objc-exception.h`].
4747
///
4848
/// [`objc-exception.h`]: https://github.com/apple-oss-distributions/objc4/blob/objc4-818.2/runtime/objc-exception.h
4949
pub fn objc_exception_throw(exception: *mut objc_object) -> !;
50-
#[cfg(apple)]
50+
#[cfg(apple_new)]
5151
pub fn objc_exception_rethrow() -> !;
52+
53+
#[cfg(apple_old)]
54+
pub fn objc_exception_try_enter(exception_data: *const c_void);
55+
56+
#[cfg(apple_old)]
57+
pub fn objc_exception_try_exit(exception_data: *const c_void);
58+
59+
// objc_exception_extract
60+
// objc_exception_match
61+
// objc_exception_get_functions
62+
// objc_exception_set_functions
63+
5264
#[cfg(any(gnustep, winobjc))]
5365
pub fn objc_exception_rethrow(exc_buf: *mut c_void) -> !;
5466

55-
#[cfg(apple)]
67+
#[cfg(apple_new)]
5668
pub fn objc_setExceptionMatcher(f: objc_exception_matcher) -> objc_exception_matcher;
57-
#[cfg(apple)]
69+
#[cfg(apple_new)]
5870
pub fn objc_setExceptionPreprocessor(
5971
f: objc_exception_preprocessor,
6072
) -> objc_exception_preprocessor;
61-
#[cfg(any(apple, objfw))]
73+
#[cfg(any(apple_new, objfw))]
6274
pub fn objc_setUncaughtExceptionHandler(
6375
f: objc_uncaught_exception_handler,
6476
) -> objc_uncaught_exception_handler;
6577

6678
/// Only available on macOS.
67-
#[cfg(all(apple, target_os = "macos"))]
79+
#[cfg(all(apple_new, target_os = "macos"))]
6880
pub fn objc_addExceptionHandler(f: objc_exception_handler, context: *mut c_void) -> usize;
6981
/// Only available on macOS.
70-
#[cfg(all(apple, target_os = "macos"))]
82+
#[cfg(all(apple_new, target_os = "macos"))]
7183
pub fn objc_removeExceptionHandler(token: usize);
7284

7385
// Only available when ENABLE_OBJCXX is set, and a useable C++ runtime is

objc-sys/src/lib.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,7 @@ macro_rules! extern_c {
9393
mod class;
9494
mod constants;
9595

96-
#[cfg(not(all(apple, target_os = "macos", target_arch = "x86")))]
9796
mod exception;
98-
#[cfg(all(apple, target_os = "macos", target_arch = "x86"))]
99-
#[path = "exception-macos-x86.rs"]
100-
mod exception;
101-
10297
mod message;
10398
mod method;
10499
mod object;

objc-sys/src/various.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ pub type IMP = Option<unsafe extern "C" fn()>;
2424
// /// Not available on macOS x86.
2525
// ///
2626
// /// Remember that this is non-null!
27-
// #[cfg(all(apple, not(all(target_os = "macos", target_arch = "x86"))))]
27+
// #[cfg(apple_new)]
2828
// pub type objc_hook_getClass =
2929
// unsafe extern "C" fn(name: *const c_char, out_cls: *mut *const crate::objc_class) -> BOOL;
3030
//
3131
// /// Not available on macOS x86.
3232
// ///
3333
// /// Remember that this is non-null!
34-
// #[cfg(all(apple, not(all(target_os = "macos", target_arch = "x86"))))]
34+
// #[cfg(apple_new)]
3535
// pub type objc_hook_lazyClassNamer =
3636
// unsafe extern "C" fn(cls: *const crate::objc_class) -> *const c_char;
3737

@@ -94,7 +94,7 @@ extern_c! {
9494
// /// Not available on macOS x86.
9595
// ///
9696
// /// Remember that this is non-null!
97-
// #[cfg(all(apple, not(all(target_os = "macos", target_arch = "x86"))))]
97+
// #[cfg(apple_new)]
9898
// pub fn objc_setHook_getClass(
9999
// new_value: objc_hook_getClass,
100100
// out_old_value: *mut objc_hook_getClass,
@@ -103,7 +103,7 @@ extern_c! {
103103
// /// Not available on macOS x86.
104104
// ///
105105
// /// Remember that this is non-null!
106-
// #[cfg(all(apple, not(all(target_os = "macos", target_arch = "x86"))))]
106+
// #[cfg(apple_new)]
107107
// pub fn objc_setHook_lazyClassNamer(
108108
// new_value: objc_hook_lazyClassNamer,
109109
// out_old_value: *mut objc_hook_lazyClassNamer,

0 commit comments

Comments
 (0)