1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/fiddle] test: ensure freeing closure

GitHub: GH-102

This also improves freed closures assertions.

https://github.com/ruby/fiddle/commit/0495624caf
This commit is contained in:
Sutou Kouhei 2022-09-15 06:44:07 +09:00 committed by Hiroshi SHIBATA
parent dfca6a8799
commit 824c474c95

View file

@ -18,8 +18,11 @@ module Fiddle
def teardown
# Ensure freeing all closures.
# See https://github.com/ruby/fiddle/issues/102#issuecomment-1241763091 .
GC.start
assert_equal(0, ObjectSpace.each_object(Fiddle::Closure) {})
not_freed_closures = []
ObjectSpace.each_object(Fiddle::Closure) do |closure|
not_freed_closures << closure unless closure.freed?
end
assert_equal([], not_freed_closures)
end
def test_default_abi
@ -82,11 +85,12 @@ module Fiddle
end
def test_argument_count
closure = Class.new(Closure) {
closure_class = Class.new(Closure) do
def call one
10 + one
end
}.new(TYPE_INT, [TYPE_INT])
end
closure_class.create(TYPE_INT, [TYPE_INT]) do |closure|
func = Function.new(closure, [TYPE_INT], TYPE_INT)
assert_raise(ArgumentError) do
@ -96,6 +100,7 @@ module Fiddle
func.call
end
end
end
def test_last_error
func = Function.new(@libc['strcpy'], [TYPE_VOIDP, TYPE_VOIDP], TYPE_VOIDP)