#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/>