Skip to content

Commit d5b33cc

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

10 files changed

Lines changed: 126 additions & 37 deletions

File tree

objc-sys/src/class.rs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use std::os::raw::{c_char, c_int, c_uint};
22

3-
use crate::{
4-
objc_ivar, objc_method, objc_object, objc_property, objc_property_attribute_t, objc_protocol,
5-
objc_selector, OpaqueData, BOOL, IMP,
6-
};
3+
#[cfg(not(objfw))]
4+
use crate::{objc_ivar, objc_method, objc_object, objc_property, objc_property_attribute_t};
5+
use crate::{objc_protocol, objc_selector, OpaqueData, BOOL, IMP};
76

87
/// An opaque type that represents an Objective-C class.
98
#[repr(C)]
@@ -14,6 +13,7 @@ pub struct objc_class {
1413
_p: OpaqueData,
1514
}
1615

16+
#[cfg(not(objfw))]
1717
/// This is `c_char` in GNUStep's libobjc2 and `uint8_t` in Apple's objc4.
1818
///
1919
/// The pointer represents opaque data, and is definitely not just an integer,
@@ -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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//! Apple: `objc-exception.h`
33
//! GNUStep: `eh_personality.c`, which is a bit brittle to rely on, but I
44
//! think it's fine...
5+
#[cfg(not(objfw))]
56
use core::ffi::c_void;
67
#[cfg(apple)]
78
use std::os::raw::c_int;
@@ -24,6 +25,10 @@ pub type objc_exception_preprocessor =
2425
#[cfg(apple)]
2526
pub type objc_uncaught_exception_handler = unsafe extern "C" fn(exception: *mut objc_object);
2627

28+
#[cfg(objfw)]
29+
pub type objc_uncaught_exception_handler =
30+
Option<unsafe extern "C" fn(exception: *mut objc_object)>;
31+
2732
/// Only available on macOS.
2833
///
2934
/// Remember that this is non-null!
@@ -32,7 +37,9 @@ pub type objc_exception_handler =
3237
unsafe extern "C" fn(unused: *mut objc_object, context: *mut c_void);
3338

3439
extern_c! {
40+
#[cfg(not(objfw))]
3541
pub fn objc_begin_catch(exc_buf: *mut c_void) -> *mut objc_object;
42+
#[cfg(not(objfw))]
3643
pub fn objc_end_catch();
3744
/// See [`objc-exception.h`].
3845
///
@@ -49,7 +56,7 @@ extern_c! {
4956
pub fn objc_setExceptionPreprocessor(
5057
f: objc_exception_preprocessor,
5158
) -> objc_exception_preprocessor;
52-
#[cfg(apple)]
59+
#[cfg(any(apple, objfw))]
5360
pub fn objc_setUncaughtExceptionHandler(
5461
f: objc_uncaught_exception_handler,
5562
) -> objc_uncaught_exception_handler;

objc-sys/src/message.rs

Lines changed: 2 additions & 2 deletions
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

Lines changed: 8 additions & 2 deletions
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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
#[cfg(not(objfw))]
12
use core::ffi::c_void;
23
use std::os::raw::c_char;
34

4-
use crate::{objc_class, objc_ivar, OpaqueData};
5+
#[cfg(not(objfw))]
6+
use crate::objc_ivar;
7+
use crate::{objc_class, OpaqueData};
58

69
/// An opaque type that represents an object / an instance of a class.
710
#[repr(C)]
@@ -15,23 +18,31 @@ pub struct objc_object {
1518
extern_c! {
1619
pub fn object_getClass(obj: *const objc_object) -> *const objc_class;
1720
pub fn object_getClassName(obj: *const objc_object) -> *const c_char;
21+
pub fn object_setClass(obj: *mut objc_object, cls: *const objc_class) -> *const objc_class;
22+
23+
#[cfg(not(objfw))]
1824
pub fn object_getIndexedIvars(obj: *const objc_object) -> *const c_void;
25+
#[cfg(not(objfw))]
1926
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;
27+
#[cfg(not(objfw))]
2228
pub fn object_setIvar(obj: *mut objc_object, ivar: *const objc_ivar, value: *mut objc_object);
2329

2430
#[deprecated = "Not needed since ARC"]
2531
#[cfg(apple)]
2632
pub fn object_copy(obj: *const objc_object, size: usize) -> *mut objc_object;
33+
2734
#[deprecated = "Not needed since ARC"]
35+
#[cfg(not(objfw))]
2836
pub fn object_dispose(obj: *mut objc_object) -> *mut objc_object;
37+
2938
#[deprecated = "Not needed since ARC"]
39+
#[cfg(not(objfw))]
3040
pub fn object_setInstanceVariable(
3141
obj: *mut objc_object,
3242
name: *const c_char,
3343
value: *mut c_void,
3444
) -> *const objc_ivar;
45+
3546
// Available in macOS 10.12
3647
// #[deprecated = "Not needed since ARC"]
3748
// #[cfg(apple)]
@@ -40,12 +51,15 @@ extern_c! {
4051
// name: *const c_char,
4152
// value: *mut c_void,
4253
// ) -> *const objc_ivar;
54+
4355
#[deprecated = "Not needed since ARC"]
56+
#[cfg(not(objfw))]
4457
pub fn object_getInstanceVariable(
4558
obj: *const objc_object,
4659
name: *const c_char,
4760
out_value: *mut *const c_void,
4861
) -> *const objc_ivar;
62+
4963
#[deprecated = "Not needed since ARC"]
5064
#[cfg(apple)]
5165
pub fn objc_getFutureClass(name: *const c_char) -> *const objc_class;

objc-sys/src/property.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use std::os::raw::{c_char, c_uint};
1+
use std::os::raw::c_char;
2+
#[cfg(not(objfw))]
3+
use std::os::raw::c_uint;
24

35
use crate::OpaqueData;
46

@@ -22,6 +24,8 @@ pub struct objc_property_attribute_t {
2224
}
2325

2426
extern_c! {
27+
#![cfg(not(objfw))]
28+
2529
pub fn property_copyAttributeList(
2630
property: *const objc_property,
2731
out_len: *mut c_uint,

objc-sys/src/protocol.rs

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
use std::os::raw::{c_char, c_uint};
1+
use std::os::raw::c_char;
2+
#[cfg(not(objfw))]
3+
use std::os::raw::c_uint;
24

3-
use crate::{
4-
objc_method_description, objc_property, objc_property_attribute_t, objc_selector, OpaqueData,
5-
BOOL,
6-
};
5+
#[cfg(not(objfw))]
6+
use crate::{objc_method_description, objc_property, objc_property_attribute_t, objc_selector};
7+
use crate::{OpaqueData, BOOL};
78

89
/// Opaque type for Objective-C protocols.
910
///
@@ -19,19 +20,32 @@ pub struct objc_protocol {
1920
}
2021

2122
extern_c! {
23+
#[cfg(not(objfw))]
2224
pub fn objc_getProtocol(name: *const c_char) -> *const objc_protocol;
25+
#[cfg(not(objfw))]
2326
pub fn objc_copyProtocolList(out_len: *mut c_uint) -> *mut *const objc_protocol;
2427

28+
#[cfg(not(objfw))]
2529
pub fn objc_allocateProtocol(name: *const c_char) -> *mut objc_protocol;
30+
#[cfg(not(objfw))]
2631
pub fn objc_registerProtocol(proto: *mut objc_protocol);
2732

33+
pub fn protocol_conformsToProtocol(
34+
proto: *const objc_protocol,
35+
other: *const objc_protocol,
36+
) -> BOOL;
37+
pub fn protocol_isEqual(proto: *const objc_protocol, other: *const objc_protocol) -> BOOL;
38+
pub fn protocol_getName(proto: *const objc_protocol) -> *const c_char;
39+
40+
#[cfg(not(objfw))]
2841
pub fn protocol_addMethodDescription(
2942
proto: *mut objc_protocol,
3043
name: *const objc_selector,
3144
types: *const c_char,
3245
is_required_method: BOOL,
3346
is_instance_method: BOOL,
3447
);
48+
#[cfg(not(objfw))]
3549
pub fn protocol_addProperty(
3650
proto: *mut objc_protocol,
3751
name: *const c_char,
@@ -40,39 +54,39 @@ extern_c! {
4054
is_required_property: BOOL,
4155
is_instance_property: BOOL,
4256
);
57+
#[cfg(not(objfw))]
4358
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;
59+
#[cfg(not(objfw))]
4860
pub fn protocol_copyMethodDescriptionList(
4961
proto: *const objc_protocol,
5062
is_required_method: BOOL,
5163
is_instance_method: BOOL,
5264
out_len: *mut c_uint,
5365
) -> *mut objc_method_description;
66+
#[cfg(not(objfw))]
5467
pub fn protocol_copyPropertyList(
5568
proto: *const objc_protocol,
5669
out_len: *mut c_uint,
5770
) -> *mut *const objc_property;
71+
#[cfg(not(objfw))]
5872
pub fn protocol_copyProtocolList(
5973
proto: *const objc_protocol,
6074
out_len: *mut c_uint,
6175
) -> *mut *const objc_protocol;
76+
#[cfg(not(objfw))]
6277
pub fn protocol_getMethodDescription(
6378
proto: *const objc_protocol,
6479
sel: *const objc_selector,
6580
is_required_method: BOOL,
6681
is_instance_method: BOOL,
6782
) -> objc_method_description;
68-
pub fn protocol_getName(proto: *const objc_protocol) -> *const c_char;
83+
#[cfg(not(objfw))]
6984
pub fn protocol_getProperty(
7085
proto: *const objc_protocol,
7186
name: *const c_char,
7287
is_required_property: BOOL,
7388
is_instance_property: BOOL,
7489
) -> *const objc_property;
75-
pub fn protocol_isEqual(proto: *const objc_protocol, other: *const objc_protocol) -> BOOL;
7690

7791
// #[cfg(macos >= 10.12)]
7892
// protocol_copyPropertyList2

0 commit comments

Comments
 (0)