Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Returning values from objc_msgSend etc



On Mar 31, 2008, at 8:34 AM, Sherm Pendley wrote:
On Sat, Mar 1, 2008 at 9:00 AM, Greg Parker <email@hidden> wrote:
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.)

I don't think libffi does any type promotion.

Indeed not - the sample below prints different results when run on PPC (including Rosetta) and i386. On PPC, only the promoted version returns the correct result. On Intel, both of them do. The question then, becomes - should libffi be handling this difference transparently?

ffi_call(3) says:
"rvalue must point to storage that is sizeof(long) or larger. For smaller return value sizes, the ffi_arg or ffi_sarg integral type must be used to hold the return value."



    char returnCharValue;

ffi_call(&cif_nopromote,
(void(*)(void))getCharFunction,
&returnCharValue,
NULL
);
printf("Return value from cif_nopromote is %d.\n", returnCharValue);

...which means this isn't allowed. In fact, it's probably smashing memory on your stack.



-- 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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >Re: Returning values from objc_msgSend etc (From: "Sherm Pendley" <email@hidden>)
 >Re: Returning values from objc_msgSend etc (From: Greg Parker <email@hidden>)
 >Re: Returning values from objc_msgSend etc (From: "Sherm Pendley" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.