Skip to content

Commit

Permalink
sys: Move ARC functions to their own file, and add missing declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Sep 5, 2021
1 parent 96a80f0 commit 052bcd6
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 23 deletions.
6 changes: 0 additions & 6 deletions objc_sys/src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,12 +376,6 @@ extern "C" {
extern "C" {
pub fn imp_removeBlock(anImp: IMP) -> BOOL;
}
extern "C" {
pub fn objc_loadWeak(location: *mut id) -> id;
}
extern "C" {
pub fn objc_storeWeak(location: *mut id, obj: id) -> id;
}
extern "C" {
pub fn objc_setAssociatedObject(
object: id,
Expand Down
20 changes: 3 additions & 17 deletions objc_sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@

extern crate std;

use core::ffi::c_void;
use std::os::raw::{c_char, c_int, c_uint};

mod bindings;
mod constants;
mod message;
mod rc;
mod types;
mod bindings;

pub use constants::*;
pub use message::*;
pub use rc::*;
pub use types::*;

#[link(name = "objc", kind = "dylib")]
Expand Down Expand Up @@ -92,9 +93,6 @@ extern "C" {
pub fn objc_allocateProtocol(name: *const c_char) -> *mut objc_protocol;
pub fn objc_registerProtocol(proto: *mut objc_protocol);

pub fn objc_autoreleasePoolPush() -> *mut c_void;
pub fn objc_autoreleasePoolPop(context: *mut c_void);

pub fn protocol_addMethodDescription(
proto: *mut objc_protocol,
name: *const objc_selector,
Expand Down Expand Up @@ -125,16 +123,4 @@ extern "C" {
pub fn method_getNumberOfArguments(method: *const objc_method) -> c_uint;
pub fn method_setImplementation(method: *mut objc_method, imp: IMP) -> IMP;
pub fn method_exchangeImplementations(m1: *mut objc_method, m2: *mut objc_method);

pub fn objc_retain(obj: *mut objc_object) -> *mut objc_object;
pub fn objc_release(obj: *mut objc_object);
pub fn objc_autorelease(obj: *mut objc_object);

pub fn objc_loadWeakRetained(location: *mut *mut objc_object) -> *mut objc_object;
pub fn objc_initWeak(
location: *mut *mut objc_object,
obj: *mut objc_object,
) -> *mut objc_object;
pub fn objc_destroyWeak(location: *mut *mut objc_object);
pub fn objc_copyWeak(to: *mut *mut objc_object, from: *mut *mut objc_object);
}
51 changes: 51 additions & 0 deletions objc_sys/src/rc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//! ARC functions.
//!
//! All available since macOS `10.7`.
//!
//! Defined in `objc-internal.h`, but is available in Clang's
//! [documentation][ARC] so these are safe to rely on.
//!
//! [ARC]: https://clang.llvm.org/docs/AutomaticReferenceCounting.html#runtime-support>
use core::ffi::c_void;

use crate::objc_object;

extern "C" {
// Autorelease

pub fn objc_autorelease(value: *mut objc_object) -> *mut objc_object;
pub fn objc_autoreleasePoolPop(pool: *mut c_void);
pub fn objc_autoreleasePoolPush() -> *mut c_void;
pub fn objc_autoreleaseReturnValue(value: *mut objc_object) -> *mut objc_object;

// Weak pointers

pub fn objc_copyWeak(to: *mut *mut objc_object, from: *mut *mut objc_object);
pub fn objc_destroyWeak(location: *mut *mut objc_object);
pub fn objc_initWeak(
location: *mut *mut objc_object,
value: *mut objc_object,
) -> *mut objc_object;
// Defined in runtime.h
pub fn objc_loadWeak(location: *mut *mut objc_object) -> *mut objc_object;
pub fn objc_loadWeakRetained(location: *mut *mut objc_object) -> *mut objc_object;
pub fn objc_moveWeak(to: *mut *mut objc_object, from: *mut *mut objc_object);

// Retain / release

pub fn objc_release(value: *mut objc_object);
pub fn objc_retain(value: *mut objc_object) -> *mut objc_object;
pub fn objc_retainAutorelease(value: *mut objc_object) -> *mut objc_object;
pub fn objc_retainAutoreleasedReturnValue(value: *mut objc_object) -> *mut objc_object;
// Defined in objc-abi.h
pub fn objc_retainBlock(value: *mut objc_object) -> *mut objc_object;

// Storing values

pub fn objc_storeStrong(location: *mut *mut objc_object, value: *mut objc_object);
// Defined in runtime.h
pub fn objc_storeWeak(
location: *mut *mut objc_object,
value: *mut objc_object,
) -> *mut objc_object;
}

0 comments on commit 052bcd6

Please sign in to comment.