bug-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: objc_next_class


From: Richard Frith-Macdonald
Subject: Re: objc_next_class
Date: Fri, 14 Jun 2002 06:14:54 +0100

I'm not sure what the original problem is, but just in case it's not obvious,
the code would fail (as Nicola notes below) because it would raise an
exception and crash as it iterates past the Object class -
NSLog() uses the -description method to log the class 'cl', but Object
does not respond ot that method.
I don't know where Object would appear in the iterated list (I'd have
expected it to be right at one end).

Perhaps we should add a category of Object in GNUstep-base, to implement
-description for it?

On Friday, June 14, 2002, at 02:40 AM, Nicola Pero wrote:


Definitely the NSLog call is causing problems - try adding a 'NSLog' call
before this code snippet (looks like the first call to NSLog is
initializing something which is confusing objc_next_class() ... bug in the
runtime ?) ... I'd like to check if the new 3.1 runtime still has this
problem (since I rewrote all that runtime code).

Anyway - after adding a dumb NSLog call before the code, I get all the
classes, except one of the last ones gives -

error: Object (class)
Object does not recognize respondsToSelector:
Aborted

not much you can do about it ...

NSLog (@"%@", [Object class]);

seems to be causing an error.

Replacing the NSLog with

NSLog (@"fail on %@\n", NSStringFromClass (cl));

fixes this problem.


Hope all that helps :-)

Please post questions/bug reports etc to a mailing list, such as
bug-gnustep@gnu.org, so that other people get the opportunity of taking
part/commenting/reading.


On Tue, 11 Jun 2002, Marko Riedel wrote:


Hi all,

I am working on another example. I don't want to go into the details
until I have a working program.

I have a question about objc_next_class. It used to work fine, but now
it no longer iterates over all classes. Here is the code that I am
using:

    void *state = NULL;
    Class cl;
    id primitive;

    while((cl = objc_next_class(&state)) != nil){
        if([NSStringFromClass(cl) hasPrefix:PRIM_CLASS_PREF]){
            primitive = [[cl alloc] init];
            NSLog(@"primitive %@ %@\n", cl, primitive);
            [prim setObject:primitive
                  forKey:[primitive primName]];
        }
        else{
            NSLog(@"fail on %@\n", cl);
        }
    }
    NSLog(@"last %@\n", cl);

The output is as follows:

Jun 11 17:57:40 ...[9998] fail on NSPrinter
Jun 11 17:57:40 ...[9998] last (nil)

Where are all the other classes that I know are there, like NSObject,
NSString, NSDictionary etc.?

What is going on here? I also tried class_table_next, but it doesn't
seem to be available in the distribution that I downloaded.



_______________________________________________
Bug-gnustep mailing list
Bug-gnustep@gnu.org
http://mail.gnu.org/mailman/listinfo/bug-gnustep





reply via email to

[Prev in Thread] Current Thread [Next in Thread]