On Dec 1, 2007, at 5:15 PM, Christiaan Hofman wrote:

> BTW, I was wondering about a compiler issue: what object do the ivars
> actually belong to, is it the receiver of the method, or the current
> value of self? So if I do:
>
>   receiver = self;
>   self = replacement;
>   myIvar;
>
> Is myIvar now equivalent to receiver->myIvar or replacement->myIvar?
> This would be relevant in this case if super's init could replace the
> object, because it may make assigning ivare before [super init]
> unreliable.

That's a good question.  Practically, it looks like that will only be  
a problem if -[BDSKAsynchronousDOServer init] returns something other  
than self, and we can guarantee that it won't do that.

I wrote a test program to play with this idea.  There's some magic  
that happens with ivar pointers here that I do not understand.

#import <Foundation/Foundation.h>

@interface StringSubclass1 : NSString
@end

@implementation StringSubclass1

- (id)init
{
     [self release];
     return (id)CFStringCreateCopy(NULL, CFSTR("CFString test"));
     return [NSObject new];
}

@end

@interface StringSubclass : StringSubclass1
{
     NSString *string;
}
@end

@implementation StringSubclass

- (id)init
{
     string = [@"Test" copy];
     id originalSelf = self;
     NSLog(@"original self is %@ (%p)", originalSelf->isa,  
originalSelf);
     NSLog(@"string is %p", string);
     self = [super init];
     NSLog(@"original self is %@ (%p)", originalSelf->isa,  
originalSelf);
     NSLog(@"self is %@ (%p)", self->isa, self);
     NSLog(@"string is %p", self->string);
     return self;
}

- (unsigned)length { return [string length]; }
- (unichar)characterAtIndex:(unsigned)idx { return [string  
characterAtIndex:idx]; }

- (void)dealloc
{
     NSLog(@"dealloc StringSubclass %@, releasing string %@", self,  
string);
     //[string release];
     //[super dealloc];
}

@end

int main (int argc, char const *argv[])
{
     NSAutoreleasePool *pool = [NSAutoreleasePool new];

     StringSubclass *c = [[StringSubclass alloc] init];
     [c release];

     [pool release];
     return 0;
}



-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
Bibdesk-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-develop

Reply via email to