objc_sys/
various.rs

1use core::ffi::c_void;
2#[cfg(any(doc, not(feature = "unstable-objfw")))]
3use std::os::raw::c_char;
4use std::os::raw::c_int;
5#[cfg(any(doc, target_vendor = "apple"))]
6use std::os::raw::c_uint;
7
8#[cfg(any(doc, not(feature = "unstable-objfw")))]
9use crate::{objc_AssociationPolicy, BOOL};
10use crate::{objc_object, OpaqueData};
11
12/// An opaque type that represents an instance variable.
13#[repr(C)]
14pub struct objc_ivar {
15    _priv: [u8; 0],
16    _p: OpaqueData,
17}
18
19#[cfg(not(feature = "unstable-c-unwind"))]
20type InnerImp = unsafe extern "C" fn();
21#[cfg(feature = "unstable-c-unwind")]
22type InnerImp = unsafe extern "C-unwind" fn();
23
24/// A nullable pointer to the start of a method implementation.
25///
26/// Not all APIs are guaranteed to take NULL values; read the docs!
27pub type IMP = Option<InnerImp>;
28
29// /// Remember that this is non-null!
30// #[cfg(any(doc, all(target_vendor = "apple", not(all(target_os = "macos", target_arch = "x86")))))]
31// pub type objc_hook_getClass =
32//     unsafe extern "C" fn(name: *const c_char, out_cls: *mut *const crate::objc_class) -> BOOL;
33//
34// /// Remember that this is non-null!
35// #[cfg(any(doc, all(target_vendor = "apple", not(all(target_os = "macos", target_arch = "x86")))))]
36// pub type objc_hook_lazyClassNamer =
37//     unsafe extern "C" fn(cls: *const crate::objc_class) -> *const c_char;
38
39extern_c_unwind! {
40    // Instead of being able to change this, it's a weak symbol on GNUStep.
41    #[cfg(any(doc, target_vendor = "apple", feature = "unstable-objfw"))]
42    pub fn objc_enumerationMutation(obj: *mut objc_object);
43}
44
45extern_c! {
46    #[cfg(any(doc, not(feature = "unstable-objfw")))]
47    pub fn imp_getBlock(imp: IMP) -> *mut objc_object;
48    // See also <https://landonf.org/code/objc/imp_implementationWithBlock.20110413.html>
49    #[cfg(any(doc, not(feature = "unstable-objfw")))]
50    pub fn imp_implementationWithBlock(block: *mut objc_object) -> IMP;
51    #[cfg(any(doc, not(feature = "unstable-objfw")))]
52    pub fn imp_removeBlock(imp: IMP) -> BOOL;
53
54    #[cfg(any(doc, not(feature = "unstable-objfw")))]
55    pub fn ivar_getName(ivar: *const objc_ivar) -> *const c_char;
56    #[cfg(any(doc, not(feature = "unstable-objfw")))]
57    pub fn ivar_getOffset(ivar: *const objc_ivar) -> isize;
58    #[cfg(any(doc, not(feature = "unstable-objfw")))]
59    pub fn ivar_getTypeEncoding(ivar: *const objc_ivar) -> *const c_char;
60
61    #[cfg(any(doc, target_vendor = "apple"))]
62    pub fn objc_copyClassNamesForImage(
63        image: *const c_char,
64        out_len: *mut c_uint,
65    ) -> *mut *const c_char;
66    #[cfg(any(doc, target_vendor = "apple"))]
67    /// The returned array is deallocated with [`free`][crate::free].
68    pub fn objc_copyImageNames(out_len: *mut c_uint) -> *mut *const c_char;
69
70    #[cfg(any(doc, target_vendor = "apple", feature = "unstable-objfw"))]
71    pub fn objc_setEnumerationMutationHandler(
72        handler: Option<unsafe extern "C" fn(obj: *mut objc_object)>,
73    );
74
75    #[cfg(any(doc, not(feature = "unstable-objfw")))]
76    pub fn objc_getAssociatedObject(
77        object: *const objc_object,
78        key: *const c_void,
79    ) -> *const objc_object;
80    #[cfg(any(doc, not(feature = "unstable-objfw")))]
81    pub fn objc_setAssociatedObject(
82        object: *mut objc_object,
83        key: *const c_void,
84        value: *mut objc_object,
85        policy: objc_AssociationPolicy,
86    );
87    #[cfg(any(doc, not(feature = "unstable-objfw")))]
88    pub fn objc_removeAssociatedObjects(object: *mut objc_object);
89
90    #[cfg(any(doc, target_vendor = "apple", feature = "unstable-objfw"))]
91    pub fn objc_setForwardHandler(fwd: *mut c_void, fwd_stret: *mut c_void);
92    // These two are defined in:
93    // - Apple: objc-sync.h
94    // - GNUStep: dtable.h / associate.m
95    // - ObjFW: ObjFW-RT.h
96    pub fn objc_sync_enter(obj: *mut objc_object) -> c_int;
97    pub fn objc_sync_exit(obj: *mut objc_object) -> c_int;
98
99    // Available in macOS 10.14.4
100    // /// Remember that this is non-null!
101    // #[cfg(any(doc, all(target_vendor = "apple", not(all(target_os = "macos", target_arch = "x86")))))]
102    // pub fn objc_setHook_getClass(
103    //     new_value: objc_hook_getClass,
104    //     out_old_value: *mut objc_hook_getClass,
105    // );
106    // Available in macOS 11
107    // /// Remember that this is non-null!
108    // #[cfg(any(doc, all(target_vendor = "apple", not(all(target_os = "macos", target_arch = "x86")))))]
109    // pub fn objc_setHook_lazyClassNamer(
110    //     new_value: objc_hook_lazyClassNamer,
111    //     out_old_value: *mut objc_hook_lazyClassNamer,
112    // );
113
114    // #[deprecated = "not recommended"]
115    // #[cfg(any(doc, target_vendor = "apple"))]
116    // pub fn _objc_flush_caches
117
118    // #[cfg(any(doc, feature = "gnustep-1-7"))]
119    // objc_test_capability
120}