[Issue 9931] Bus error interfacing with C function returning structs with floats

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Apr 16 00:10:36 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=9931



--- Comment #5 from Jacob Carlborg <doob at me.com> 2013-04-16 00:10:33 PDT ---
Here's one of my post from the discussion of this issue at the newsgroup:

http://forum.dlang.org/thread/kkefk8$2663$1@digitalmars.com

I've done some investigation about how the "objc_msgSend" family of functions
work, including "objc_msgSend_stret". For those who don't know they're are part
of the Objective-C runtime used for calling Objective-C methods.

These functions are _not_ regular C functions, they're completely implemented
using assembly. What they basically do is looking up the Objective-C method to
call and just calls it (some caching is involved as well).

What's special about this is that it won't mess with any resister or stack used
for passing function arguments or sending back return values. What happens when
it has found the correct Objective-C method is that it will just jump to the
function. All registers and the stack are already correct, from the call to the
objc_msgSend itself. I assume that is way the objc_msgSend method need to be
cast to the correct signature before calling it. We don't want to use the ABI
for variadic functions (as declared by objc_msgSend), we want the ABI used for
the target function, that is, the Objective-C method.

An Objective-C method is implement like a regular C function, following the ABI
of the platform. It has to take at least these two parameters:

void foo (id self, SEL _cmd);

"self" would be the object we're calling the method on. "_cmd" is the selector
(method) being called.

Then what's objc_msgSend_stret used for. The objc_msgSend_stret function is
used for returning structs that are too large to fit in the register. This is
completely dependent on the platform ABI.

I don't know if this helps.

Some info about how objc_msgSend works:

http://www.friday.com/bbum/2009/12/18/objc_msgsend-part-1-the-road-map/

Some info about why objc_msgSend_stret exists:

http://www.sealiesoftware.com/blog/archive/2008/10/30/objc_explain_objc_msgSend_stret.html

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list