discuss-gnustep
[Top][All Lists]
Advanced

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

Re: Is +[NSMutableArray initialize] completely implemented?


From: Kazunobu Kuriyama
Subject: Re: Is +[NSMutableArray initialize] completely implemented?
Date: Sun, 22 Feb 2004 23:11:37 +0900
User-agent: Mozilla/5.0 (X11; U; Linux i686; ja-JP; rv:1.4) Gecko/20030624 Netscape/7.1

Though this seems to be a dated document, gcc/objc/README of GCC's source tells

<quote>
+initialize
===========

This method, if defined, is called before any other instance or class methods of that particular class. This method is not inherited, and is thus not called as initializer for a subclass that doesn't define it itself. Thus, each +initialize method is called once (or never if no methods of that particular class is never
called).
Besides this, it is allowed ot have several +initialize methods, one for each category. The order in which these (multiple methods) are called is not well
defined.  I am not completely certain what the semantics of this methods is
for other implementations, but this is how it works for GNU Objective C.
<unquote>

Is there anyone who knows further?  Is there a formal document of GNU's ObjC
runtime?

Cheers,
- Kazunobu Kuriyama



David Ayers wrote:

Richard Frith-Macdonald wrote:


On 22 Feb 2004, at 11:56, Philip Mötteli wrote:

and that [NSMutableArray+initialize] is called before any other method of the class, so I don't know how -initWithCapacity: could be called without NSMutableArrayClass being initialised.
or step through in debug yourself to find out what is going on?



I set a breakpoint in both +initialize, in NSMutableArray and NSArray and NSArray's initialize is clearly not called.



Then I guess for some reason the runtime does not think that NSMutableArray inherits from NSArray ... why not?



I found the problem: I have a +initialize method in a category of NSArray. So the runtime system called only this one.



Interesting ... it's worth trying to remember that problem because it's not at all obvious.

Perhaps we should have some coding hints somewhere to say things like ... 'don't override +initilize in a category'


This sounds reasonable... I also fell into that trap before because I believed to have read that +initialize would be called for every category. But I had confused that with +load which /does/ get called per category.

Actually, it's not clear to me whether the runtime should try to detect this situation and call the class implementation before calling the category implementation ... probably not , as I think that categories are generally supposed to be responsible for handling things like that. Also, what if two or more categories override +initialize etc. As far as I know there is no standard way to resolve the situation where multiple categories override a method.


The +load mechanism works because the runtimes invokes it directly (i.e. via implementation pointer when loading the category and not via message lookup.) I don't think we should try doing the same for the current runtimes wrt +initialize. Now whether a future unified runtime had similar mechanism that invokes a standardized method per Class/Category after all runtime initialization has been done, is a different issue.

Perhaps GNUstep should establish some conventions for this and perhaps provide a few runtime helper functions to assist in managing this sort of thing.
On the other hand, it's rarely an issue ...


That's something I think is worth pondering about.

Cheers,
David


_______________________________________________
Discuss-gnustep mailing list
Discuss-gnustep@gnu.org
http://mail.gnu.org/mailman/listinfo/discuss-gnustep






reply via email to

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