[macruby-changes] [4972] MacRuby/trunk/spec/macruby
source_changes at macosforge.org
source_changes at macosforge.org
Thu Dec 2 19:27:39 PST 2010
Revision: 4972
http://trac.macosforge.org/projects/ruby/changeset/4972
Author: lsansonetti at apple.com
Date: 2010-12-02 19:27:36 -0800 (Thu, 02 Dec 2010)
Log Message:
-----------
add new specs regarding C-level blocks
Modified Paths:
--------------
MacRuby/trunk/spec/macruby/fixtures/method.bridgesupport
MacRuby/trunk/spec/macruby/fixtures/method.m
MacRuby/trunk/spec/macruby/language/objc_method_spec.rb
Modified: MacRuby/trunk/spec/macruby/fixtures/method.bridgesupport
===================================================================
--- MacRuby/trunk/spec/macruby/fixtures/method.bridgesupport 2010-12-03 03:27:04 UTC (rev 4971)
+++ MacRuby/trunk/spec/macruby/fixtures/method.bridgesupport 2010-12-03 03:27:36 UTC (rev 4972)
@@ -23,6 +23,20 @@
<method selector='methodAcceptingSEL:target:'>
<arg index='0' sel_of_type='v@:iBf'/>
</method>
+ <method selector='methodSavingBlockReference:'>
+ <arg index='0' function_pointer='true' type='@?'>
+ <arg type='I'/>
+ <arg type='I'/>
+ <retval type='I'/>
+ </arg>
+ </method>
+ <method selector='methodSavingBlockCopy:'>
+ <arg index='0' function_pointer='true' type='@?'>
+ <arg type='I'/>
+ <arg type='I'/>
+ <retval type='I'/>
+ </arg>
+ </method>
</class>
<informal_protocol name='Foo'>
<method type="i@:i" selector="informalProtocolMethod1:"/>
Modified: MacRuby/trunk/spec/macruby/fixtures/method.m
===================================================================
--- MacRuby/trunk/spec/macruby/fixtures/method.m 2010-12-03 03:27:04 UTC (rev 4971)
+++ MacRuby/trunk/spec/macruby/fixtures/method.m 2010-12-03 03:27:36 UTC (rev 4972)
@@ -11,6 +11,7 @@
{
id _foo;
NSMutableDictionary *dic;
+ int (^_my_block)(int, int);
}
@end
@@ -28,6 +29,7 @@
- (void)dealloc
{
[dic release];
+ [_my_block release];
[super dealloc];
}
@@ -791,6 +793,21 @@
return [o informalProtocolMethod2:40 withValue:2];
}
+- (void)methodSavingBlockReference:(int (^)(int, int))b
+{
+ _my_block = b;
+}
+
+- (void)methodSavingBlockCopy:(int (^)(int, int))b
+{
+ _my_block = [b copy];
+}
+
+- (int)callSavedBlockCopyWithArg:(int)x andArg:(int)y
+{
+ return _my_block(x, y);
+}
+
@end
CFNumberRef functionMultiplicatingByTwoViaFctPtr(CFNumberRef nb, CFNumberRef (*multiplier)(CFNumberRef))
Modified: MacRuby/trunk/spec/macruby/language/objc_method_spec.rb
===================================================================
--- MacRuby/trunk/spec/macruby/language/objc_method_spec.rb 2010-12-03 03:27:04 UTC (rev 4971)
+++ MacRuby/trunk/spec/macruby/language/objc_method_spec.rb 2010-12-03 03:27:36 UTC (rev 4972)
@@ -808,6 +808,16 @@
})
res.should == ['zero', 'one', 'two']
end
+
+ it "is properly retained/released when transformed as a Block" do
+ o = TestMethod.new
+ o.methodSavingBlockReference(Proc.new { |x, y| x * y })
+ 10000.times { |i| i.to_s }; GC.start
+ o.callSavedBlockCopyWithArg(42, andArg:100).should == 4200
+ o.methodSavingBlockCopy(Proc.new { |x, y| x * y })
+ 10000.times { |i| i.to_s }; GC.start
+ o.callSavedBlockCopyWithArg(42, andArg:100).should == 4200
+ end
end
describe "Ignored Obj-C selectors" do
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101202/e13c4561/attachment.html>
More information about the macruby-changes
mailing list