Re: objc_msgSend_stret Intel crashes
Re: objc_msgSend_stret Intel crashes
- Subject: Re: objc_msgSend_stret Intel crashes
- From: Greg Parker <email@hidden>
- Date: 25 Jun 2006 00:06:50 -0000
- Organization: Apple Computer, Inc.
Tim Conkling wrote:
> I have some calls to -[NSWindow frame] that originally looked like this:
>
> objc_msgSend_stret( &origWindowFrame, window,
> NSSelectorFromString(CFSTR("frame"))
> );
>
> I changed them to this:
>
> origWindowFrame = (*(NSRect(*)(void*, void*, ...))
> objc_msgSend_stret)(window, NSSelectorFromString(CFSTR("frame")));
>
> And eliminated crashes associated with those calls to objc_msgSend_stret.
This is correct. You should always cast objc_msgSend() and its variants
to an appropriate function pointer type, even on PPC.
> However, there are other calls to the function that are still failing. For
> example, I changed this code:
>
> objc_msgSend_stret(&origMousePos, gNSEventClass,
> NSSelectorFromString(CFSTR("mouseLocation")));
>
> to this:
>
> origMousePos = (*(NSPoint(*)(void*, void*, ...))
> objc_msgSend_stret)(gNSEventClass,
> NSSelectorFromString(CFSTR("mouseLocation")));
>
> This line crashes every time (as does the original code).
This fails because the struct type is NSPoint. In the i386 function
call ABI, sufficiently small structs like NSPoint are returned in
registers instead of in memory. In this case, you need to use
objc_msgSend() (cast to return NSPoint). objc_msgSend_stret() only
works for structs returned in memory. The PPC ABI returns eight-byte
structs in memory, so objc_msgSend_stret() is the correct call there.
For more details about which structs are returned where,
see the Mac OS X ABI Function Call Guide
http://developer.apple.com/documentation/developertools/Conceptual/LowLevelABI/LowLevelABI.pdf
--
Greg Parker email@hidden Runtime Wrangler
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden