Re: Returning values from objc_msgSend etc
Re: Returning values from objc_msgSend etc
- Subject: Re: Returning values from objc_msgSend etc
- From: Greg Parker <email@hidden>
- Date: Sat, 1 Mar 2008 05:00:07 -0800
On Mar 1, 2008, at 1:22 AM, Sherm Pendley wrote:
On Fri, Feb 29, 2008 at 2:46 PM, Greg Parker <email@hidden>
wrote:
When in doubt, write Objective-C code that returns the type you want,
compile it, and use whichever function the generated assembly code
chose.
What's your advice about what to do when the choice must be made at
runtime? I'm using libffi. Does it know about the implicit first
argument for struct returns? That is, do I take the moral equivalent
of the suggestion in objc/objc-runtime.h, call objc_msgSend_stret()
using a struct return type and leave the argument shuffling for ffi
to handle? Or, do I call it as declared, with a void return type,
setting up the return pointer argument myself and disregarding the
comment in the header file?
libffi is smart enough to know about all of the ABI rules. If your
ffi_types correctly describe the method's parameters, then libffi will
marshal them properly. (If it doesn't, then that's a libffi bug.)
However, you still need to choose the correct objc_msgSend variant.
libffi will correctly set up the implicit struct return argument or
not as required, but there's no way for you to know whether it's going
to do that or not. So if your C structure is returned in registers,
then libffi will handle it correctly but you'll crash if you use
objc_msgSend_stret instead of objc_msgSend.
The right way to fix this is to add new API in libobjc: given an
ffi_type, return the correct objc_msgSend function pointer for that
return type. I filed the feature request for that today. Until then
you'll still need to handle that choice yourself. All of the required
code is in libffi somewhere, but there's no way for you to call it
directly. libffi is open source, so you could try digging through the
implementation and copying the code you want into your program.
Also, do you know what, if any, type promotions are relevant, and
whether libffi automatically handles them?
I don't think libffi does any type promotion.
--
Greg Parker email@hidden Runtime Wrangler
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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