Bus error on 32bit OSX, not 64bit

Jacob Carlborg doob at me.com
Tue Apr 16 00:07:32 PDT 2013


On 2013-04-15 19:56, John Colvin wrote:

> Casting a function that returns void to a function that returns
> something seems bound to cause trouble. While it may be allowed in C It
> seems a bit of a leap to assume that it would work properly in D.

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

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list