|
| 1 | +use core::hint; |
1 | 2 | use core::mem; |
2 | 3 |
|
3 | 4 | use super::conditional_try; |
4 | 5 | use crate::ffi; |
5 | | -use crate::runtime::{Class, Object, Sel}; |
| 6 | +use crate::runtime::{Class, Imp, Object, Sel}; |
6 | 7 | use crate::{Encode, MessageArguments}; |
7 | 8 |
|
| 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 | + if cfg!(debug_assertions) { |
| 15 | + unreachable!("got unexpected null IMP") |
| 16 | + } else { |
| 17 | + // This shouldn't ever happen |
| 18 | + unsafe { hint::unreachable_unchecked() } |
| 19 | + } |
| 20 | + } |
| 21 | + } |
| 22 | +} |
| 23 | + |
8 | 24 | #[track_caller] |
9 | 25 | pub(crate) unsafe fn send_unverified<A, R>(receiver: *mut Object, sel: Sel, args: A) -> R |
10 | 26 | where |
|
22 | 38 | } |
23 | 39 |
|
24 | 40 | 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"); |
| 41 | + let msg_send_fn = unwrap_msg_send_fn(msg_send_fn); |
26 | 42 | unsafe { conditional_try(|| A::__invoke(msg_send_fn, receiver, sel, args)) } |
27 | 43 | } |
28 | 44 |
|
|
48 | 64 | super_class: superclass.cast(), |
49 | 65 | }; |
50 | 66 | 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"); |
| 67 | + let msg_send_fn = unwrap_msg_send_fn(msg_send_fn); |
52 | 68 | unsafe { conditional_try(|| A::__invoke(msg_send_fn, receiver, sel, args)) } |
53 | 69 | } |
0 commit comments