Skip to content

Commit 3d9615a

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

7 files changed

Lines changed: 82 additions & 585 deletions

File tree

objc2/src/message/gnustep.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
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+
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+
824
#[track_caller]
925
pub(crate) unsafe fn send_unverified<A, R>(receiver: *mut Object, sel: Sel, args: A) -> R
1026
where
@@ -22,7 +38,7 @@ where
2238
}
2339

2440
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);
2642
unsafe { conditional_try(|| A::__invoke(msg_send_fn, receiver, sel, args)) }
2743
}
2844

@@ -48,6 +64,6 @@ where
4864
super_class: superclass.cast(),
4965
};
5066
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);
5268
unsafe { conditional_try(|| A::__invoke(msg_send_fn, receiver, sel, args)) }
5369
}

0 commit comments

Comments
 (0)