Re: Which flavor of objc_msgSend for NSSize return
Re: Which flavor of objc_msgSend for NSSize return
- Subject: Re: Which flavor of objc_msgSend for NSSize return
- From: Greg Parker <email@hidden>
- Date: Fri, 11 May 2007 20:40:21 -0700
Sherm Pendley wrote:
When I call objc_msgSend_stret() in CamelBones, I call it as
documented in the runtime reference, returning the struct by
reference in the first argument. It's much simpler, with no need for
the typecast.
Never call any objc_msgSend function without casting to an appropriate
function pointer type.
Calls that may misbehave include structure return on i386, and scalar
promotion on all architectures (which will only get worse in 64-bit).
Yes, I'm aware of the note regarding typecasting in objc-runtime.h;
IMHO, the runtime reference docs are the official last word, and
take precedence over a cryptic comment buried in a header file. That
comment has been there for at least six years, to my knowledge, and
all the while the runtime reference has made no mention of this
function being unreliable for future use.
The `objc_msgSend_stret(&result, receiver, selector, ...)` form does
not work on i386. The problem is that the i386 ABI for a function that
returns a large struct does not match the i386 ABI for a function that
takes a struct address as the first parameter. In the former case, the
callee pops the struct address and the caller pops the other
arguments. In the latter case, the caller pops all arguments,
including the struct address. Depending on the optimization level and
the code around the call site, use of this form will crash after
disturbing the caller's stack pointer.
Trivia: The comment on objc_msgSend_stret() dates from Panther. It was
added because the problem was discovered in the then-secret Intel port
of Mac OS X early during Panther development. Steve wasn't kidding
when he said "Mac OS X has been leading a secret double life the past
five years".
--
Greg Parker email@hidden Runtime Wrangler
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden