On 18 Jan 2011, at 12:29, Quentin Mathé wrote: > Le 18 janv. 2011 à 12:27, David Chisnall a écrit : > >> On 18 Jan 2011, at 11:20, Quentin Mathé wrote: >> >>> Le 17 janv. 2011 à 23:31, David Chisnall a écrit : >>> >>>> NSZombie is a root class, so its class should inherit from NSObject, >>> >>> Hm, I suppose you mean it shoudn't inherit from NSObject, right? >>> Or may be you mean some NSObject methods are added to NSZombie since it's a >>> root class and it doesn't inherit from NSObject… >> >> No. It's class inherits from NSObject - its metaclass has NSObject's class >> as its superclass. > > Ah right, I forgot how the top of the hierarchy is set up.
I don't like it, but some code does seem to depend on it, unfortunately. >>>> but NSObject's -class method will return the metaclass if self is a >>>> class... >>> >>> As far I remember you can never access the metaclass with NSObject API, >>> NSObject has both -class and +class, but +class returns the receiver class >>> rather than its metaclass. >>> So -class and +class returns the same iirc. >> >> Correct. However, NSObject's instance methods are all class methods of >> other root classes because of this strange rule in Objective-C. That's why >> you have to be careful adding methods to NSObject. > > I wonder if it wouldn't be cleaner to support distinct multiple hiearchies > instead of a single one rooted in NSObject. This could be break some code > that adds methods to NSObject and call them on NSProxy instances, but this is > not a common use though. That's what I did initially in libobjc2. Each root class was its metaclass's superclass (that's a horrible sentence, sorry). Unfortunately, this broke a load of stuff. Thinking about it, the GCC runtime makes Object, rather than NSObject, the superclass in this case. I wonder if the NSZombie stuff depends on this behaviour - if -class in Object returns the class. Back to the original problem: Tobias, could you find the -class method on NSObject in NSObject.m in GNUstep-base, and change it to this: - (Class)class { Class cls = object_getClass(self); if (class_isMetaClass(cls)) { return (Class)self; } return cls; } I think that should fix the problem. If it does, let me know and I'll commit it. There might be some other methods in NSObject that don't properly take into account the fact that they can be called on classes - I'll take a look. Oddly enough, -isClass actually does take this into account, so it's a bit weird that -class doesn't. David -- Sent from my IBM 1620 _______________________________________________ Etoile-dev mailing list Etoile-dev@gna.org https://mail.gna.org/listinfo/etoile-dev