[MacRuby] #401: Cannot call from ObjC to Ruby with an int argument
#401: Cannot call from ObjC to Ruby with an int argument -------------------------------------+-------------------------------------- Reporter: antony.blakey@… | Owner: lsansonetti@… Type: defect | Status: new Priority: critical | Milestone: MacRuby 0.5 Component: MacRuby | Keywords: -------------------------------------+-------------------------------------- 0.5b1 / 10.6.1 Given this Obj-C trampoline (with corresponding header): {{{ @implementation CallInDriver +(id) test:(id)rubyObject { return [rubyObject callWithInt:1]; } @end }}} and this Ruby that uses it: {{{ class Test def callWithInt(i) nil end end CallInDriver.test(Test.new) }}} you get: {{{ Program received signal: “EXC_BAD_ACCESS". }}} Changing the ObjC call to: {{{ return [rubyObject callWithInt:[NSNumber numberWithInt: 1]]; }}} doesn't have the problem (as you would expect). I presume this is meant to work? -- Ticket URL: <http://www.macruby.org/trac/ticket/401> MacRuby <http://macruby.org/>
#401: Cannot call from ObjC to Ruby with an int argument -------------------------------------+-------------------------------------- Reporter: antony.blakey@… | Owner: lsansonetti@… Type: defect | Status: closed Priority: critical | Milestone: MacRuby 0.5 Component: MacRuby | Resolution: invalid Keywords: | -------------------------------------+-------------------------------------- Changes (by lsansonetti@…): * status: new => closed * resolution: => invalid Comment: Calling Ruby from Objective-C can be problematic because of the runtime signature. In your case, the callWithInt: Ruby method is registered by default as accepting an Objective-C object, but in the Objective-C side you pass a C int, which results in the segfault. We introduced an API called -performRubySelector:, we recommend to use it when calling Ruby from Objective-C. Check out the MacRuby.h header file for the complete list of these APIs. -- Ticket URL: <http://www.macruby.org/trac/ticket/401#comment:1> MacRuby <http://macruby.org/>
#401: Cannot call from ObjC to Ruby with an int argument -------------------------------------+-------------------------------------- Reporter: antony.blakey@… | Owner: lsansonetti@… Type: defect | Status: closed Priority: critical | Milestone: MacRuby 0.5 Component: MacRuby | Resolution: invalid Keywords: | -------------------------------------+-------------------------------------- Comment(by antony.blakey@…): How is it possible then to implement Ruby objects that act as delegates or dataSources? I'm doing this now for table delegates, and it works with int arguments. The Ruby object '''doesn't''' descend from an Objective-C implementation of the protocol (which I've found fixes the problem). If this is true then how can you implement any Objective-C protocol with non- object arguments in a Ruby object? Is there something I need to do to register a protocol's method signatures so that the argument types become the default? -- Ticket URL: <http://www.macruby.org/trac/ticket/401#comment:2> MacRuby <http://macruby.org/>
#401: Cannot call from ObjC to Ruby with an int argument -------------------------------------+-------------------------------------- Reporter: antony.blakey@… | Owner: lsansonetti@… Type: defect | Status: closed Priority: critical | Milestone: MacRuby 0.5 Component: MacRuby | Resolution: invalid Keywords: | -------------------------------------+-------------------------------------- Comment(by lsansonetti@…): The current solution is to provide a BridgeSupport file that annotates all informal protocols (including datasource or delegate methods) of your Objective-C framework. MacRuby will read that file at runtime and appropriately register the methods using the right runtime signature. Most frameworks of Mac OS X ship with BridgeSupport files, so you should not need to do any of that if you deal with system APIs. In case you're trying to use MacRuby from your own Objective-C framework, you will have to generate a BridgeSupport file for it. Check out the gen_bridge_metadata(1) man-page for more info (you can also google a bit). -- Ticket URL: <http://www.macruby.org/trac/ticket/401#comment:3> MacRuby <http://macruby.org/>
participants (1)
-
MacRuby