From: Brian M. <ma...@ex...> - 2008-05-02 21:38:49
|
Here's a program that shows a core dump when posting an NSNotification after Ruby GC. I suspect I'm doing something stupid, possibly with a selector. -------------------------------------- #!/usr/bin/env ruby require 'osx/cocoa' include OSX Center = NSNotificationCenter.defaultCenter class Receiver < NSObject def init Center.addObserver_selector_name_object(self, :handle_, "notification name", nil) end def handle(notification) puts notification end end class Sender < NSObject def announce Center.postNotificationName_object("notification name", self) end end if $0 == __FILE__ r = Receiver.alloc.init # Center.postNotificationName_object("notification name", self) Sender.alloc.init.announce # removable GC.start # removable puts "About to post" Sender.alloc.init.announce # Center.postNotificationName_object("notification name", self) puts "I survived!" end -------------------------------------- Here's the result with stock Leopard RubyCocoa (OSX::RUBYCOCOA_VERSION=> "0.13.1"): 563 $ ruby x.rb NSConcreteNotification 0x57a8f0 {name = notification name; object = <Sender: 0x2a9a30>} x.rb:30: [BUG] Segmentation fault ruby 1.8.6 (2007-09-24) [universal-darwin9.0] Abort trap Most any change you make to the code prevents the core dump: - remove either of the lines marked removable. - remove the assignment to the global (but keep the alloc.init). - change the first use of Sender to post the notification directly. (Changing the second does not prevent the core dump.) I tried using addRubyMethod_withType (per http://www.rubycocoa.com/appleremote/2 ), but got all the same behavior. Here's the backtrace: #0 0x941300ea in kill$UNIX2003 () (gdb) bt #0 0x941300ea in kill$UNIX2003 () #1 0x941a73f2 in raise () #2 0x941b69af in abort () #3 0x000cdc50 in rb_bug () #4 0x0013464f in rb_gc_mark_trap_list () #5 0x9412e5eb in _sigtramp () #6 0xffffffff in ?? () #7 0x000cfe3c in rb_clear_cache_by_class () #8 0x000db695 in rb_obj_respond_to () #9 0x000db721 in rb_respond_to () #10 0x0018a3d4 in rbobj_call_ruby () #11 0x0018689a in sel_to_rbobj () #12 0x96ba8424 in ffi_prep_cif_machdep () #13 0x94345bda in NSZoneMalloc () #14 0x936e19da in _CFXNotificationResetSessionForTask () #15 0x936e1cb3 in _CFXNotificationPostNotification () #16 0x94342fd0 in NSPopAutoreleasePool () #17 0x9434c668 in _NSDescriptionWithLocaleFunc () #18 0x96ba81dd in ffi_call_SYSV () #19 0x96ba8771 in ffi_call () #20 0x00196a6c in rb_ffi_dispatch () #21 0x00181b65 in objcptr_s_new_with_cptr () #22 0x00182e44 in init_mdl_OCObjWrapper () #23 0x96ba8424 in ffi_prep_cif_machdep () #24 0x000da18c in rb_eval_string_wrap () #25 0x000dad6a in rb_eval_string_wrap () #26 0x000d80da in rb_eval_string_wrap () #27 0x000e706e in rb_load_protect () #28 0x000e709f in ruby_exec () #29 0x000e70cb in ruby_run () #30 0x00001fff in main () ----- Brian Marick, independent consultant Mostly on agile methods with a testing slant www.exampler.com, www.exampler.com/blog, www.twitter.com/marick |