Hi, I tried to call a method in my ObjC class, then I got the 'private method' error. Even with a bridge-support file for the class, it remains the same. How can I use my ObjC class? @interface TestObject : NSObject - (void)test; @end #dir = NSBundle.mainBundle.resourcePath.fileSystemRepresentation #load_bridge_support_file dir + '/TestObject.bridgesupport' class AppController < NSObject def awakeFromNib a = TestObject.alloc.init a.test end end Revision: the latest trunk Project: http://limechat.net/macruby/ObjcTest.zip /Users/psychs/dev/macruby/ObjcTest/build/Release/ObjcTest.app/Contents/ Resources/appcontroller.rb:7:in `awakeFromNib': private method `test' called for #<TestObject:0x10af580> (NoMethodError) from /Users/psychs/dev/macruby/ObjcTest/build/Release/ObjcTest.app/ Contents/Resources/rb_main.rb:22:in `NSApplicationMain' from /Users/psychs/dev/macruby/ObjcTest/build/Release/ObjcTest.app/ Contents/Resources/rb_main.rb:22:in `<main>' -- Satoshi Nakagawa
Hi Satoshi-san, It's most probably a duplicate of http://trac.macosforge.org/projects/ruby/ticket/14 The problem is that when you call #test on your object, MacRuby tries to call Kernel#test (because Kernel is included in NSObject). And this fails. You can reproduce it by calling #test on any object: $ /usr/local/bin/irb irb(main):001:0> 1.test NoMethodError: private method `test' called for 1:Fixnum (Even in 1.8.) Until this problem is addressed, you can call a.performSelector(:test) as a workaround to make sure your Objective-C method will be called. Laurent On Mar 4, 2008, at 7:43 PM, Satoshi Nakagawa wrote:
Hi,
I tried to call a method in my ObjC class, then I got the 'private method' error. Even with a bridge-support file for the class, it remains the same.
How can I use my ObjC class?
@interface TestObject : NSObject - (void)test; @end
#dir = NSBundle.mainBundle.resourcePath.fileSystemRepresentation #load_bridge_support_file dir + '/TestObject.bridgesupport'
class AppController < NSObject def awakeFromNib a = TestObject.alloc.init a.test end end
Revision: the latest trunk Project: http://limechat.net/macruby/ObjcTest.zip
/Users/psychs/dev/macruby/ObjcTest/build/Release/ObjcTest.app/ Contents/ Resources/appcontroller.rb:7:in `awakeFromNib': private method `test' called for #<TestObject:0x10af580> (NoMethodError) from /Users/psychs/dev/macruby/ObjcTest/build/Release/ObjcTest.app/ Contents/Resources/rb_main.rb:22:in `NSApplicationMain' from /Users/psychs/dev/macruby/ObjcTest/build/Release/ObjcTest.app/ Contents/Resources/rb_main.rb:22:in `<main>'
-- Satoshi Nakagawa
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
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
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
Oh sorry. You are right. performSelector worked well for (id)test; -- Satoshi Nakagawa On 2008/03/05, at 15:03, Laurent Sansonetti wrote:
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
I yesterday night investigated a few ways to work around this problem, temporarily, but wasn't able to find one that would work without impacting the current YARV dispatching performance. Let's therefore keep this bug around and in theory it should be automatically fixed once we will use the Objective-C dispatcher for everything. Laurent On Mar 4, 2008, at 11:46 PM, Satoshi Nakagawa wrote:
Oh sorry. You are right. performSelector worked well for (id)test;
-- Satoshi Nakagawa
On 2008/03/05, at 15:03, Laurent Sansonetti wrote:
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
participants (2)
-
Laurent Sansonetti
-
Satoshi Nakagawa