kimura wataru
kimur****@i*****
Tue Oct 31 06:47:07 JST 2006
(1) is caused by "placeholder" class trick of Cocoa. The code "NSMutableDictionary.alloc.init" in BigLetterView.rb does not work correctly. [EN] http://www.mulle-kybernetik.com/artikel/Optimization/opti-2.html [JA] http://homepage.mac.com/mkino2/spec/optimize/allocation.html ----------------------------------- % irb -r osx/cocoa irb:001> pholder = OSX::NSMutableDictionary.alloc => #<OSX::NSPlaceholderMutableDictionary:0x831ee0 class='NSPlaceholderMutableDic tionary' id=0x4c28c0> irb:002> dict = pholder.init => #<OSX::NSCFDictionary:0x830838 class='NSCFDictionary' id=0x113a310> irb:003> dict.retainCount => 2 irb:004> pholder2 = OSX::NSMutableDictionary.alloc => #<OSX::NSPlaceholderMutableDictionary:0x831ee0 class='NSPlaceholderMutableDic tionary' id=0x4c28c0> irb:005> pholder.release => nil irb:006> pholder3 = OSX::NSMutableDictionary.alloc /usr/local/stow/ruby-1.8.5/lib/ruby/1.8/irb.rb:298: [BUG] Segmentation fault ruby 1.8.5 (2006-08-25) [powerpc-darwin8.7.0] zsh: abort irb -r osx/cocoa ----------------------------------- Some Cocoa classes uses placeholder class for better performance. * 001, 004: NSMutableDictionary returns the same object at alloc. * 002: after init, the real instance of NSMutableDictionary is generated. In Ruby; * 003: the retainCount value should be 1. Because of the different object between alloc and alloc.init, internal "retained" value was NO at alloc.init. * 005: placeholder object was not referenced from ruby, the object was freed by GC. * 006: placeholder object was deallocated. Sending a message to the placeholder object caused a crash. I think the following modification will fix the problem. I'm trying to make the change, and I'll post a patch later. * in ocm_retain_result_if_necessary() 1. the selector begins with "init" and the id of a return value differ from the id of the receiver, then the return value seems to be generated with a placeholder class. 2. If the receiver's retained value is "YES", set the return value's retained to "YES" and set the receiver's to "NO". On Sun, 29 Oct 2006 00:35:56 +0900, kimura wataru wrote: > I changed the subject and thread three. > > Current RubyCocoa trunk (r1189) has these problems. > > (1) sample/RubyTypingTutor crash at dragging > (2) hisa's MSM2006 tutorial_1 crash evaluate the following script > ---- > win = OSX.NSApp().keyWindow > win.setContentView(OSX::NSView.alloc.init) > ---- > > I tried to find the cause of the crashes. I guessed RubyCocoa trunk > has problem(s) in memory management. > > (1) sample/RubyTypingTutor crash at dragging > > I modified the code of trunk as the following diff, and (1) not > occurred. I'll survey more. > > > === framework/src/objc/mdl_objwrapper.m > ================================================================== > --- framework/src/objc/mdl_objwrapper.m (revision 1306) > +++ framework/src/objc/mdl_objwrapper.m (local) > @@ -202,8 +202,8 @@ > // by "alloc/allocWithZone/new/copy/mutableCopy". > if (!NIL_P(result) && rb_obj_is_kind_of(result, objid_s_class()) > == Qtrue) { > if (!OBJCID_DATA_PTR(result)->retained > - && strcmp(selector, "alloc") != 0 > - && strcmp(selector, "allocWithZone:") != 0 > +// && strcmp(selector, "alloc") != 0 > +// && strcmp(selector, "allocWithZone:") != 0 > && strcmp(selector, "new") != 0 > && strcmp(selector, "copy") != 0 > && strcmp(selector, "mutableCopy") != 0) { > >