Re: Creating an NSInvocation from an NSMethodSignature
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