-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from madsmtm/better-message
Improve message sending
- Loading branch information
Showing
17 changed files
with
324 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,40 @@ | ||
use core::mem; | ||
use objc2_sys::{objc_msg_lookup, objc_msg_lookup_super, objc_super}; | ||
|
||
use super::{Encode, Message, MessageArguments, MessageError}; | ||
use super::{conditional_try, Encode, MessageArguments, MessageError}; | ||
use crate::runtime::{Class, Object, Sel}; | ||
|
||
pub unsafe fn send_unverified<T, A, R>(obj: *const T, sel: Sel, args: A) -> Result<R, MessageError> | ||
pub unsafe fn send_unverified<A, R>( | ||
receiver: *mut Object, | ||
sel: Sel, | ||
args: A, | ||
) -> Result<R, MessageError> | ||
where | ||
T: Message, | ||
A: MessageArguments, | ||
R: Encode, | ||
{ | ||
if obj.is_null() { | ||
if receiver.is_null() { | ||
return mem::zeroed(); | ||
} | ||
|
||
let receiver = obj as *mut T as *mut Object; | ||
let msg_send_fn = objc_msg_lookup(receiver as *mut _, sel.as_ptr() as *const _); | ||
objc_try!({ A::invoke(msg_send_fn.expect("Null IMP"), receiver, sel, args) }) | ||
conditional_try(|| A::invoke(msg_send_fn.expect("Null IMP"), receiver, sel, args)) | ||
} | ||
|
||
pub unsafe fn send_super_unverified<T, A, R>( | ||
obj: *const T, | ||
pub unsafe fn send_super_unverified<A, R>( | ||
receiver: *mut Object, | ||
superclass: &Class, | ||
sel: Sel, | ||
args: A, | ||
) -> Result<R, MessageError> | ||
where | ||
T: Message, | ||
A: MessageArguments, | ||
R: Encode, | ||
{ | ||
let receiver = obj as *mut T as *mut Object; | ||
let sup = objc_super { | ||
receiver: receiver as *mut _, | ||
super_class: superclass as *const Class as *const _, | ||
}; | ||
let msg_send_fn = objc_msg_lookup_super(&sup, sel.as_ptr() as *const _); | ||
objc_try!({ A::invoke(msg_send_fn.expect("Null IMP"), receiver, sel, args) }) | ||
conditional_try(|| A::invoke(msg_send_fn.expect("Null IMP"), receiver, sel, args)) | ||
} |
Oops, something went wrong.