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: Dylan Adams <email@hidden>
- Date: Thu, 24 Jul 2003 13:04:49 -0500
Martin H wrote:
Hi there,
First, please vorgive the repost, but I fear that my last e-mail was so
badly written that nobody wanted to answer to it...
well, how do I get the runtime to give me a list of all its classes?
That is, not just the ones that this code snippet gives me?
--- snip ---
- allClasses
{
id allClasses = [NSMutableArray array];
int classCount = objc_getClassList(NULL, 0);
Class classes[classCount];
objc_getClassList( classes, classCount );
while (classCount--) {
[allClasses addObject:NSStringFromClass(classes[classCount])];
}
return allClasses;
}
This code is perfectly correct. It will return a list of all the class
names registered with the runtime.
--- snap ---
My problem is that when I write a simple testcase like this:
--- snip ---
#import "DWTTestCaseTest.h"
#import "DWTClassLister.h"
#include <objc/objc-runtime.h>
int main(int argc, char **argv)
{
id pool = [NSAutoreleasePool new];
// This does not list "DWTClassListerTest"
// (I think that is because it's not called anywhere)
NSLog(@"%@", [[DWTClassLister new] allClasses]);
// But this works perfectly
Class classListerTest = objc_lookUpClass("DWTClassListerTest");
printf("lookUp returned: '%s'\n", classListerTest->name);
// now this one does does list the class in question
NSLog(@"%@", [[DWTClassLister new] allClasses]);
[pool release];
return 0;
}
--- snap ---
The first time I call -allClasses I don't get "DWTClassListerTest
included in the results, though it works after the call to
objc_lookUpClass. :(
I doubt this to be the case. All objc_lookUpClass does is, well, look up
for a class with the given name in the list of registered classes. It is
does not change the list of registered classes at all.
I wrote a test case based on the code you've given (except I used NSSets
instead of NSArrays so I could use set operations to look through the
list rather than trying to vgrep the output of NSLog). I was not able to
reproduce the situtation you've described. My test case is here:
http://dadams.acm.jhu.edu/misc/ObjCRuntimeTest.tar.gz
dylan
_______________________________________________
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.