[前][次][番号順一覧][スレッド一覧]

ruby-changes:26269

From: ngoto <ko1@a...>
Date: Wed, 12 Dec 2012 00:44:54 +0900 (JST)
Subject: [ruby-changes:26269] ngoto:r38326 (trunk): * test/dl/test_func.rb (test_name_with_block, test_bind, test_qsort1): call unbind to release the callback closure because maximum number of callbacks is limited to DL::MAX_CALLBACK (== 5) with pure DL without Fiddle.

ngoto	2012-12-12 00:44:22 +0900 (Wed, 12 Dec 2012)

  New Revision: 38326

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38326

  Log:
    * test/dl/test_func.rb (test_name_with_block, test_bind, test_qsort1): call unbind to release the callback closure because maximum number of callbacks is limited to DL::MAX_CALLBACK (== 5) with pure DL without Fiddle.

  Modified files:
    trunk/ChangeLog
    trunk/test/dl/test_func.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38325)
+++ ChangeLog	(revision 38326)
@@ -1,3 +1,10 @@
+Wed Dec 12 00:32:11 2012  Naohisa Goto  <ngotogenome@g...>
+
+	* test/dl/test_func.rb (test_name_with_block, test_bind, test_qsort1):
+	  call unbind to release the callback closure because maximum number
+	  of callbacks is limited to DL::MAX_CALLBACK (== 5) with pure DL
+	  without Fiddle.
+
 Wed Dec 12 00:13:34 2012  Naohisa Goto  <ngotogenome@g...>
 
 	* ext/dl/lib/dl/func.rb (DL::Function#unbind, #bound?): suppress
Index: test/dl/test_func.rb
===================================================================
--- test/dl/test_func.rb	(revision 38325)
+++ test/dl/test_func.rb	(revision 38326)
@@ -10,9 +10,13 @@
     end
 
     def test_name_with_block
-      cb = Function.new(CFunc.new(0, TYPE_INT, '<callback>qsort'),
-                        [TYPE_VOIDP, TYPE_VOIDP]){|x,y| CPtr.new(x)[0] <=> CPtr.new(y)[0]}
-      assert_equal('<callback>qsort', cb.name)
+      begin
+        cb = Function.new(CFunc.new(0, TYPE_INT, '<callback>qsort'),
+                          [TYPE_VOIDP, TYPE_VOIDP]){|x,y| CPtr.new(x)[0] <=> CPtr.new(y)[0]}
+        assert_equal('<callback>qsort', cb.name)
+      ensure
+        cb.unbind if cb # max number of callbacks is limited to MAX_CALLBACK
+      end
     end
 
     def test_bound
@@ -60,10 +64,14 @@
 
     def test_bind
       f = Function.new(CFunc.new(0, TYPE_INT, 'test'), [TYPE_INT, TYPE_INT])
-      assert_nothing_raised {
-        f.bind { |x, y| x + y }
-      }
-      assert_equal 579, f.call(123, 456)
+      begin
+        assert_nothing_raised {
+          f.bind { |x, y| x + y }
+        }
+        assert_equal 579, f.call(123, 456)
+      ensure
+        f.unbind # max number of callbacks is limited to MAX_CALLBACK
+      end
     end
 
     def test_to_i
@@ -145,18 +153,22 @@
     end
 
     def test_qsort1()
-      cb = Function.new(CFunc.new(0, TYPE_INT, '<callback>qsort'),
-                        [TYPE_VOIDP, TYPE_VOIDP]){|x,y| CPtr.new(x)[0] <=> CPtr.new(y)[0]}
-      qsort = Function.new(CFunc.new(@libc['qsort'], TYPE_VOID, 'qsort'),
-                           [TYPE_VOIDP, TYPE_SIZE_T, TYPE_SIZE_T, TYPE_VOIDP])
-      buff = "9341"
-      qsort.call(buff, buff.size, 1, cb)
-      assert_equal("1349", buff)
+      begin
+        cb = Function.new(CFunc.new(0, TYPE_INT, '<callback>qsort'),
+                          [TYPE_VOIDP, TYPE_VOIDP]){|x,y| CPtr.new(x)[0] <=> CPtr.new(y)[0]}
+        qsort = Function.new(CFunc.new(@libc['qsort'], TYPE_VOID, 'qsort'),
+                             [TYPE_VOIDP, TYPE_SIZE_T, TYPE_SIZE_T, TYPE_VOIDP])
+        buff = "9341"
+        qsort.call(buff, buff.size, 1, cb)
+        assert_equal("1349", buff)
 
-      bug4929 = '[ruby-core:37395]'
-      buff = "9341"
-      EnvUtil.under_gc_stress {qsort.call(buff, buff.size, 1, cb)}
-      assert_equal("1349", buff, bug4929)
+        bug4929 = '[ruby-core:37395]'
+        buff = "9341"
+        EnvUtil.under_gc_stress {qsort.call(buff, buff.size, 1, cb)}
+        assert_equal("1349", buff, bug4929)
+      ensure
+        cb.unbind if cb # max number of callbacks is limited to MAX_CALLBACK
+      end
     end
 
     def test_qsort2()

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]