Skip to content

Commit df36b02

Browse files
committed
Preserve backwards compatibility for old rust versions
As mentioned in #66, the new release will just be a patch release. To be on the safe side, we can preserve backwards compatibility by working around the following two incompatibilities: * omitting the field name when initializing `Sel`, which requires rust 1.17 * using `AtomicPtr::new` in a constant, which requires rust 1.24
1 parent 6584f53 commit df36b02

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

src/macros.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@ macro_rules! class {
1818
#[inline(always)]
1919
fn get_class(name: &str) -> Option<&'static $crate::runtime::Class> {
2020
unsafe {
21-
static CLASS: ::std::sync::atomic::AtomicPtr<$crate::runtime::Class> =
22-
::std::sync::atomic::AtomicPtr::new(0 as *mut _);
21+
static CLASS: ::std::sync::atomic::AtomicUsize = ::std::sync::atomic::ATOMIC_USIZE_INIT;
2322
// `Relaxed` should be fine since `objc_getClass` is thread-safe.
24-
let ptr = CLASS.load(::std::sync::atomic::Ordering::Relaxed);
23+
let ptr = CLASS.load(::std::sync::atomic::Ordering::Relaxed) as *const $crate::runtime::Class;
2524
if ptr.is_null() {
2625
let cls = $crate::runtime::objc_getClass(name.as_ptr() as *const _);
27-
CLASS.store(cls as *mut _, ::std::sync::atomic::Ordering::Relaxed);
26+
CLASS.store(cls as usize, ::std::sync::atomic::Ordering::Relaxed);
2827
if cls.is_null() { None } else { Some(&*cls) }
2928
} else {
3029
Some(&*ptr)
@@ -47,14 +46,13 @@ macro_rules! sel_impl {
4746
#[inline(always)]
4847
fn register_sel(name: &str) -> $crate::runtime::Sel {
4948
unsafe {
50-
static SEL: ::std::sync::atomic::AtomicPtr<::std::os::raw::c_void> =
51-
::std::sync::atomic::AtomicPtr::new(0 as *mut _);
52-
let ptr = SEL.load(::std::sync::atomic::Ordering::Relaxed);
49+
static SEL: ::std::sync::atomic::AtomicUsize = ::std::sync::atomic::ATOMIC_USIZE_INIT;
50+
let ptr = SEL.load(::std::sync::atomic::Ordering::Relaxed) as *const ::std::os::raw::c_void;
5351
// It should be fine to use `Relaxed` ordering here because `sel_registerName` is
5452
// thread-safe.
5553
if ptr.is_null() {
5654
let sel = $crate::runtime::sel_registerName(name.as_ptr() as *const _);
57-
SEL.store(sel.as_ptr() as *mut _, ::std::sync::atomic::Ordering::Relaxed);
55+
SEL.store(sel.as_ptr() as usize, ::std::sync::atomic::Ordering::Relaxed);
5856
sel
5957
} else {
6058
$crate::runtime::Sel::from_ptr(ptr)

src/runtime.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ impl Sel {
154154
#[inline]
155155
pub unsafe fn from_ptr(ptr: *const c_void) -> Sel {
156156
Sel {
157-
ptr,
157+
ptr: ptr,
158158
}
159159
}
160160

0 commit comments

Comments
 (0)