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: Philip Mötteli
Subject: Re: Is +[NSMutableArray initialize] completely implemented?
Date: Sun, 22 Feb 2004 10:30:03 +0100

Am 22.02.2004 um 01:10 schrieb Richard Frith-Macdonald:
On 21 Feb 2004, at 23:49, Philip Mötteli wrote:

The runtime should ensure that [NSArray+initialize] is called before [NSMutableArray+initialize]

Is that sure? As I understood, the first time, a class receives a message, +initialize is called by the runtime. So if NSArray didn't receive a message before NSMutableArray receives its first message, it shouldn't be initialized.


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.


Re
Phil




I'm trying to track down a strange exception, that I never had before the last CVS update:

: Uncaught exception NSGenericException, reason: subclass NSMutableArray(instance) should override initWithCapacity:


The backtrace, that leads to that is the following:

+[NSException raise:format:arguments:]
+[NSException raise:format:]
-[NSObject(GSCategories) subclassResponsibility:]
-[NSMutableArray initWithCapacity:]
-[NSMutableArray initWithObjects:count:]
-[NSArray init]
-[EDStack init]
+[EDStack stack]


So all happens during a very early phase of the program. Most classes haven't been called once yet. I'm not sure, but I have the impression, that the problem could perhaps be situated here:


@implementation NSMutableArray

+ (void) initialize
{
  if (self == [NSMutableArray class])
    {
    }
}

+ (id) allocWithZone: (NSZone*)z
{
  if (self == NSMutableArrayClass)
    {
      return NSAllocateObject(GSMutableArrayClass, 0, z);
    }
  else
    {
      return NSAllocateObject(self, 0, z);
    }
}
...


Shouldn't there be some more code in + initialize? Because in the debugger the variable NSMutableArrayClass is been shown as having the value nil. Probably, the problem is because +[NSArray initialize] has not yet been called, is it? There should be a mechanisme, that assures that or that initializes the same data.






reply via email to

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