discuss-gnustep
[Top][All Lists]
Advanced

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

Re: has my bug report & fix been submitted (in NSProcessInfo.m)?


From: Gregory John Casamento
Subject: Re: has my bug report & fix been submitted (in NSProcessInfo.m)?
Date: Tue, 19 Jul 2005 18:49:25 -0700 (PDT)

Lloyd,

--- Lloyd Dupont <lloyd@nova-mind.com> wrote:

> > I don't think this could possibly be the correct fix.  This is just 
> > duct-taping a fix over something else which is obviously broken... Aren't 
> > + initialize methods only supposed to be called once?
> 
> so why is it that this test is done on Linux?

It's not only done on Linux, see below...

> and why is it that NeXT documentation (last time I read them in.. uh.. 96?) 
> stated to write your initialize method like that:

I didn't see the example below in either the OpenStep spec '94 or the current
docs.  

> + initialize
> {
>     static BOOL first = true;
>     if(first)
>     {
>         first = false;
>         // real init goes there...
>     }
> }

Please see the following documentation for +initialize at Apple's site:

http://developer.apple.com/documentation/Cocoa/Reference/Foundation/ObjC_classic/Classes/NSObject.html#//apple_ref/doc/uid/20000050-initialize

It's not unusual to see this type of check to prevent a subclass from causing
the code in initialize from being executed a second time (in it's superclass)
when the subclass is loaded.  For instance, suppose I have classes "A" and "B".
 "A" has an initialize method and "B" does not.   In certain circumstances I
may not want initialize code in "A" to be called again when the run-time loads
"B".  In situations like that, I'd do something like the above.

> anyway if if it's "duct taping", it's absolutely not wrong, and it even 
> solve a bug I had.

It may indeed have solved the problem, but that's not the question.  The
question is whether it's the correct fix.  

> Now this method is called 3 times in my code, it maybe because I'm not using 
> ObjectiveC at all (actuall my code is Managed C++, 100% un-compatible with 
> ObjectiveC) and the runtime get confused (I'm just calling the IMPs, and 
> initialized the runtime and classes as well as I could).

The issue is likely somewhere in how you're invoking the Objective-C methods
from C++.   In the (libobjc) runtime objc_msg_send() calls
__obj_init_install_dtable() which then calls __objc_send_initialize() which
sends the initialize msg and then sets a flag which marks the class as
initialized.  This flag is subsequently checked to make certain initialize is
only called once when a class is first used.

> >
> > Just my two cents,
> > Andrew Ruder 

Later, GJC


Gregory John Casamento 
-- CEO/President Open Logic Corp. (A MD Corp.)
## Maintainer of Gorm (IB Equiv.) for GNUstep.




reply via email to

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