• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Hard Objc-Runtime question: objc_getClassList lies to me...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: Hard Objc-Runtime question: objc_getClassList lies to me...
      • From: Martin Häcker <email@hidden>
References: 
 >How to get a list of all classes known to the runtime (From: Martin Häcker <email@hidden>)
 >Hard Objc-Runtime question: objc_getClassList lies to me... (From: Martin Häcker <email@hidden>)

  • Prev by Date: Re: Bug reports and documentation updates
  • Next by Date: Re: time-based beta termination system
  • Previous by thread: Re: Hard Objc-Runtime question: objc_getClassList lies to me...
  • Next by thread: Re: Hard Objc-Runtime question: objc_getClassList lies to me...
  • Index(es):
    • Date
    • Thread