Re:Interoperating Between Objective-C and Rust
by dmitryskiba on Sunday November 30, 2014 @12:20AM
(#8676062)
Strictly speaking, [string UTF8String] is equivalent to '((const char <star>(<star>)(id, SEL))objc_msgSend)(string, selector)'. Since objc_msgSend is vararg function, it will promote it's arguments, so for example method taking float will be called with double. Casting to a proper function type works around that.
[ Parent
| on HN ]
Re:Interoperating Between Objective-C and Rust
by sasheldon on Sunday November 30, 2014 @01:04AM
(#8676135)
Oh good point, I hadn't considered vararg promotion!
Do you know if casting to a function also make objc_msgSend_stret and objc_msgSend_fpret unnecessary? I haven't yet worked with any methods that return structs or floating point values, so I haven't had to deal with them yet.
Edit: Oh, nope, my bad, objc_msgSend_stret is the one where you definitely have to cast: http://blog.lazerwalker.com/blog/2013/10/12/the-objective-c-...
Re:Interoperating Between Objective-C and Rust
by teacup50 on Sunday November 30, 2014 @12:36PM
(#8677382)
As you discovered, _stret/_fpret remain necessary.
objc_msgSend()'s type is not expressible in C; the only time it is correct to call objc_msgSend without a cast is when calling a method IMP with the literal vararg type of id (*method) (id self, SEL sel, ...);
In other words, essentially never.