• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Which flavor of objc_msgSend for NSSize return
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Which flavor of objc_msgSend for NSSize return


  • Subject: Re: Which flavor of objc_msgSend for NSSize return
  • From: Greg Parker <email@hidden>
  • Date: Fri, 11 May 2007 20:40:21 -0700

Sherm Pendley wrote:

When I call objc_msgSend_stret() in CamelBones, I call it as documented in the runtime reference, returning the struct by reference in the first argument. It's much simpler, with no need for the typecast.

Never call any objc_msgSend function without casting to an appropriate function pointer type.


Calls that may misbehave include structure return on i386, and scalar promotion on all architectures (which will only get worse in 64-bit).


Yes, I'm aware of the note regarding typecasting in objc-runtime.h; IMHO, the runtime reference docs are the official last word, and take precedence over a cryptic comment buried in a header file. That comment has been there for at least six years, to my knowledge, and all the while the runtime reference has made no mention of this function being unreliable for future use.

The `objc_msgSend_stret(&result, receiver, selector, ...)` form does not work on i386. The problem is that the i386 ABI for a function that returns a large struct does not match the i386 ABI for a function that takes a struct address as the first parameter. In the former case, the callee pops the struct address and the caller pops the other arguments. In the latter case, the caller pops all arguments, including the struct address. Depending on the optimization level and the code around the call site, use of this form will crash after disturbing the caller's stack pointer.


Trivia: The comment on objc_msgSend_stret() dates from Panther. It was added because the problem was discovered in the then-secret Intel port of Mac OS X early during Panther development. Steve wasn't kidding when he said "Mac OS X has been leading a secret double life the past five years".


-- Greg Parker email@hidden Runtime Wrangler


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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


  • Follow-Ups:
    • Re: Which flavor of objc_msgSend for NSSize return
      • From: Sherm Pendley <email@hidden>
  • Prev by Date: Re: Easier Toolbar Class
  • Next by Date: Re: Which flavor of objc_msgSend for NSSize return
  • Previous by thread: Re: Which flavor of objc_msgSend for NSSize return
  • Next by thread: Re: Which flavor of objc_msgSend for NSSize return
  • Index(es):
    • Date
    • Thread