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: Martin Häcker <email@hidden>
- Date: Fri, 25 Jul 2003 00:44:37 +0200
Hi!
First of all, thanks for your response and the testcase!
This code is perfectly correct. It will return a list of all the
class names registered with the runtime.
Thanks for the assurance!
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.
Well.. I thought that too.
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:
But then I tried your testcase and get these weird results:
--- snip ---
2003-07-24 23:55:07.900 ObjCRuntimeTest[1505] Before contains <CFSet
0x58f40 [0xa018014c]>{count = 2, capacity = 2, values = (
0 : DATestClass
4 : DAClassLister
)}
2003-07-24 23:55:07.907 ObjCRuntimeTest[1505] After contains <CFSet
0x58f40 [0xa018014c]>{count = 2, capacity = 2, values = (
0 : DATestClass
4 : DAClassLister
)}
ObjCRuntimeTest has exited with status 0.
--- snap ---
Notice that the printf is not in this output.
Then I changed my version of this testcase to this (I also switched
from NSArray to NSSet):
--- snip ---
#import <Foundation/Foundation.h>
#import "ClassLister.h"
//#import "Test.h"
#include <objc/objc-runtime.h>
int main(int argc, char **argv)
{
id pool = [NSAutoreleasePool new];
NSSet *before, *after, *target;
ClassLister *lister = [ClassLister new];
target = [NSSet setWithObjects:@"ClassLister", @"Test", nil];
before = [lister allClasses];
if ([target isSubsetOfSet:before])
NSLog(@"Found it in first try");
Class test = objc_lookUpClass("Test");
if (NULL != test)
printf("lookUp returned: '%s'\n", test->name);
after = [lister allClasses];
if ([target isSubsetOfSet:after])
NSLog(@"found it in second try");
[pool release];
return 0;
}
--- snap ---
And this turns out this results:
--- snip ---
lookUp returned: 'Test'
2003-07-24 23:59:07.619 classtest[1515] found it in second try
classtest has exited with status 0.
--- snap ---
Uhm.... I don't get this. :(
I noticed that I didn't need to include the header of "Test.h" in
main.m, but it seems the compiler dosn't delete the code for Test.h.
(which is good. :)
But I absolutely can't explain why this is happening.
Thanks a lot for your time!
cu Martin
--
dont.wanna.tell
[ot]coder - hehe
_______________________________________________
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.