3 ms·
I don't see anything w.r.t. objc_msgSend() that obviously prevents it from being written in C, as opposed to objc_msg_lookup(). I mean, worst case scenario, co
by groovy2shoes 10y ago
I don't see anything w.r.t. objc_msgSend() that obviously prevents it from being written in C, as opposed to objc_msg_lookup(). I mean, worst case scenario, could it not just be:
id objc_msgSend(id object, id selector, ...) {
IMP tmp = objc_msg_lookup(object, selector);
return tmp(object, selector, ...);
}
(forgive me for any mistyping here, as I'm not an Obj-C programmer, and for the varargs shorthand, to keep things simple)? Especially given that GCC supports some extensions to C that could reduce the overhead a bit (tail-recursion elimination, for example), I don't see why such a function couldn't be implementable in (GCC) C.
Would you be willing to enlighten me?
- DHowett 10y agoIt's the ... that's the hard part; I've explained a little more here: https://news.ycombinator.com/item?id=13046391 https://news.ycombinator.com/item?id=13046391.
- ksherlock 10y agoConceptually, it is: IMP tmp = objc_msg_lookup(object, selector); goto *tmp; but C can't handle that (and even with gcc computed gotos you need to preserve any argument registers and not screw up the stack). objc_msgSend has a variable number of arguments and no way to determine how many there are.