Skip to content

Commit 8525bfc

Browse files
committed
Add new runtime functions
1 parent 90ecad0 commit 8525bfc

File tree

5 files changed

+43
-10
lines changed

5 files changed

+43
-10
lines changed

crates/objc-sys/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66

77
## Unreleased - YYYY-MM-DD
88

9+
### Added
10+
* Added `objc_terminate`, `object_isClass`, `objc_alloc` and
11+
`objc_allocWithZone` now that Rust's macOS deployment target is 10.12.
12+
913

1014
## 0.3.1 - 2023-06-20
1115

crates/objc-sys/src/exception.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,15 @@ extern_c_unwind! {
4444
/// See [`objc-exception.h`].
4545
///
4646
/// [`objc-exception.h`]: https://github.com/apple-oss-distributions/objc4/blob/objc4-818.2/runtime/objc-exception.h
47+
#[cold]
4748
pub fn objc_exception_throw(exception: *mut objc_object) -> !;
4849

4950
#[cfg(apple_new)]
51+
#[cold]
5052
pub fn objc_exception_rethrow() -> !;
5153

5254
#[cfg(gnustep)]
55+
#[cold]
5356
pub fn objc_exception_rethrow(exc_buf: *mut c_void) -> !;
5457
}
5558

@@ -91,6 +94,10 @@ extern_c! {
9194
//
9295
// #[cfg(any(doc, gnustep))]
9396
// pub fn objc_set_apple_compatible_objcxx_exceptions(newValue: c_int) -> c_int;
97+
98+
#[cold]
99+
#[cfg(any(doc, apple_new))]
100+
pub fn objc_terminate() -> !;
94101
}
95102

96103
extern "C" {

crates/objc-sys/src/object.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use std::os::raw::c_char;
44

55
#[cfg(any(doc, not(objfw)))]
66
use crate::objc_ivar;
7+
#[cfg(any(doc, apple))]
8+
use crate::BOOL;
79
use crate::{objc_class, OpaqueData};
810

911
/// An opaque type that represents an object / an instance of a class.
@@ -23,6 +25,8 @@ extern_c! {
2325
pub fn object_getClass(obj: *const objc_object) -> *const objc_class;
2426
pub fn object_getClassName(obj: *const objc_object) -> *const c_char;
2527
pub fn object_setClass(obj: *mut objc_object, cls: *const objc_class) -> *const objc_class;
28+
#[cfg(any(doc, apple))]
29+
pub fn object_isClass(obj: *const objc_object) -> BOOL;
2630

2731
#[cfg(any(doc, not(objfw)))]
2832
pub fn object_getIndexedIvars(obj: *const objc_object) -> *const c_void;
@@ -90,6 +94,8 @@ extern_c! {
9094
// atomic: BOOL,
9195
// shouldCopy: i8,
9296
// );
97+
// + the atomic versions
98+
9399
// This is generated in setters to struct properties.
94100
// pub fn objc_copyStruct(
95101
// dest: *mut c_void,

crates/objc-sys/src/rc.rs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
//! ARC functions.
22
//!
3-
//! Is available in Clang's [documentation][ARC] so these are safe to rely on.
4-
//!
5-
//! All available since macOS `10.7`.
3+
//! These are documented in Clang's [documentation][ARC], and available since
4+
//! macOS `10.7` unless otherwise noted, so they are safe to rely on.
65
//!
76
//! Defined in:
87
//! - Apple: `objc-internal.h`
98
//! - GNUStep: `objc-arc.h`
109
//! - ObjFW: `runtime/arc.m`
1110
//!
12-
//! [ARC]: https://clang.llvm.org/docs/AutomaticReferenceCounting.html#runtime-support>
11+
//! [ARC]: https://clang.llvm.org/docs/AutomaticReferenceCounting.html#runtime-support
1312
use core::ffi::c_void;
1413

14+
#[cfg(any(doc, apple_new))]
15+
use crate::objc_class;
1516
use crate::objc_object;
1617

1718
// All of these very rarely unwind, but may if the user defined methods
@@ -60,4 +61,25 @@ extern_c_unwind! {
6061
// TODO: Decide about nonstandard extensions like these:
6162
// #[cfg(any(doc, gnustep))]
6263
// pub fn objc_delete_weak_refs(obj: *mut objc_object) -> BOOL;
64+
65+
// Fast paths for certain selectors.
66+
//
67+
// These are not defined in the ARC documentation, but are emitted by
68+
// `clang` and included (and intended to be included) in the final
69+
// binary, so very likely safe to use.
70+
//
71+
// TODO: Unsure why these are not available in the old fragile runtime,
72+
// the headers seem to indicate that they are.
73+
//
74+
// <https://github.com/llvm/llvm-project/blob/llvmorg-17.0.5/clang/include/clang/Basic/ObjCRuntime.h#L229>
75+
76+
// Available since macOS 10.9.
77+
#[cfg(any(doc, apple_new))]
78+
pub fn objc_alloc(value: *const objc_class) -> *mut objc_object;
79+
80+
// Available since macOS 10.9.
81+
#[cfg(any(doc, apple_new))]
82+
pub fn objc_allocWithZone(value: *const objc_class) -> *mut objc_object;
83+
84+
// TODO: objc_alloc_init once supported
6385
}

helper-scripts/gen-git.fish

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,6 @@ function bty
6161
end
6262

6363
function blocklisted
64-
# Added in 10.8
65-
bfn objc_terminate
66-
67-
# Added in 10.10
68-
bfn object_isClass
69-
7064
# Removed in 10.11
7165
bfn objc_setFutureClass
7266

0 commit comments

Comments
 (0)