Skip to content

Commit

Permalink
Remove old dispatch prototypes to avoid a transmute.
Browse files Browse the repository at this point in the history
This fixes the warning appearing from rust-lang/rust#31710.

The objc_msgSend functions aren't intended to be used directly, so since
OSX 10.8 they are defined empty like this as long as you don't define
OBJC_OLD_DISPATCH_PROTOTYPES.
  • Loading branch information
SSheldon committed Mar 20, 2016
1 parent 97463bf commit b09ad20
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 35 deletions.
16 changes: 8 additions & 8 deletions src/message/arm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,37 @@ pub fn msg_send_fn<R: Any>(obj: *mut Object, _: Sel) -> (Imp, *mut Object) {
// http://infocenter.arm.com/help/topic/com.arm.doc.ihi0042e/IHI0042E_aapcs.pdf

extern {
fn objc_msgSend(obj: *mut Object, op: Sel, ...) -> *mut Object;
fn objc_msgSend_stret(obj: *mut Object, op: Sel, ...);
fn objc_msgSend();
fn objc_msgSend_stret();
}

let type_id = TypeId::of::<R>();
let msg_fn = if mem::size_of::<R>() <= 4 ||
type_id == TypeId::of::<i64>() ||
type_id == TypeId::of::<u64>() ||
type_id == TypeId::of::<f64>() {
unsafe { mem::transmute(objc_msgSend) }
objc_msgSend
} else {
unsafe { mem::transmute(objc_msgSend_stret) }
objc_msgSend_stret
};

(msg_fn, obj)
}

pub fn msg_send_super_fn<R: Any>(sup: &Super, _: Sel) -> (Imp, *mut Object) {
extern {
fn objc_msgSendSuper(sup: *const Super, op: Sel, ...) -> *mut Object;
fn objc_msgSendSuper_stret(sup: *const Super, op: Sel, ... );
fn objc_msgSendSuper();
fn objc_msgSendSuper_stret();
}

let type_id = TypeId::of::<R>();
let msg_fn = if mem::size_of::<R>() <= 4 ||
type_id == TypeId::of::<i64>() ||
type_id == TypeId::of::<u64>() ||
type_id == TypeId::of::<f64>() {
unsafe { mem::transmute(objc_msgSendSuper) }
objc_msgSendSuper
} else {
unsafe { mem::transmute(objc_msgSendSuper_stret) }
objc_msgSendSuper_stret
};

(msg_fn, sup as *const Super as *mut Object)
Expand Down
12 changes: 4 additions & 8 deletions src/message/arm64.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::mem;

use runtime::{Object, Imp, Sel};
use super::Super;

Expand All @@ -8,18 +6,16 @@ pub fn msg_send_fn<R>(obj: *mut Object, _: Sel) -> (Imp, *mut Object) {
// https://twitter.com/gparker/status/378079715824660480

extern {
fn objc_msgSend(obj: *mut Object, op: Sel, ...) -> *mut Object;
fn objc_msgSend();
}

let msg_fn = unsafe { mem::transmute(objc_msgSend) };
(msg_fn, obj)
(objc_msgSend, obj)
}

pub fn msg_send_super_fn<R>(sup: &Super, _: Sel) -> (Imp, *mut Object) {
extern {
fn objc_msgSendSuper(sup: *const Super, op: Sel, ...) -> *mut Object;
fn objc_msgSendSuper();
}

let msg_fn = unsafe { mem::transmute(objc_msgSendSuper) };
(msg_fn, sup as *const Super as *mut Object)
(objc_msgSendSuper, sup as *const Super as *mut Object)
}
20 changes: 10 additions & 10 deletions src/message/x86.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,36 @@ pub fn msg_send_fn<R: Any>(obj: *mut Object, _: Sel) -> (Imp, *mut Object) {
// https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/LowLevelABI/130-IA-32_Function_Calling_Conventions/IA32.html

extern {
fn objc_msgSend(obj: *mut Object, op: Sel, ...) -> *mut Object;
fn objc_msgSend_fpret(obj: *mut Object, op: Sel, ...) -> f64;
fn objc_msgSend_stret(obj: *mut Object, op: Sel, ...);
fn objc_msgSend();
fn objc_msgSend_fpret();
fn objc_msgSend_stret();
}

let type_id = TypeId::of::<R>();
let size = mem::size_of::<R>();
let msg_fn = if type_id == TypeId::of::<f32>() ||
type_id == TypeId::of::<f64>() {
unsafe { mem::transmute(objc_msgSend_fpret) }
objc_msgSend_fpret
} else if size == 0 || size == 1 || size == 2 || size == 4 || size == 8 {
unsafe { mem::transmute(objc_msgSend) }
objc_msgSend
} else {
unsafe { mem::transmute(objc_msgSend_stret) }
objc_msgSend_stret
};

(msg_fn, obj)
}

pub fn msg_send_super_fn<R: Any>(sup: &Super, _: Sel) -> (Imp, *mut Object) {
extern {
fn objc_msgSendSuper(sup: *const Super, op: Sel, ...) -> *mut Object;
fn objc_msgSendSuper_stret(sup: *const Super, op: Sel, ... );
fn objc_msgSendSuper();
fn objc_msgSendSuper_stret();
}

let size = mem::size_of::<R>();
let msg_fn = if size == 0 || size == 1 || size == 2 || size == 4 || size == 8 {
unsafe { mem::transmute(objc_msgSendSuper) }
objc_msgSendSuper
} else {
unsafe { mem::transmute(objc_msgSendSuper_stret) }
objc_msgSendSuper_stret
};

(msg_fn, sup as *const Super as *mut Object)
Expand Down
16 changes: 8 additions & 8 deletions src/message/x86_64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@ pub fn msg_send_fn<R>(obj: *mut Object, _: Sel) -> (Imp, *mut Object) {
// http://people.freebsd.org/~obrien/amd64-elf-abi.pdf

extern {
fn objc_msgSend(obj: *mut Object, op: Sel, ...) -> *mut Object;
fn objc_msgSend_stret(obj: *mut Object, op: Sel, ...);
fn objc_msgSend();
fn objc_msgSend_stret();
}

let msg_fn = if mem::size_of::<R>() <= 16 {
unsafe { mem::transmute(objc_msgSend) }
objc_msgSend
} else {
unsafe { mem::transmute(objc_msgSend_stret) }
objc_msgSend_stret
};

(msg_fn, obj)
}

pub fn msg_send_super_fn<R>(sup: &Super, _: Sel) -> (Imp, *mut Object) {
extern {
fn objc_msgSendSuper(sup: *const Super, op: Sel, ...) -> *mut Object;
fn objc_msgSendSuper_stret(sup: *const Super, op: Sel, ... );
fn objc_msgSendSuper();
fn objc_msgSendSuper_stret();
}

let msg_fn = if mem::size_of::<R>() <= 16 {
unsafe { mem::transmute(objc_msgSendSuper) }
objc_msgSendSuper
} else {
unsafe { mem::transmute(objc_msgSendSuper_stret) }
objc_msgSendSuper_stret
};

(msg_fn, sup as *const Super as *mut Object)
Expand Down
2 changes: 1 addition & 1 deletion src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub struct Object {
}

/// A pointer to the start of a method implementation.
pub type Imp = unsafe extern fn(*mut Object, Sel, ...) -> *mut Object;
pub type Imp = unsafe extern fn();

#[link(name = "objc", kind = "dylib")]
extern {
Expand Down

0 comments on commit b09ad20

Please sign in to comment.