• 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: Creating an NSInvocation from an NSMethodSignature
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Creating an NSInvocation from an NSMethodSignature


  • Subject: Re: Creating an NSInvocation from an NSMethodSignature
  • From: Greg Parker <email@hidden>
  • Date: Tue, 12 May 2009 15:19:41 -0700

On May 12, 2009, at 6:43 AM, Michael Ash wrote:
Use -methodForSelector: to get the IMP for a nonexistent method. This
IMP will be a function pointer straight to the runtime's forwarding
machinery. Then install that IMP as the implementation for your
overridden methods. Callers will go straight into the forwarding
machinery rather than into your overridden methods, which will then
invoke -forwardInvocation: as usual and you can then do as you like.

This trick has a few platform- and architecture-specific pitfalls. Here's the safest way to do it:


First: don't call that IMP directly. On some platforms it breaks C function rules, because it assumes it's being called from objc_msgSend.

Second: don't do this for methods that return a struct. There may be two distinct forwarding IMPs, with -methodForSelector: returning the non-struct version. (By "struct return" I mean "method is called via objc_msgSend_stret()", which differs from "returns C struct" on some architectures.)

Someday this will all work seamlessly, but currently all platforms and architectures suffer from at least one of the above.


-- 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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Creating an NSInvocation from an NSMethodSignature
      • From: Mike Mangino <email@hidden>
    • Re: Creating an NSInvocation from an NSMethodSignature
      • From: Michael Ash <email@hidden>
References: 
 >Creating an NSInvocation from an NSMethodSignature (From: Mike Mangino <email@hidden>)
 >Re: Creating an NSInvocation from an NSMethodSignature (From: Michael Ash <email@hidden>)
 >Re: Creating an NSInvocation from an NSMethodSignature (From: Mike Mangino <email@hidden>)
 >Re: Creating an NSInvocation from an NSMethodSignature (From: Michael Ash <email@hidden>)

  • Prev by Date: Re: How to know CD Driver type
  • Next by Date: Re: [iPhone] Caching images fetched from a URL?
  • Previous by thread: Re: Creating an NSInvocation from an NSMethodSignature
  • Next by thread: Re: Creating an NSInvocation from an NSMethodSignature
  • Index(es):
    • Date
    • Thread