Re: [Pyobjc-dev] NSTextView weirdness
Brought to you by:
ronaldoussoren
From: Ronald O. <ous...@ci...> - 2002-11-13 21:16:17
|
Some more debugging shows: The test code is too complex, the code below also causes a crash: from AppKit import NSTextView NSTextView.alloc() What I don't fully understand is the output of the following program: #import <AppKit/AppKit.h> int main(void) { id pool = [[NSAutoreleasePool alloc] init]; id obj = [NSTextView alloc]; NSLog(@"obj: %p [%d]\n", obj, [obj retainCount]); id withInit = [obj init]; NSLog(@"withInit: %p [%d]\n", withInit, [withInit retainCount]); NSLog(@"same? %d", obj == withInit); [pool release]; NSLog(@"obj: %p [%d]\n", obj, [obj retainCount]); return 0; } This emits: 2002-11-13 20:46:02.303 t[1448] obj: 0xb0890 [1] 2002-11-13 20:46:02.355 t[1448] withInit: 0xb0890 [3] 2002-11-13 20:46:02.357 t[1448] same? 1 2002-11-13 20:46:02.359 t[1448] obj: 0xb0890 [2] The retainCount after [[NSTextView alloc] init] is 3, and then autoreleased??? I've reproduced the problem in some pure Objective-C code: #import <AppKit/AppKit.h> int main(void) { id nil_obj = nil; id pool = [[NSAutoreleasePool alloc] init]; id inv = [NSInvocation invocationWithMethodSignature: [NSMethodSignature signatureWithObjCTypes:"@@:"]]; [inv retain]; [inv setTarget:[NSTextView class]]; [inv setSelector:@selector(alloc)]; [inv invoke]; [inv setReturnValue:&nil_obj]; return 0; } This crashes when using NSTextView, and works when using NSTableView. This looks like a problem with Apple code. I've checked in a workaround that at least should allow NSTextView.alloc().init(). The following code now works: from AppKit import NSTextView for i in range(10): print NSTextView.alloc().init() print "done" The workaround consists of adding custom wrappers for +alloc. This is intented to be a temporary workaround. Hmm, if your debugging the NSInternalConsistency problem from Arnolds message earlier today this isn't very helpfull, the problem doesn't go away. If I evaluate NSTextView.setEditable_ before calling obj.setEditable_ all goes well. I'm still checking why this is necessary. Ronald |