Skip to content

Commit c54c300

Browse files
committed
Improve GNUStep message sending a bit
1 parent 8ad87ad commit c54c300

File tree

7 files changed

+81
-585
lines changed

7 files changed

+81
-585
lines changed

objc2/src/message/gnustep.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
1+
use core::hint;
12
use core::mem;
23

34
use super::conditional_try;
45
use crate::ffi;
5-
use crate::runtime::{Class, Object, Sel};
6+
use crate::runtime::{Class, Imp, Object, Sel};
67
use crate::{Encode, MessageArguments};
78

9+
#[inline]
10+
fn unwrap_msg_send_fn(msg_send_fn: Option<Imp>) -> Imp {
11+
match msg_send_fn {
12+
Some(msg_send_fn) => msg_send_fn,
13+
None => {
14+
// SAFETY: This will never be NULL, even if the selector is not
15+
// found a callable function pointer will still be returned!
16+
//
17+
// `clang` doesn't insert a NULL check here either.
18+
unsafe { hint::unreachable_unchecked() }
19+
}
20+
}
21+
}
22+
823
#[track_caller]
924
pub(crate) unsafe fn send_unverified<A, R>(receiver: *mut Object, sel: Sel, args: A) -> R
1025
where
@@ -22,7 +37,7 @@ where
2237
}
2338

2439
let msg_send_fn = unsafe { ffi::objc_msg_lookup(receiver.cast(), sel.as_ptr()) };
25-
let msg_send_fn = msg_send_fn.expect("Null IMP");
40+
let msg_send_fn = unwrap_msg_send_fn(msg_send_fn);
2641
unsafe { conditional_try(|| A::__invoke(msg_send_fn, receiver, sel, args)) }
2742
}
2843

@@ -48,6 +63,6 @@ where
4863
super_class: superclass.cast(),
4964
};
5065
let msg_send_fn = unsafe { ffi::objc_msg_lookup_super(&sup, sel.as_ptr()) };
51-
let msg_send_fn = msg_send_fn.expect("Null IMP");
66+
let msg_send_fn = unwrap_msg_send_fn(msg_send_fn);
5267
unsafe { conditional_try(|| A::__invoke(msg_send_fn, receiver, sel, args)) }
5368
}

0 commit comments

Comments
 (0)