[MacRuby-devel] Calling ObjC method

Laurent Sansonetti lsansonetti at apple.com
Tue Mar 4 22:03:26 PST 2008


Ah yes, it's because your test method is defined as returning "void",  
but MacRuby wants to convert the return value because [NSObject - 
performSelector:] is registered in the runtime to return an Objective- 
C object instead (@).

Calling [-performSelector:] on methods that do not return '@' isn't a  
good idea, as in RubyCocoa.

But we need to fix the real bug, which is that the test method should  
be called in priority, and not Kernel#test :)

Laurent

On Mar 4, 2008, at 9:09 PM, Satoshi Nakagawa wrote:

> Hi Laurent,
>
> Thanks.
> I confirmed I call the method with performSelector.
> But it crashed after the method call.
>
> class AppController < NSObject
>  def awakeFromNib
>    a = TestObject.alloc.init
>    a.performSelector(:test)
>  end
> end
>
> [Session started at 2008-03-05 14:06:28 +0900.]
> 2008-03-05 14:06:28.673 ObjcTest[12900:10b] called!
> Loading program into debugger…
> GNU gdb 6.3.50-20050815 (Apple version gdb-768) (Tue Oct  2 04:07:49  
> UTC 2007)
> Copyright 2004 Free Software Foundation, Inc.
> GDB is free software, covered by the GNU General Public License, and  
> you are
> welcome to change it and/or distribute copies of it under certain  
> conditions.
> Type "show copying" to see the conditions.
> There is absolutely no warranty for GDB.  Type "show warranty" for  
> details.
> This GDB was configured as "i386-apple-darwin".Program loaded.
> sharedlibrary apply-load-rules all
> Attaching to program: `/Users/psychs/dev/macruby/ObjcTest/build/ 
> Release/ObjcTest.app/Contents/MacOS/ObjcTest', process 12900.
> (gdb) where
> #0  rb_objc_boot_ocid (ocid=0x1) at objc.m:727
> #1  0x002a1b37 in rb_objc_ocid_to_rval (ocval=<value temporarily  
> unavailable, due to optimizations>, rbval=0xbfffda50) at objc.m:762
> #2  0x002a1f64 in rb_objc_ocval_to_rbval (ocval=0xbfffd800,  
> octype=0xbfffd8c4 "@", rbval=0xbfffda50) at objc.m:787
> #3  0x002a299d in rb_objc_to_ruby_closure_handler (cif=0xbfffd820,  
> resp=0xbfffda50, args=0xbfffda10, userdata=0x406b04) at objc.m:1007
> #4  0x925ec424 in ffi_closure_SYSV ()
> #5  0x00297090 in vm_call_method (th=0x1013f70, cfp=0xafee0, num=1,  
> blockptr=0x1, flag=97, id=113247, mn=0x1563000, recv=22425248,  
> klass=22424672) at vm_insnhelper.c:372
> #6  0x00290908 in vm_eval (th=0x1013f70, initial=0) at insns.def:1085
> #7  0x002962ac in vm_eval_body (th=0x1013f70) at vm.c:1149
> #8  0x00297804 in vm_call0 (th=0x1013f70, klass=22238096,  
> recv=22357968, id=113200, oid=0, argc=0, argv=0xbfffe4e0,  
> body=0x15355e0, nosuper=0) at vm.c:443
> #9  0x001d5284 in rb_call0 (klass=22238096, recv=22357968,  
> mid=113200, argc=0, argv=0xbfffe4e0, scope=1, self=16894304) at  
> eval.c:1464
> #10 0x001d5459 in rb_call (klass=<value temporarily unavailable, due  
> to optimizations>, recv=<value temporarily unavailable, due to  
> optimizations>, mid=<value temporarily unavailable, due to  
> optimizations>, argc=0, argv=0x0, scope=0) at eval.c:1480
> #11 0x001d92f0 in rb_apply (recv=22357968, mid=113200,  
> args=17351024) at eval.c:1492
> #12 0x002a2bbb in rb_ruby_to_objc_closure_handler (cif=0x6bf730,  
> resp=0xbfffe640, args=0xbfffe600, userdata=0x0) at objc.m:1075
> #13 0x925ec424 in ffi_closure_SYSV ()
> #14 0x94fafa55 in -[NSSet makeObjectsPerformSelector:] ()
> #15 0x95b6fec2 in -[NSIBObjectData  
> nibInstantiateWithOwner:topLevelObjects:] ()
> #16 0x95b660ec in loadNib ()
> #17 0x95b65a4d in +[NSBundle(NSNibLoading)  
> _loadNibFile:nameTable:withZone:ownerBundle:] ()
> #18 0x95b65690 in +[NSBundle(NSNibLoading)  
> loadNibFile:externalNameTable:withZone:] ()
> #19 0x95b655ce in +[NSBundle(NSNibLoading) loadNibNamed:owner:] ()
> #20 0x95b6527e in NSApplicationMain ()
> #21 0x925ec1dd in .LCFI1 ()
> #22 0x925ec771 in ffi_call ()
> #23 0x002a2250 in bs_function_dispatch (argc=2, argv=0x30050,  
> recv=16894304) at objc.m:1458
> #24 0x00289385 in call_cfunc (func=0x2a1fd0 <bs_function_dispatch>,  
> recv=16894304, len=<value temporarily unavailable, due to  
> optimizations>, argc=2, argv=0x30050) at vm_insnhelper.c:282
> #25 0x00297090 in vm_call_method (th=0x1013f70, cfp=0xaff88, num=2,  
> blockptr=0x1, flag=2145, id=10693, mn=0x151ac20, recv=16894304,  
> klass=16894336) at vm_insnhelper.c:372
> #26 0x00290908 in vm_eval (th=0x1013f70, initial=0) at insns.def:1085
> #27 0x002962ac in vm_eval_body (th=0x1013f70) at vm.c:1149
> #28 0x00296581 in rb_iseq_eval (iseqval=17503408) at vm.c:1358
> #29 0x001d22c4 in ruby_exec_node (n=0x10b1150, file=0x10b0061 "/ 
> Users/psychs/dev/macruby/ObjcTest/build/Release/ObjcTest.app/ 
> Contents/Resources/rb_main.rb") at eval.c:235
> #30 0x001d789f in ruby_run_node (n=0x10b1150) at eval.c:265
> #31 0x002a0cda in macruby_main (path=0x1fcc "rb_main.rb", argc=3,  
> argv=0x409270) at objc.m:2403
> #32 0x00001fba in main (argc=1, argv=0x1) at /Users/psychs/dev/ 
> macruby/ObjcTest/main.m:14
> Current language:  auto; currently objective-c
> (gdb) frame
> #0  rb_objc_boot_ocid (ocid=0x1) at objc.m:727
> 727	    if (rb_objc_is_non_native((VALUE)ocid)) {
>
> --
> Satoshi Nakagawa
>



More information about the MacRuby-devel mailing list