Skip to content

Commit abf49eb

Browse files
committed
Support the rest of the super selectors [WIP]
1 parent af5d39b commit abf49eb

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
@@ -49,6 +49,23 @@ impl<T: ?Sized + Message, O: Ownership> MsgSendId<&'_ Class, Id<T, O>>
4949
}
5050
}
5151

52+
// Super: `new`, TODO: Can this ever happen?
53+
impl<T: ?Sized + Message, O: Ownership> MsgSendSuperId<&'_ Class, Id<T, O>>
54+
for Assert<true, false, false, false>
55+
{
56+
#[inline(always)]
57+
unsafe fn send_super_message_id<A: MessageArguments>(
58+
obj: &Class,
59+
superclass: &Class,
60+
sel: Sel,
61+
args: A,
62+
) -> Result<Option<Id<T, O>>, MessageError> {
63+
unsafe {
64+
MessageReceiver::send_super_message(obj, superclass, sel, args).map(|r| Id::new(r))
65+
}
66+
}
67+
}
68+
5269
// `alloc`, should mark the return value as "allocated, not initialized" somehow
5370
impl<T: ?Sized + Message, O: Ownership> MsgSendId<&'_ Class, Id<T, O>>
5471
for Assert<false, true, false, false>
@@ -63,6 +80,23 @@ impl<T: ?Sized + Message, O: Ownership> MsgSendId<&'_ Class, Id<T, O>>
6380
}
6481
}
6582

83+
// Super: `alloc`, TODO: Can this ever happen?
84+
impl<T: ?Sized + Message, O: Ownership> MsgSendSuperId<&'_ Class, Id<T, O>>
85+
for Assert<false, true, false, false>
86+
{
87+
#[inline(always)]
88+
unsafe fn send_super_message_id<A: MessageArguments>(
89+
cls: &Class,
90+
superclass: &Class,
91+
sel: Sel,
92+
args: A,
93+
) -> Result<Option<Id<T, O>>, MessageError> {
94+
unsafe {
95+
MessageReceiver::send_super_message(cls, superclass, sel, args).map(|r| Id::new(r))
96+
}
97+
}
98+
}
99+
66100
// `init`, should mark the input value as "allocated, not initialized" somehow
67101
//
68102
// The generic bound allows `init` to take both `Option<Id>` and `Id`.
@@ -121,6 +155,23 @@ impl<T: MessageReceiver, U: ?Sized + Message, O: Ownership> MsgSendId<T, Id<U, O
121155
}
122156
}
123157

158+
// Super: `copy` and `mutableCopy`. TODO: Will this ever happen?
159+
impl<T: MessageReceiver, U: ?Sized + Message, O: Ownership> MsgSendSuperId<T, Id<U, O>>
160+
for Assert<false, false, false, true>
161+
{
162+
#[inline(always)]
163+
unsafe fn send_super_message_id<A: MessageArguments>(
164+
obj: T,
165+
superclass: &Class,
166+
sel: Sel,
167+
args: A,
168+
) -> Result<Option<Id<U, O>>, MessageError> {
169+
unsafe {
170+
MessageReceiver::send_super_message(obj, superclass, sel, args).map(|r| Id::new(r))
171+
}
172+
}
173+
}
174+
124175
// All other selectors
125176
impl<T: MessageReceiver, U: Message, O: Ownership> MsgSendId<T, Id<U, O>>
126177
for Assert<false, false, false, false>
@@ -260,17 +311,25 @@ mod tests {
260311
}
261312

262313
#[test]
314+
#[ignore = "TMP"]
263315
fn test_msg_send_super_id() {
264316
// We send the messages to the class itself instead of it's actual
265317
// superclass, just to verify that the macro works.
266318
// TODO: Better solution!
267319
let cls = class!(NSObject);
268320

269-
let obj = unsafe { msg_send_id![cls, alloc] };
321+
let _obj: Id<Object, Owned> = unsafe { msg_send_id![super(cls, cls), new].unwrap() };
322+
323+
let obj = unsafe { msg_send_id![super(cls, cls), alloc] };
270324

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

328+
let _copy: Id<Object, Shared> = unsafe { msg_send_id![super(&obj, cls), copy].unwrap() };
329+
330+
let _mutable_copy: Id<Object, Shared> =
331+
unsafe { msg_send_id![super(&obj, cls), mutableCopy].unwrap() };
332+
274333
let _desc: Option<Id<Object, Shared>> =
275334
unsafe { msg_send_id![super(&obj, cls), description] };
276335
}

0 commit comments

Comments
 (0)