Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## Unreleased

### Changed

* `msg_send!` no longer dereferences it's first argument, which would invoke
undefined behaviour when called with a null pointer. So if you were passing
`objc_id::Id` or similar directly, you now have to manually dereference it
like this: `msg_send![&*obj, ...]`.

## 0.2.7

### Fixed
Expand Down
4 changes: 2 additions & 2 deletions src/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,8 @@ mod tests {
// Registering the custom class is in test_utils
let obj = test_utils::custom_object();
unsafe {
let _: () = msg_send![obj, setFoo:13u32];
let result: u32 = msg_send![obj, foo];
let _: () = msg_send![&*obj, setFoo:13u32];
let result: u32 = msg_send![&*obj, foo];
assert!(result == 13);
}
}
Expand Down
13 changes: 7 additions & 6 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ macro_rules! sel {
/**
Sends a message to an object.

The first argument can be any type that dereferences to a type that implements
`Message`, like a reference, pointer, or an `Id`.
The first argument can be any reference or pointer to a type that implements
[`Message`].

The syntax is similar to the message syntax in Objective-C.
Variadic arguments are not currently supported.

Expand All @@ -81,7 +82,7 @@ macro_rules! msg_send {
(super($obj:expr, $superclass:expr), $name:ident) => ({
let sel = $crate::sel!($name);
let result;
match $crate::__send_super_message(&*$obj, $superclass, sel, ()) {
match $crate::__send_super_message($obj, $superclass, sel, ()) {
Err(s) => panic!("{}", s),
Ok(r) => result = r,
}
Expand All @@ -90,7 +91,7 @@ macro_rules! msg_send {
(super($obj:expr, $superclass:expr), $($name:ident : $arg:expr)+) => ({
let sel = $crate::sel!($($name:)+);
let result;
match $crate::__send_super_message(&*$obj, $superclass, sel, ($($arg,)*)) {
match $crate::__send_super_message($obj, $superclass, sel, ($($arg,)*)) {
Err(s) => panic!("{}", s),
Ok(r) => result = r,
}
Expand All @@ -99,7 +100,7 @@ macro_rules! msg_send {
($obj:expr, $name:ident) => ({
let sel = $crate::sel!($name);
let result;
match $crate::__send_message(&*$obj, sel, ()) {
match $crate::__send_message($obj, sel, ()) {
Err(s) => panic!("{}", s),
Ok(r) => result = r,
}
Expand All @@ -108,7 +109,7 @@ macro_rules! msg_send {
($obj:expr, $($name:ident : $arg:expr)+) => ({
let sel = $crate::sel!($($name:)+);
let result;
match $crate::__send_message(&*$obj, sel, ($($arg,)*)) {
match $crate::__send_message($obj, sel, ($($arg,)*)) {
Err(s) => panic!("{}", s),
Ok(r) => result = r,
}
Expand Down
12 changes: 6 additions & 6 deletions src/message/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ mod tests {
fn test_send_message() {
let obj = test_utils::custom_object();
let result: u32 = unsafe {
let _: () = msg_send![obj, setFoo:4u32];
msg_send![obj, foo]
let _: () = msg_send![&*obj, setFoo:4u32];
msg_send![&*obj, foo]
};
assert!(result == 4);
}
Expand All @@ -246,7 +246,7 @@ mod tests {
fn test_send_message_stret() {
let obj = test_utils::custom_object();
let result: test_utils::CustomStruct = unsafe {
msg_send![obj, customStruct]
msg_send![&*obj, customStruct]
};
let expected = test_utils::CustomStruct { a: 1, b:2, c: 3, d: 4 };
assert!(result == expected);
Expand Down Expand Up @@ -277,12 +277,12 @@ mod tests {
let obj = test_utils::custom_subclass_object();
let superclass = test_utils::custom_class();
unsafe {
let _: () = msg_send![obj, setFoo:4u32];
let foo: u32 = msg_send![super(obj, superclass), foo];
let _: () = msg_send![&*obj, setFoo:4u32];
let foo: u32 = msg_send![super(&*obj, superclass), foo];
assert!(foo == 4);

// The subclass is overriden to return foo + 2
let foo: u32 = msg_send![obj, foo];
let foo: u32 = msg_send![&*obj, foo];
assert!(foo == 6);
}
}
Expand Down