Skip to content

Commit

Permalink
Fix Id's UnwindSafe impl for upcoming changes to the compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Feb 28, 2022
1 parent a10fec8 commit f90605b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
13 changes: 2 additions & 11 deletions objc2-foundation/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,10 @@ unsafe impl<T: Send> Send for NSArray<T, Owned> {}

object! {
// TODO: Ensure that this deref to NSArray is safe!
unsafe pub struct NSMutableArray<T, O: Ownership>: NSArray<T, O> {
item: PhantomData<Id<T, O>>,
}
// This "inherits" NSArray, and has the same `Send`/`Sync` impls as that.
unsafe pub struct NSMutableArray<T, O: Ownership>: NSArray<T, O> {}
}

// SAFETY: Same as NSArray.
//
// TODO: Properly verify this
unsafe impl<T: Sync + Send> Sync for NSMutableArray<T, Shared> {}
unsafe impl<T: Sync + Send> Send for NSMutableArray<T, Shared> {}
unsafe impl<T: Sync> Sync for NSMutableArray<T, Owned> {}
unsafe impl<T: Send> Send for NSMutableArray<T, Owned> {}

unsafe fn from_refs<T: Message + ?Sized>(cls: &Class, refs: &[&T]) -> NonNull<Object> {
let obj: *mut Object = unsafe { msg_send![cls, alloc] };
let obj: *mut Object = unsafe {
Expand Down
8 changes: 7 additions & 1 deletion objc2/src/rc/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use core::fmt;
use core::marker::PhantomData;
use core::mem::ManuallyDrop;
use core::ops::{Deref, DerefMut};
use core::panic::{RefUnwindSafe, UnwindSafe};
use core::ptr::NonNull;
use std::panic::{RefUnwindSafe, UnwindSafe};

use super::AutoreleasePool;
use super::{Owned, Ownership, Shared};
Expand Down Expand Up @@ -117,6 +117,11 @@ pub struct Id<T: ?Sized, O: Ownership> {
item: PhantomData<T>,
/// To prevent warnings about unused type parameters.
own: PhantomData<O>,
/// Marks the type as !UnwindSafe. Later on we'll re-enable this.
///
/// See <https://github.com/rust-lang/rust/issues/93367> for why this is
/// required.
notunwindsafe: PhantomData<&'static mut ()>,
}

impl<T: Message + ?Sized, O: Ownership> Id<T, O> {
Expand Down Expand Up @@ -171,6 +176,7 @@ impl<T: Message + ?Sized, O: Ownership> Id<T, O> {
ptr,
item: PhantomData,
own: PhantomData,
notunwindsafe: PhantomData,
}
}

Expand Down

0 comments on commit f90605b

Please sign in to comment.