Re: Hard Objc-Runtime question: objc_getClassList lies to me...
Re: Hard Objc-Runtime question: objc_getClassList lies to me...
- Subject: Re: Hard Objc-Runtime question: objc_getClassList lies to me...
- From: Greg Parker <email@hidden>
- Date: Sun, 27 Jul 2003 19:13:27 -0700
Martin wrote:
> The first time I call -allClasses I don't get "DWTClassListerTest
> included in the results, though it works after the call to
> objc_lookUpClass. :(
>
> Well... The Runtime obviously knows about the class I am asking it,
> because I can look it up via "objc_lookupClass", but how can I get
> all of these classes without knowing their name beforehand?
As you've already discovered, this behavior is a side effect of
ZeroLink. Here's some more details about what's going on.
(Terminology note: an `image` is any Mach-O file with binary code in it,
like an application, library, or bundle. Mach-O images are subdivided
into `modules`. Each module typically corresponds to a single source
code file.)
objc_getClassList() returns all of the classes that have been
registered with the Objective-C runtime. Ordinarily, all classes in
an image are loaded together when that image is loaded into the process.
Thus objc_getClassList() will show all classes in all of Foundation
once Foundation is loaded.
When running with ZeroLink, the Objective-C runtime (as well as C
and C++) is lazier. Instead of loading all classes in an image
together, the runtime only loads all classes in an individual
module; other classes in other modules in the same image are left
alone.
objc_lookUpClass() used to simply check whether a class had been
loaded yet. It now has a side-effect when running with ZeroLink:
if the class has not been loaded yet but ZeroLink can find it,
then ZeroLink will bring it in.
In your code, the "missing" class is presumably in a different
source file and thus in a different Mach-O module. The class is
not yet loaded when objc_getClassList() is called the first time,
and objc_lookUpClass() forces ZeroLink to load it before the second
objc_getClassList() call.
If you need objc_getClassList() to return all of your classes, you can
* explicitly use them early on in your code
* link your program with -single_module
* turn off ZeroLink in your project
--
Greg Parker email@hidden Java & Objective-C
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.