Skip to content

Commit 3ceff5a

Browse files
committed
Support the rest of the super selectors [WIP]
1 parent 8106a8d commit 3ceff5a

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

objc2/src/__macro_helpers.rs

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,23 @@ impl<T: ?Sized + Message, O: Ownership> MsgSendId<&'_ Class, Id<T, O>>
7575
}
7676
}
7777

78+
// Super: `new`, TODO: Can this ever happen?
79+
impl<T: ?Sized + Message, O: Ownership> MsgSendSuperId<&'_ Class, Id<T, O>>
80+
for RetainSemantics<true, false, false, false>
81+
{
82+
#[inline(always)]
83+
unsafe fn send_super_message_id<A: MessageArguments>(
84+
obj: &Class,
85+
superclass: &Class,
86+
sel: Sel,
87+
args: A,
88+
) -> Result<Option<Id<T, O>>, MessageError> {
89+
unsafe {
90+
MessageReceiver::send_super_message(obj, superclass, sel, args).map(|r| Id::new(r))
91+
}
92+
}
93+
}
94+
7895
// `alloc`, should mark the return value as "allocated, not initialized" somehow
7996
impl<T: ?Sized + Message, O: Ownership> MsgSendId<&'_ Class, Id<T, O>>
8097
for RetainSemantics<false, true, false, false>
@@ -89,6 +106,23 @@ impl<T: ?Sized + Message, O: Ownership> MsgSendId<&'_ Class, Id<T, O>>
89106
}
90107
}
91108

109+
// Super: `alloc`, TODO: Can this ever happen?
110+
impl<T: ?Sized + Message, O: Ownership> MsgSendSuperId<&'_ Class, Id<T, O>>
111+
for RetainSemantics<false, true, false, false>
112+
{
113+
#[inline(always)]
114+
unsafe fn send_super_message_id<A: MessageArguments>(
115+
cls: &Class,
116+
superclass: &Class,
117+
sel: Sel,
118+
args: A,
119+
) -> Result<Option<Id<T, O>>, MessageError> {
120+
unsafe {
121+
MessageReceiver::send_super_message(cls, superclass, sel, args).map(|r| Id::new(r))
122+
}
123+
}
124+
}
125+
92126
// `init`, should mark the input value as "allocated, not initialized" somehow
93127
impl<T: ?Sized + Message, O: Ownership> MsgSendId<Option<Id<T, O>>, Id<T, O>>
94128
for RetainSemantics<false, false, true, false>
@@ -145,6 +179,23 @@ impl<T: MessageReceiver, U: ?Sized + Message, O: Ownership> MsgSendId<T, Id<U, O
145179
}
146180
}
147181

182+
// Super: `copy` and `mutableCopy`. TODO: Will this ever happen?
183+
impl<T: MessageReceiver, U: ?Sized + Message, O: Ownership> MsgSendSuperId<T, Id<U, O>>
184+
for RetainSemantics<false, false, false, true>
185+
{
186+
#[inline(always)]
187+
unsafe fn send_super_message_id<A: MessageArguments>(
188+
obj: T,
189+
superclass: &Class,
190+
sel: Sel,
191+
args: A,
192+
) -> Result<Option<Id<U, O>>, MessageError> {
193+
unsafe {
194+
MessageReceiver::send_super_message(obj, superclass, sel, args).map(|r| Id::new(r))
195+
}
196+
}
197+
}
198+
148199
// All other selectors
149200
impl<T: MessageReceiver, U: Message, O: Ownership> MsgSendId<T, Id<U, O>>
150201
for RetainSemantics<false, false, false, false>
@@ -334,17 +385,25 @@ mod tests {
334385
}
335386

336387
#[test]
388+
#[ignore = "TMP"]
337389
fn test_msg_send_super_id() {
338390
// We send the messages to the class itself instead of it's actual
339391
// superclass, just to verify that the macro works.
340392
// TODO: Better solution!
341393
let cls = class!(NSObject);
342394

343-
let obj = unsafe { msg_send_id![cls, alloc] };
395+
let _obj: Id<Object, Owned> = unsafe { msg_send_id![super(cls, cls), new].unwrap() };
396+
397+
let obj = unsafe { msg_send_id![super(cls, cls), alloc] };
344398

345399
let obj = obj.unwrap(); // Required on super
346400
let obj: Id<Object, Owned> = unsafe { msg_send_id![super(obj, cls), init].unwrap() };
347401

402+
let _copy: Id<Object, Shared> = unsafe { msg_send_id![super(&obj, cls), copy].unwrap() };
403+
404+
let _mutable_copy: Id<Object, Shared> =
405+
unsafe { msg_send_id![super(&obj, cls), mutableCopy].unwrap() };
406+
348407
let _desc: Option<Id<Object, Shared>> =
349408
unsafe { msg_send_id![super(&obj, cls), description] };
350409
}

0 commit comments

Comments
 (0)