discuss-gnustep
[Top][All Lists]
Advanced

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

Re: Why is +initialize not inherited?


From: Richard Frith-Macdonald
Subject: Re: Why is +initialize not inherited?
Date: Fri, 16 Sep 2011 10:46:01 +0100

On 15 Sep 2011, at 19:46, Larry Campbell wrote:

> I always thought it was a bad idea to call +initialize directly. For one 
> thing, the runtime guarantees that only one thread can be in your +initialize 
> at a time, but that guarantee vanishes if you call it yourself directly.

Which is why you must NOT depend on that thread safety (any code linked into 
your app might call +initialize).  The thread safety guarantee only applies to 
the *first* time a +initialize implementation is called.
This is why the paradigm is
+ (void) initialize
{
  static BOOL beenHere = NO;

  if (NO == beenHere)
    {
      beenHere = YES;
      // setup lock if required
    }
  // use lock for thread safety if required
}

> So I typically (on Mac OS) try to init classes like this as follows:
> 
>    [Subclass class];
> 
> On Mac OS X that causes +[Superclass initialize] to get called, but not in 
> gnustep.
> 
> - lc
> 
> On Sep 15, 2011, at 2:43 PM, David Chisnall wrote:
> 
>> I'm not sure how that would help you.  Your subclasses would only receive a 
>> +initialize message once you'd sent them some other message, which requires 
>> some other bit of code to be able to locate them, which means the other code 
>> can trivially register them...
>> 
>> That said, I agree that we should aim to be compatible with Apple, although 
>> in this case I think the GNU behaviour is more logical.

I think the Apple behavior has always more accurately matched the documentation 
(though the wording used to be vague enough for wiggle room), and the 
latest/current Apple documentation is certainly explicit about this, so the GNU 
runtime derived behavior is wrong.

>> I've made that change in the GNUstep Objective-C runtime, and it will be 
>> part of the 1.6 release unless someone objects strongly...

I've fixed the GNUstep traditional ObjC runtime (and put the new version on the 
ftp site), and also sent Nicola a patch to fix the the GCC-4.6.x runtime.

I've also added a testcase for this in the base library testsuite.


reply via email to

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