I've been attempting to get an objective-c framework to work with macruby and I 
believe I've found a bug in the way ruby Proc objects are copied when used as 
objective-c blocks.
The copied block doesn't seem to persist correctly beyond the scope in which it 
was copied. It isn't deallocated, but calling it results in a crash. Typical 
error messages are:
 wrong type NSCFSet (expected Proc) (TypeError)
 wrong type NSRectSet (expected Proc) (TypeError)
I'm guessing that there's a pointer to the wrong memory location?

Here's the Objective-C implementation:

@implementation TestBlock

- (id)initWithBlock:(void (^)())aBlock;
{
        [super init];
        block = [aBlock copy];
        NSLog(@"Block: %@", block);
        block();
        return self;
}

- (void)callBlock;
{
        NSLog(@"block: %@", block);
        block();
}

@end


Within 'initWithBlock:', the copied block can be invoked without error. 
Attempting to do so from 'callBlock', results in a crash. The test framework 
can be used without error when using objective-c.

Here's the ruby controller code:

@b = TestBlock.alloc.initWithBlock Proc.new { puts "hello from ruby"} 

# this next line is called from a different scope and causes the crash
@b.callBlock


2010-11-19 08:41:06.620 CallObjectiveCBlocks[7046:a0f] Block: <__NSAutoBlock__: 
0x200be74a0>
hello from ruby

2010-11-19 08:41:20.011 CallObjectiveCBlocks[7046:a0f] block: <__NSAutoBlock__: 
0x200be74a0>
2010-11-19 08:41:20.012 CallObjectiveCBlocks[7046:a0f] 
/Users/alan/Documents/programming/macruby/CallObjectiveCBlocks/build/Debug/CallObjectiveCBlocks.app/Contents/Resources/Controller.rb:21:in
 `call:': wrong type Array (expected Proc) (TypeError)
        from 
/Users/alan/Documents/programming/macruby/CallObjectiveCBlocks/build/Debug/CallObjectiveCBlocks.app/Contents/Resources/rb_main.rb:23:in
 `<main>'
_______________________________________________
MacRuby-devel mailing list
MacRuby-devel@lists.macosforge.org
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel

Reply via email to