objc_sys/
object.rs

1#[cfg(any(doc, not(feature = "unstable-objfw")))]
2use core::ffi::c_void;
3use std::os::raw::c_char;
4
5#[cfg(any(doc, not(feature = "unstable-objfw")))]
6use crate::objc_ivar;
7#[cfg(any(doc, target_vendor = "apple"))]
8use crate::BOOL;
9use crate::{objc_class, OpaqueData};
10
11/// An opaque type that represents an object / an instance of a class.
12#[repr(C)]
13pub struct objc_object {
14    // `isa` field is deprecated, so we don't expose it here.
15    //
16    // Also, we need this to be a zero-sized, so that the compiler doesn't
17    // assume anything about the layout.
18    //
19    // Use `object_getClass` instead.
20    _priv: [u8; 0],
21    _p: OpaqueData,
22}
23
24extern_c! {
25    pub fn object_getClass(obj: *const objc_object) -> *const objc_class;
26    pub fn object_getClassName(obj: *const objc_object) -> *const c_char;
27    pub fn object_setClass(obj: *mut objc_object, cls: *const objc_class) -> *const objc_class;
28    #[cfg(any(doc, target_vendor = "apple"))]
29    pub fn object_isClass(obj: *const objc_object) -> BOOL;
30
31    #[cfg(any(doc, not(feature = "unstable-objfw")))]
32    pub fn object_getIndexedIvars(obj: *const objc_object) -> *const c_void;
33    #[cfg(any(doc, not(feature = "unstable-objfw")))]
34    pub fn object_getIvar(obj: *const objc_object, ivar: *const objc_ivar) -> *const objc_object;
35    #[cfg(any(doc, not(feature = "unstable-objfw")))]
36    pub fn object_setIvar(obj: *mut objc_object, ivar: *const objc_ivar, value: *mut objc_object);
37
38    #[deprecated = "Not needed since ARC"]
39    #[cfg(any(doc, target_vendor = "apple"))]
40    pub fn object_copy(obj: *const objc_object, size: usize) -> *mut objc_object;
41
42    #[deprecated = "Not needed since ARC"]
43    #[cfg(any(doc, not(feature = "unstable-objfw")))]
44    pub fn object_dispose(obj: *mut objc_object) -> *mut objc_object;
45
46    #[deprecated = "Not needed since ARC"]
47    #[cfg(any(doc, not(feature = "unstable-objfw")))]
48    pub fn object_setInstanceVariable(
49        obj: *mut objc_object,
50        name: *const c_char,
51        value: *mut c_void,
52    ) -> *const objc_ivar;
53
54    // Available in macOS 10.12
55    // #[deprecated = "Not needed since ARC"]
56    // #[cfg(any(doc, target_vendor = "apple"))]
57    // pub fn object_setInstanceVariableWithStrongDefault(
58    //     obj: *mut objc_object,
59    //     name: *const c_char,
60    //     value: *mut c_void,
61    // ) -> *const objc_ivar;
62
63    #[deprecated = "Not needed since ARC"]
64    #[cfg(any(doc, not(feature = "unstable-objfw")))]
65    pub fn object_getInstanceVariable(
66        obj: *const objc_object,
67        name: *const c_char,
68        out_value: *mut *const c_void,
69    ) -> *const objc_ivar;
70
71    #[deprecated = "Not needed since ARC"]
72    #[cfg(any(doc, target_vendor = "apple"))]
73    pub fn objc_getFutureClass(name: *const c_char) -> *const objc_class;
74    #[deprecated = "Not needed since ARC"]
75    #[cfg(any(doc, target_vendor = "apple"))]
76    pub fn objc_constructInstance(cls: *const objc_class, bytes: *mut c_void) -> *mut objc_object;
77    #[deprecated = "Not needed since ARC"]
78    #[cfg(any(doc, target_vendor = "apple"))]
79    pub fn objc_destructInstance(obj: *mut objc_object) -> *mut c_void;
80
81    // TODO: Unsure if we should expose these; are they useful, and stable?
82    // Defined in objc-abi.h
83    // pub fn objc_getProperty(
84    //     obj: *const objc_object,
85    //     sel: *const objc_selector,
86    //     offset: isize,
87    //     atomic: BOOL,
88    // ) -> *mut c_void;
89    // pub fn objc_setProperty(
90    //     obj: *const objc_object,
91    //     sel: *const objc_selector,
92    //     offset: isize,
93    //     newValue: *const c_void,
94    //     atomic: BOOL,
95    //     shouldCopy: i8,
96    // );
97    // + the atomic versions
98
99    // This is generated in setters to struct properties.
100    // pub fn objc_copyStruct(
101    //     dest: *mut c_void,
102    //     src: *const c_void,
103    //     size: isize,
104    //     atomic: BOOL,
105    //     hasStrong: BOOL,
106    // );
107
108    // #[deprecated = "use object_copy instead"]
109    // #[cfg(any(doc, all(target_vendor = "apple", target_os = "macos")))]
110    // object_copyFromZone
111    // #[deprecated = "use class_createInstance instead"]
112    // #[cfg(any(doc, all(target_vendor = "apple", target_os = "macos")))]
113    // class_createInstanceFromZone
114}