[MacRuby] #1003: Copied Proc objects cause crash when used as Objective-C blocks
#1003: Copied Proc objects cause crash when used as Objective-C blocks ----------------------------------+----------------------------------------- Reporter: al_skipp@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Objective-C objects which copy a C block to invoke later can cause a crash/error when used in macruby. The Objective-C code is as follows (also attached as a framework): {{{ #import <Cocoa/Cocoa.h> @interface TestBlock : NSObject { void (^block)(void); } - (id)initWithBlock:(void (^)())aBlock; - (void)callBlock; @end #import "TestBlock.h" @implementation TestBlock - (id)initWithBlock:(void (^)())aBlock; { if ((self = [super init])) { block = [aBlock copy]; NSLog(@"Block: %@", block); block(); } return self; } - (void)callBlock; { NSLog(@"block: %@", block); block(); } @end }}} The following code will work if saved in an .rb file and called from Macruby. However the same code in Macirb will fail. {{{ framework File.expand_path('BlockFrameworkTest.framework') b = TestBlock.alloc.initWithBlock Proc.new { puts "hello"} b.callBlock }}} Also included is a small Xcode project that shows that the code fails when invoked from macruby, but not from objective-c. My guess is that when the object is initialized and the 'callBlock' method are invoked within the same iteration of the run loop, then the error doesn't occur. If the 'callBlock' method call occurs in a later run loop iteration, the error will occur. But that's a guess. -- Ticket URL: <http://www.macruby.org/trac/ticket/1003> MacRuby <http://macruby.org/>
#1003: Copied Proc objects cause crash when used as Objective-C blocks ----------------------------------+----------------------------------------- Reporter: al_skipp@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Comment(by al_skipp@…): I was unable to attach the Xcode project, as the file size exceeded the upload limit. -- Ticket URL: <http://www.macruby.org/trac/ticket/1003#comment:1> MacRuby <http://macruby.org/>
#1003: Copied Proc objects cause crash when used as Objective-C blocks ----------------------------------+----------------------------------------- Reporter: al_skipp@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Comment(by al_skipp@…): Xcode project now attached. Will need to manually relink to the 'BlockFramework.framework' to get it to build. -- Ticket URL: <http://www.macruby.org/trac/ticket/1003#comment:2> MacRuby <http://macruby.org/>
#1003: Copied Proc objects cause crash when used as Objective-C blocks ----------------------------------+----------------------------------------- Reporter: al_skipp@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Comment(by martinlagardette@…): That's just a guess, but I think MacRuby is creating the wrong type of block: {{{ ## Objective-C block 2010-11-20 11:58:46.104 CallObjectiveCBlocks[44528:a0f] Block: <__NSGlobalBlock__: 0x100001240> ## Ruby block 2010-11-20 11:58:46.111 CallObjectiveCBlocks[44528:a0f] Block: <__NSAutoBlock__: 0x2009e7620> }}} It may be that auto means "auto-released", in which case it would be the reason. -- Ticket URL: <http://www.macruby.org/trac/ticket/1003#comment:3> MacRuby <http://macruby.org/>
#1003: Copied Proc objects cause crash when used as Objective-C blocks ----------------------------------+----------------------------------------- Reporter: al_skipp@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Comment(by martinlagardette@…): More specifically: {{{ ## Objective-C # block argument to initWithBlock 2010-11-20 18:23:43.047 CallObjectiveCBlocks[47405:a0f] [initWithBlock:] aBlock: <__NSGlobalBlock__: 0x100001240> # Copied block 2010-11-20 18:23:43.050 CallObjectiveCBlocks[47405:a0f] [initWithBlock:] block: <__NSGlobalBlock__: 0x100001240> ## Ruby # block argument to initWithBlock 2010-11-20 18:23:43.055 CallObjectiveCBlocks[47405:a0f] [initWithBlock:] aBlock: <__NSStackBlock__: 0x7fff5fbfd400> # Copied block 2010-11-20 18:23:43.056 CallObjectiveCBlocks[47405:a0f] [initWithBlock:] block: <__NSAutoBlock__: 0x200bedf80> }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/1003#comment:4> MacRuby <http://macruby.org/>
#1003: Copied Proc objects cause crash when used as Objective-C blocks ----------------------------------+----------------------------------------- Reporter: al_skipp@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Comment(by lsansonetti@…): The problem here is that the Proc is prematurely garbage-collected. It must be retained during the live cycle of the block. -- Ticket URL: <http://www.macruby.org/trac/ticket/1003#comment:5> MacRuby <http://macruby.org/>
#1003: Copied Proc objects cause crash when used as Objective-C blocks ----------------------------------+----------------------------------------- Reporter: al_skipp@… | Owner: lsansonetti@… Type: defect | Status: closed Priority: blocker | Milestone: MacRuby 0.8 Component: MacRuby | Resolution: fixed Keywords: | ----------------------------------+----------------------------------------- Changes (by lsansonetti@…): * status: new => closed * resolution: => fixed * milestone: => MacRuby 0.8 Comment: Should be fixed in r4971. -- Ticket URL: <http://www.macruby.org/trac/ticket/1003#comment:6> MacRuby <http://macruby.org/>
participants (1)
-
MacRuby