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 protected] Runtime Wrangler _______________________________________________ Cocoa-dev mailing list ([email protected]) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [email protected]
