Skip to content

Commit

Permalink
WIP: Add AllocInit thing
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Aug 15, 2022
1 parent b229e59 commit 8d9d410
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions objc2/src/__macro_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ pub struct RetainSemantics<

type New = RetainSemantics<true, false, false, false>;
type Alloc = RetainSemantics<false, true, false, false>;
type AllocInit = RetainSemantics<true, true, false, false>;
type Init = RetainSemantics<false, false, true, false>;
type CopyOrMutCopy = RetainSemantics<false, false, false, true>;
type Other = RetainSemantics<false, false, false, false>;
Expand All @@ -90,7 +91,7 @@ pub trait MsgSendId<T, U: ?Sized, O: Ownership> {
) -> R;
}

impl<T: ?Sized + Message, O: Ownership> MsgSendId<&'_ Class, T, O> for New {
impl<T: ?Sized + Message, O: Ownership> MsgSendId<&Class, T, O> for New {
#[inline]
#[track_caller]
unsafe fn send_message_id<A: MessageArguments, R: MaybeUnwrap<T, O>>(
Expand All @@ -106,7 +107,7 @@ impl<T: ?Sized + Message, O: Ownership> MsgSendId<&'_ Class, T, O> for New {
}
}

impl<T: ?Sized + Message, O: Ownership> MsgSendId<&'_ Class, Allocated<T>, O> for Alloc {
impl<T: ?Sized + Message, O: Ownership> MsgSendId<&Class, Allocated<T>, O> for Alloc {
#[inline]
#[track_caller]
unsafe fn send_message_id<A: MessageArguments, R: MaybeUnwrap<Allocated<T>, O>>(
Expand All @@ -122,6 +123,20 @@ impl<T: ?Sized + Message, O: Ownership> MsgSendId<&'_ Class, Allocated<T>, O> fo
}
}

impl<T: ?Sized + Message, O: Ownership> MsgSendId<&Class, T, O> for AllocInit {
#[inline]
#[track_caller]
unsafe fn send_message_id<A: MessageArguments, R: MaybeUnwrap<T, O>>(
cls: &Class,
sel: Sel,
args: A,
) -> R {
let obj: Option<Id<Allocated<T>, O>> = unsafe { Alloc::send_message_id(cls, alloc(), ()) };
// TODO: Specific error handling for `AllocInit`
unsafe { Init::send_message_id(obj, sel, args) }
}
}

impl<T: ?Sized + Message, O: Ownership> MsgSendId<Option<Id<Allocated<T>, O>>, T, O> for Init {
#[inline]
#[track_caller]
Expand Down

0 comments on commit 8d9d410

Please sign in to comment.