Re: Is _objc_flush_caches_(Class) necessary to swizzle methods?
Re: Is _objc_flush_caches_(Class) necessary to swizzle methods?
- Subject: Re: Is _objc_flush_caches_(Class) necessary to swizzle methods?
- From: DumberThanDanQuayle <email@hidden>
- Date: Fri, 24 Sep 2004 11:56:20 -0400
Glenn, thanks for the response.
On Sep 24, 2004, at 9:55 AM, Glenn Andreas wrote:
At 4:47 AM -0400 9/24/04, DumberThanDanQuayle wrote:
Does anybody know what the story with "_objc_flush_caches_(Class)"
and method swizzling really is?
From my understanding delving the depths of the runtime,
_objc_flush_caches_ is needed because the runtime maintains cache of
recent methods & imps used when dispatching. So once it figures out
that [foo something] is at 0x123400, it keeps that in the cache for
Foo.
If you change foo something to point to 0x567800, the cache will still
refer to the old version, so the next time you call [foo something]
0x123400 gets executed, and not your new 0x567800.
If it is a method that has never been called, you could probably get
away without calling it.
Great, now I know what _objc_flush_caches_(Class) does and that it
should have nothing to do with my runtime's "strangeness" because I am
method swizzling to achieve something like multiple inheritance and I
am attempting it in +initialize. So my instance methods should have
never been called by that time.
OTOH, I've never seen a problem with inheritence/ivars when doing this
(since that information doesn't use any of the method dispatch cache
anyway).
The type of runtime "strangeness" I am now continuing to experience is
not something simple like the old method is called instead of the new
one. I am talking about the bizarre, like a case of an infinite loop
being generate when calling [super someMethod] and somehow the runtime
decides the receiving method is in a _subclass_ (which in turn calls
[super someMethod]). My latest oddity is the swizzling of two classes
mixes up their "init" methods. It is as if my entire runtime is being
randomly swizzled (or at least those of classes related to being
modified).
This brings me to my next question. Is +initialize a bad place to
swizzle for some reason? Should I try waiting until all classes have
been initialized first? Moreover should I type-check in +initialize so
that subclasses do not redundantly swizzle methods?
Another concern I have is that the CocoaDev page I referenced also
reassigns Method->method_types when swizzling. I suppose this not
necessary useless the arguments required for the methods being swapped
are actually different, but I am not sure.
Thanks again for your help, George.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden