Skip to content

Commit 8b1fe76

Browse files
committed
cfg-guard objc_sys symbols not available in ObjFW
1 parent aac75da commit 8b1fe76

File tree

10 files changed

+103
-24
lines changed

10 files changed

+103
-24
lines changed

objc-sys/src/class.rs

+21
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ extern_c! {
2727
pub fn objc_getClass(name: *const c_char) -> *const objc_class;
2828
pub fn objc_getRequiredClass(name: *const c_char) -> *const objc_class;
2929
pub fn objc_lookUpClass(name: *const c_char) -> *const objc_class;
30+
#[cfg(not(objfw))]
3031
pub fn objc_getMetaClass(name: *const c_char) -> *const objc_class;
3132
pub fn objc_copyClassList(out_len: *mut c_uint) -> *mut *const objc_class;
3233
pub fn objc_getClassList(buffer: *mut *const objc_class, buffer_len: c_int) -> c_int;
@@ -42,9 +43,11 @@ extern_c! {
4243
name: *const c_char,
4344
extra_bytes: usize,
4445
) -> *mut objc_class;
46+
#[cfg(not(objfw))]
4547
pub fn objc_disposeClassPair(cls: *mut objc_class);
4648
pub fn objc_registerClassPair(cls: *mut objc_class);
4749

50+
#[cfg(not(objfw))]
4851
pub fn class_addIvar(
4952
cls: *mut objc_class,
5053
name: *const c_char,
@@ -58,53 +61,68 @@ extern_c! {
5861
imp: IMP,
5962
types: *const c_char,
6063
) -> BOOL;
64+
#[cfg(not(objfw))]
6165
pub fn class_addProperty(
6266
cls: *mut objc_class,
6367
name: *const c_char,
6468
attributes: *const objc_property_attribute_t,
6569
attributes_count: c_uint,
6670
) -> BOOL;
71+
#[cfg(not(objfw))]
6772
pub fn class_addProtocol(cls: *mut objc_class, protocol: *const objc_protocol) -> BOOL;
6873
pub fn class_conformsToProtocol(cls: *const objc_class, protocol: *const objc_protocol)
6974
-> BOOL;
75+
76+
#[cfg(not(objfw))] // Available in newer versions
7077
pub fn class_copyIvarList(
7178
cls: *const objc_class,
7279
out_len: *mut c_uint,
7380
) -> *mut *const objc_ivar;
81+
#[cfg(not(objfw))] // Available in newer versions
7482
pub fn class_copyMethodList(
7583
cls: *const objc_class,
7684
out_len: *mut c_uint,
7785
) -> *mut *const objc_method;
86+
#[cfg(not(objfw))] // Available in newer versions
7887
pub fn class_copyPropertyList(
7988
cls: *const objc_class,
8089
out_len: *mut c_uint,
8190
) -> *mut *const objc_property;
91+
#[cfg(not(objfw))]
8292
pub fn class_copyProtocolList(
8393
cls: *const objc_class,
8494
out_len: *mut c_uint,
8595
) -> *mut *const objc_protocol;
8696

97+
#[cfg(not(objfw))]
8798
pub fn class_createInstance(cls: *const objc_class, extra_bytes: usize) -> *mut objc_object;
99+
#[cfg(not(objfw))]
88100
pub fn class_getClassMethod(
89101
cls: *const objc_class,
90102
name: *const objc_selector,
91103
) -> *const objc_method;
104+
#[cfg(not(objfw))]
92105
pub fn class_getClassVariable(cls: *const objc_class, name: *const c_char) -> *const objc_ivar;
93106
#[cfg(apple)]
94107
pub fn class_getImageName(cls: *const objc_class) -> *const c_char;
108+
#[cfg(not(objfw))] // Available in newer versions
95109
pub fn class_getInstanceMethod(
96110
cls: *const objc_class,
97111
name: *const objc_selector,
98112
) -> *const objc_method;
99113
pub fn class_getInstanceSize(cls: *const objc_class) -> usize;
114+
#[cfg(not(objfw))]
100115
pub fn class_getInstanceVariable(
101116
cls: *const objc_class,
102117
name: *const c_char,
103118
) -> *const objc_ivar;
119+
#[cfg(not(objfw))]
104120
pub fn class_getIvarLayout(cls: *const objc_class) -> *const ivar_layout_type;
105121
pub fn class_getName(cls: *const objc_class) -> *const c_char;
122+
#[cfg(not(objfw))]
106123
pub fn class_getProperty(cls: *const objc_class, name: *const c_char) -> *const objc_property;
107124
pub fn class_getSuperclass(cls: *const objc_class) -> *const objc_class;
125+
#[cfg(not(objfw))]
108126
pub fn class_getVersion(cls: *const objc_class) -> c_int;
109127
#[cfg(apple)]
110128
pub fn class_getWeakIvarLayout(cls: *const objc_class) -> *const ivar_layout_type;
@@ -115,14 +133,17 @@ extern_c! {
115133
imp: IMP,
116134
types: *const c_char,
117135
) -> IMP;
136+
#[cfg(not(objfw))]
118137
pub fn class_replaceProperty(
119138
cls: *mut objc_class,
120139
name: *const c_char,
121140
attributes: *const objc_property_attribute_t,
122141
attributes_len: c_uint,
123142
);
124143
pub fn class_respondsToSelector(cls: *const objc_class, sel: *const objc_selector) -> BOOL;
144+
#[cfg(not(objfw))]
125145
pub fn class_setIvarLayout(cls: *mut objc_class, layout: *const ivar_layout_type);
146+
#[cfg(not(objfw))]
126147
pub fn class_setVersion(cls: *mut objc_class, version: c_int);
127148
#[cfg(apple)]
128149
pub fn class_setWeakIvarLayout(cls: *mut objc_class, layout: *const ivar_layout_type);

objc-sys/src/exception.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ pub type objc_exception_preprocessor =
2424
#[cfg(apple)]
2525
pub type objc_uncaught_exception_handler = unsafe extern "C" fn(exception: *mut objc_object);
2626

27+
#[cfg(objfw)]
28+
pub type objc_uncaught_exception_handler =
29+
Option<unsafe extern "C" fn(exception: *mut objc_object)>;
30+
2731
/// Only available on macOS.
2832
///
2933
/// Remember that this is non-null!
@@ -32,7 +36,9 @@ pub type objc_exception_handler =
3236
unsafe extern "C" fn(unused: *mut objc_object, context: *mut c_void);
3337

3438
extern_c! {
39+
#[cfg(not(objfw))]
3540
pub fn objc_begin_catch(exc_buf: *mut c_void) -> *mut objc_object;
41+
#[cfg(not(objfw))]
3642
pub fn objc_end_catch();
3743
/// See [`objc-exception.h`].
3844
///
@@ -49,7 +55,7 @@ extern_c! {
4955
pub fn objc_setExceptionPreprocessor(
5056
f: objc_exception_preprocessor,
5157
) -> objc_exception_preprocessor;
52-
#[cfg(apple)]
58+
#[cfg(any(apple, objfw))]
5359
pub fn objc_setUncaughtExceptionHandler(
5460
f: objc_uncaught_exception_handler,
5561
) -> objc_uncaught_exception_handler;

objc-sys/src/message.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ extern_c! {
6868
/// Not available on `target_arch = "aarch64"`
6969
#[cfg(all(apple, not(target_arch = "aarch64")))]
7070
pub fn _objc_msgForward_stret();
71-
/// Not available on `target_arch = "aarch64"`
72-
#[cfg(not(target_arch = "aarch64"))]
71+
/// Not available on `target_arch = "aarch64"`, always available on ObjFW
72+
#[cfg(any(objfw, not(target_arch = "aarch64")))]
7373
pub fn class_getMethodImplementation_stret();
7474

7575
// __x86_64__ and __i386__

objc-sys/src/method.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
use std::os::raw::{c_char, c_uint};
1+
use std::os::raw::c_char;
2+
#[cfg(objfw)]
3+
use std::os::raw::c_uint;
24

3-
use crate::{objc_selector, OpaqueData, IMP};
5+
#[cfg(objfw)]
6+
use crate::IMP;
7+
use crate::{objc_selector, OpaqueData};
48

59
/// A type that represents a method in a class definition.
610
#[repr(C)]
@@ -20,6 +24,8 @@ pub struct objc_method_description {
2024
}
2125

2226
extern_c! {
27+
#![cfg(objfw)]
28+
2329
pub fn method_copyArgumentType(method: *const objc_method, index: c_uint) -> *mut c_char;
2430
pub fn method_copyReturnType(method: *const objc_method) -> *mut c_char;
2531
pub fn method_exchangeImplementations(method1: *mut objc_method, method2: *mut objc_method);

objc-sys/src/object.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#[cfg(not(objfw))]
12
use core::ffi::c_void;
23
use std::os::raw::c_char;
34

@@ -15,23 +16,31 @@ pub struct objc_object {
1516
extern_c! {
1617
pub fn object_getClass(obj: *const objc_object) -> *const objc_class;
1718
pub fn object_getClassName(obj: *const objc_object) -> *const c_char;
19+
pub fn object_setClass(obj: *mut objc_object, cls: *const objc_class) -> *const objc_class;
20+
21+
#[cfg(not(objfw))]
1822
pub fn object_getIndexedIvars(obj: *const objc_object) -> *const c_void;
23+
#[cfg(not(objfw))]
1924
pub fn object_getIvar(obj: *const objc_object, ivar: *const objc_ivar) -> *const objc_object;
20-
21-
pub fn object_setClass(obj: *mut objc_object, cls: *const objc_class) -> *const objc_class;
25+
#[cfg(not(objfw))]
2226
pub fn object_setIvar(obj: *mut objc_object, ivar: *const objc_ivar, value: *mut objc_object);
2327

2428
#[deprecated = "Not needed since ARC"]
2529
#[cfg(apple)]
2630
pub fn object_copy(obj: *const objc_object, size: usize) -> *mut objc_object;
31+
2732
#[deprecated = "Not needed since ARC"]
33+
#[cfg(not(objfw))]
2834
pub fn object_dispose(obj: *mut objc_object) -> *mut objc_object;
35+
2936
#[deprecated = "Not needed since ARC"]
37+
#[cfg(not(objfw))]
3038
pub fn object_setInstanceVariable(
3139
obj: *mut objc_object,
3240
name: *const c_char,
3341
value: *mut c_void,
3442
) -> *const objc_ivar;
43+
3544
// Available in macOS 10.12
3645
// #[deprecated = "Not needed since ARC"]
3746
// #[cfg(apple)]
@@ -40,12 +49,15 @@ extern_c! {
4049
// name: *const c_char,
4150
// value: *mut c_void,
4251
// ) -> *const objc_ivar;
52+
4353
#[deprecated = "Not needed since ARC"]
54+
#[cfg(not(objfw))]
4455
pub fn object_getInstanceVariable(
4556
obj: *const objc_object,
4657
name: *const c_char,
4758
out_value: *mut *const c_void,
4859
) -> *const objc_ivar;
60+
4961
#[deprecated = "Not needed since ARC"]
5062
#[cfg(apple)]
5163
pub fn objc_getFutureClass(name: *const c_char) -> *const objc_class;

objc-sys/src/property.rs

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ pub struct objc_property_attribute_t {
2222
}
2323

2424
extern_c! {
25+
#![cfg(not(objfw))]
26+
2527
pub fn property_copyAttributeList(
2628
property: *const objc_property,
2729
out_len: *mut c_uint,

objc-sys/src/protocol.rs

+19-6
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,32 @@ pub struct objc_protocol {
1919
}
2020

2121
extern_c! {
22+
#[cfg(not(objfw))]
2223
pub fn objc_getProtocol(name: *const c_char) -> *const objc_protocol;
24+
#[cfg(not(objfw))]
2325
pub fn objc_copyProtocolList(out_len: *mut c_uint) -> *mut *const objc_protocol;
2426

27+
#[cfg(not(objfw))]
2528
pub fn objc_allocateProtocol(name: *const c_char) -> *mut objc_protocol;
29+
#[cfg(not(objfw))]
2630
pub fn objc_registerProtocol(proto: *mut objc_protocol);
2731

32+
pub fn protocol_conformsToProtocol(
33+
proto: *const objc_protocol,
34+
other: *const objc_protocol,
35+
) -> BOOL;
36+
pub fn protocol_isEqual(proto: *const objc_protocol, other: *const objc_protocol) -> BOOL;
37+
pub fn protocol_getName(proto: *const objc_protocol) -> *const c_char;
38+
39+
#[cfg(not(objfw))]
2840
pub fn protocol_addMethodDescription(
2941
proto: *mut objc_protocol,
3042
name: *const objc_selector,
3143
types: *const c_char,
3244
is_required_method: BOOL,
3345
is_instance_method: BOOL,
3446
);
47+
#[cfg(not(objfw))]
3548
pub fn protocol_addProperty(
3649
proto: *mut objc_protocol,
3750
name: *const c_char,
@@ -40,39 +53,39 @@ extern_c! {
4053
is_required_property: BOOL,
4154
is_instance_property: BOOL,
4255
);
56+
#[cfg(not(objfw))]
4357
pub fn protocol_addProtocol(proto: *mut objc_protocol, addition: *const objc_protocol);
44-
pub fn protocol_conformsToProtocol(
45-
proto: *const objc_protocol,
46-
other: *const objc_protocol,
47-
) -> BOOL;
58+
#[cfg(not(objfw))]
4859
pub fn protocol_copyMethodDescriptionList(
4960
proto: *const objc_protocol,
5061
is_required_method: BOOL,
5162
is_instance_method: BOOL,
5263
out_len: *mut c_uint,
5364
) -> *mut objc_method_description;
65+
#[cfg(not(objfw))]
5466
pub fn protocol_copyPropertyList(
5567
proto: *const objc_protocol,
5668
out_len: *mut c_uint,
5769
) -> *mut *const objc_property;
70+
#[cfg(not(objfw))]
5871
pub fn protocol_copyProtocolList(
5972
proto: *const objc_protocol,
6073
out_len: *mut c_uint,
6174
) -> *mut *const objc_protocol;
75+
#[cfg(not(objfw))]
6276
pub fn protocol_getMethodDescription(
6377
proto: *const objc_protocol,
6478
sel: *const objc_selector,
6579
is_required_method: BOOL,
6680
is_instance_method: BOOL,
6781
) -> objc_method_description;
68-
pub fn protocol_getName(proto: *const objc_protocol) -> *const c_char;
82+
#[cfg(not(objfw))]
6983
pub fn protocol_getProperty(
7084
proto: *const objc_protocol,
7185
name: *const c_char,
7286
is_required_property: BOOL,
7387
is_instance_property: BOOL,
7488
) -> *const objc_property;
75-
pub fn protocol_isEqual(proto: *const objc_protocol, other: *const objc_protocol) -> BOOL;
7689

7790
// #[cfg(macos >= 10.12)]
7891
// protocol_copyPropertyList2

objc-sys/src/rc.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
//! ARC functions.
22
//!
3-
//! All available since macOS `10.7`.
3+
//! Is available in Clang's [documentation][ARC] so these are safe to rely on.
44
//!
5-
//! Defined in `objc-internal.h`, but is available in Clang's
6-
//! [documentation][ARC] so these are safe to rely on.
5+
//! All available since macOS `10.7`.
76
//!
8-
//! On GNUStep these are defined in `objc-arc.h`.
7+
//! Defined in:
8+
//! - Apple: `objc-internal.h`
9+
//! - GNUStep: `objc-arc.h`
10+
//! - ObjFW: `runtime/arc.m`
911
//!
1012
//! [ARC]: https://clang.llvm.org/docs/AutomaticReferenceCounting.html#runtime-support>
1113
use core::ffi::c_void;
1214

1315
use crate::objc_object;
1416

1517
extern_c! {
16-
// Autorelease
18+
// Autoreleasepool
19+
// ObjFW: Defined in `autorelease.h`
1720

18-
pub fn objc_autorelease(value: *mut objc_object) -> *mut objc_object;
1921
pub fn objc_autoreleasePoolPop(pool: *mut c_void);
2022
pub fn objc_autoreleasePoolPush() -> *mut c_void;
23+
24+
// Autorelease
25+
26+
pub fn objc_autorelease(value: *mut objc_object) -> *mut objc_object;
2127
pub fn objc_autoreleaseReturnValue(value: *mut objc_object) -> *mut objc_object;
2228

2329
// Weak pointers

objc-sys/src/selector.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ pub struct objc_selector {
1313

1414
extern_c! {
1515
pub fn sel_getName(sel: *const objc_selector) -> *const c_char;
16-
pub fn sel_getUid(name: *const c_char) -> *const objc_selector;
1716
pub fn sel_isEqual(lhs: *const objc_selector, rhs: *const objc_selector) -> BOOL;
17+
pub fn sel_registerName(name: *const c_char) -> *const objc_selector;
18+
19+
#[cfg(not(objfw))]
20+
pub fn sel_getUid(name: *const c_char) -> *const objc_selector;
21+
1822
#[cfg(apple)]
1923
pub fn sel_isMapped(sel: *const objc_selector) -> BOOL;
20-
pub fn sel_registerName(name: *const c_char) -> *const objc_selector;
2124
}

0 commit comments

Comments
 (0)