kimura wataru
kimur****@i*****
Thu Oct 25 23:00:00 JST 2007
Hi Laurent, It's cool! "new" is very shorter than "alloc.init". I wrote a few tests for object ownership by "new". ocm_retain_arg_if_necessary() in objc/mdl_objwrapper.m works fine with "new", too. === tests/tc_retaincount.rb ================================================================== --- tests/tc_retaincount.rb (revision 413) +++ tests/tc_retaincount.rb (local) @@ -16,12 +16,14 @@ assert_equal(1, RBSubclass.alloc.retainCount, 'alloc') assert_equal(1, RBSubclass.allocWithZone(nil).retainCount, 'allocWithZone:') assert_equal(1, RBSubclass.alloc.init.retainCount, 'alloc.init') + assert_equal(1, RBSubclass.new.retainCount, 'new') # same as alloc.init end # retained by Ruby def test_rb_occlass assert_equal(1, OSX::NSObject.alloc.retainCount, 'alloc') assert_equal(1, OSX::NSObject.alloc.init.retainCount, 'alloc.init') + assert_equal(1, OSX::NSObject.new.retainCount, 'new') assert_equal(1, OSX::NSString.stringWithString('foo').retainCount, 'factory') end @@ -29,12 +31,14 @@ def test_objc_rbclass assert_equal(1, OSX::RetainCount.rbAllocCount, 'alloc') assert_equal(1, OSX::RetainCount.rbInitCount, 'alloc.init') + assert_equal(1, OSX::RetainCount.rbNewCount, 'new') end # retained by Ruby and Objective-C def test_obj_from_objc assert_equal(2, OSX::RetainCount.ocObject.retainCount, 'ObjC object') assert_equal(2, OSX::RetainCount.rbObject.retainCount, 'Ruby object') + assert_equal(2, OSX::RetainCount.rbNewObject.retainCount, 'Ruby object(new)') end # placeholder === tests/objc_test.m ================================================================== --- tests/objc_test.m (revision 413) +++ tests/objc_test.m (local) @@ -121,6 +121,21 @@ return [[NSClassFromString(@"RBSubclass") alloc] init]; } ++(int) rbNewCount +{ + int retainCount; + id obj; + obj = [NSClassFromString(@"RBSubclass") new]; + retainCount = [obj retainCount]; + [obj release]; + return retainCount; +} + ++(id) rbNewObject +{ + return [NSClassFromString(@"RBSubclass") new]; +} + @end // tc_uniqobj.rb