[ruby/fiddle] test: ensure freeing closure
GitHub: GH-102 This also improves freed closures assertions. https://github.com/ruby/fiddle/commit/f6431f3cf8
This commit is contained in:
parent
255e617bc3
commit
7c33141293
@ -10,8 +10,11 @@ module Fiddle
|
|||||||
super
|
super
|
||||||
# Ensure freeing all closures.
|
# Ensure freeing all closures.
|
||||||
# See https://github.com/ruby/fiddle/issues/102#issuecomment-1241763091 .
|
# See https://github.com/ruby/fiddle/issues/102#issuecomment-1241763091 .
|
||||||
GC.start
|
not_freed_closures = []
|
||||||
assert_equal(0, ObjectSpace.each_object(Fiddle::Closure) {})
|
ObjectSpace.each_object(Fiddle::Closure) do |closure|
|
||||||
|
not_freed_closures << closure unless closure.freed?
|
||||||
|
end
|
||||||
|
assert_equal([], not_freed_closures)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_argument_errors
|
def test_argument_errors
|
||||||
|
@ -60,31 +60,35 @@ module Fiddle
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_qsort1
|
def test_qsort1
|
||||||
cb = Class.new(Closure) {
|
closure_class = Class.new(Closure) do
|
||||||
def call(x, y)
|
def call(x, y)
|
||||||
Pointer.new(x)[0] <=> Pointer.new(y)[0]
|
Pointer.new(x)[0] <=> Pointer.new(y)[0]
|
||||||
end
|
end
|
||||||
}.new(TYPE_INT, [TYPE_VOIDP, TYPE_VOIDP])
|
|
||||||
|
|
||||||
qsort = Function.new(@libc['qsort'],
|
|
||||||
[TYPE_VOIDP, TYPE_SIZE_T, TYPE_SIZE_T, TYPE_VOIDP],
|
|
||||||
TYPE_VOID)
|
|
||||||
buff = "9341"
|
|
||||||
qsort.call(buff, buff.size, 1, cb)
|
|
||||||
assert_equal("1349", buff)
|
|
||||||
|
|
||||||
bug4929 = '[ruby-core:37395]'
|
|
||||||
buff = "9341"
|
|
||||||
under_gc_stress do
|
|
||||||
qsort.call(buff, buff.size, 1, cb)
|
|
||||||
end
|
end
|
||||||
assert_equal("1349", buff, bug4929)
|
|
||||||
|
closure_class.create(TYPE_INT, [TYPE_VOIDP, TYPE_VOIDP]) do |callback|
|
||||||
|
qsort = Function.new(@libc['qsort'],
|
||||||
|
[TYPE_VOIDP, TYPE_SIZE_T, TYPE_SIZE_T, TYPE_VOIDP],
|
||||||
|
TYPE_VOID)
|
||||||
|
buff = "9341"
|
||||||
|
qsort.call(buff, buff.size, 1, callback)
|
||||||
|
assert_equal("1349", buff)
|
||||||
|
|
||||||
|
bug4929 = '[ruby-core:37395]'
|
||||||
|
buff = "9341"
|
||||||
|
under_gc_stress do
|
||||||
|
qsort.call(buff, buff.size, 1, callback)
|
||||||
|
end
|
||||||
|
assert_equal("1349", buff, bug4929)
|
||||||
|
end
|
||||||
ensure
|
ensure
|
||||||
# Ensure freeing all closures.
|
# Ensure freeing all closures.
|
||||||
# See https://github.com/ruby/fiddle/issues/102#issuecomment-1241763091 .
|
# See https://github.com/ruby/fiddle/issues/102#issuecomment-1241763091 .
|
||||||
cb = nil
|
not_freed_closures = []
|
||||||
GC.start
|
ObjectSpace.each_object(Fiddle::Closure) do |closure|
|
||||||
assert_equal(0, ObjectSpace.each_object(Fiddle::Closure) {})
|
not_freed_closures << closure unless closure.freed?
|
||||||
|
end
|
||||||
|
assert_equal([], not_freed_closures)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_snprintf
|
def test_snprintf
|
||||||
|
Loading…
x
Reference in New Issue
Block a user