mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38326 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
ef12c29f3c
commit
a1a5c879f7
2 changed files with 37 additions and 18 deletions
|
@ -1,3 +1,10 @@
|
|||
Wed Dec 12 00:32:11 2012 Naohisa Goto <ngotogenome@gmail.com>
|
||||
|
||||
* 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@gmail.com>
|
||||
|
||||
* ext/dl/lib/dl/func.rb (DL::Function#unbind, #bound?): suppress
|
||||
|
|
|
@ -10,9 +10,13 @@ module DL
|
|||
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 @@ module DL
|
|||
|
||||
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 @@ module DL
|
|||
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()
|
||||
|
|
Loading…
Reference in a new issue