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: James Quick <email@hidden>
- Date: Thu, 24 Jul 2003 20:52:21 -0400
On Thursday, July 24, 2003, at 06:44 PM, Martin Hdcker wrote:
--- 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.
If the class you are looking for in that set is in a loadable bundle,
the the bundle will not be loaded until required. The Mach-o
runtime adds the required shared libraries to your executable
image at startup time. It does not, however, do any additional
work until needed. It does not load the resource from disk
into memory and do runtime linking to resolve symbols to
the point to the now valid resources in memory. If the
bundle contains objective-c resources the runtime system
cannot know about them yet.
If you had done something like, [ClassLister className], or
made any other reference which would cause the bundle to
be loaded. Then the objective c runtime would be passed a
reference to the classes, methods, and desciptions of instance
variables, etc. and you wouldn't have this problem. So, If you
need access to this information before creating any instances
or calling a class method, you'll have to make sure the containing
bundle is loaded on your own. NSBundle does this.
If it's just one or several classes, and you knew about them at
compile time, then bundleForClass will do the trick.
+ (NSBundle *) bundleForClass: (Class) aClass;
will return the bundle containing the class.
+ (NSBundle *) load;
In your case [[NSBundle bundleForClass: Test] load];
would load the bundle and (I think) inform the runtime about
the class Test, and the other classes defined in the bundle.
I think that that will work. If I am wrong, and the class
information still is not loaded to the objective-c runtime,
then try an another method
[[NSBundle bundleForClass: Test] principleClass];
That loads the bundle and returns a pointer the the
bundles principle objective C class, which defaults to the first
one loaded, but you could define to be a class which does
setup, or mediates interaction between the application
and the rest of the bundle's classes.
That actually sounds pretty cool, as you could load classes,
interrogate them about the methods they respond to,
and potentially do useful work without ever knowing
at the time you were compiled, what kind of objects
you are loading from the bundle. Wow.
I'm curious to know if -load was sufficient or you need
- principleClass, before the objc runtime gets informed.
_______________________________________________
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.