• 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: WTF is happening?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: WTF is happening?


  • Subject: Re: WTF is happening?
  • From: Greg Parker <email@hidden>
  • Date: Mon, 15 Dec 2014 12:52:33 -0800

> On Dec 13, 2014, at 7:20 AM, Maxthon Chan <email@hidden> wrote:
>
> This got me scratching my head, hard. Why would class_respondsToSelector() crash? (BTW this is used in a class search loop so I cannot use [NSObject respondsToSelector:] just yet.)

Your evil runtime hack is colliding with someone else's evil runtime hack.

If a class does not have an implementation for some selector then the runtime asks the class if it would like to add one using +resolveInstanceMethod: or +resolveClassMethod:. In this case you have found that the implementation of +[_NSObjectAnimator resolveInstanceMethod:] crashes. (It turns out that _NSObjectAnimator assumes the message is only sent to its subclasses, not to _NSObjectAnimator itself.)

In general it is not safe to look up arbitrary classes and then send messages to them. Checking for conformance (using the C function, not the NSObject method) to a protocol you defined and then only sending messages from that protocol is the safest way to go. Filtering out classes with base classes that are not NSObject sometimes works. Filtering out classes whose names start with "_" sometimes works.


--
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


  • Prev by Date: Re: WTF is happening?
  • Next by Date: Re: NSRegularExpression segfault
  • Previous by thread: Re: WTF is happening?
  • Next by thread: Apple Events not being handled during UI tracking
  • Index(es):
    • Date
    • Thread