mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
82cac33ecb
* gc.c (wmap_final_func): remove WeakRef object reference from the array. * gc.c (wmap_finalize): remove recycled object references from weak map hash properly. How to get object reference from object id was wrong. st_delete() doesn't work properly if key and value arguments are same. The key of obj2wmap is referenced object and the value of obj2wmap is WeakRef array. * gc.c (wmap_aset): obj2wmap should contain WeakRef array in the definition. * test/test_weakref.rb (TestWeakRef#test_not_reference_different_object): add a test for above. [ruby-core:49044] [Bug #7304] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37826 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
43 lines
959 B
Ruby
43 lines
959 B
Ruby
require 'test/unit'
|
|
require 'weakref'
|
|
|
|
class TestWeakRef < Test::Unit::TestCase
|
|
def make_weakref(level = 10)
|
|
obj = Object.new
|
|
str = obj.to_s
|
|
level.times {obj = WeakRef.new(obj)}
|
|
return WeakRef.new(obj), str
|
|
end
|
|
|
|
def test_ref
|
|
weak, str = make_weakref
|
|
assert_equal(str, weak.to_s)
|
|
end
|
|
|
|
def test_recycled
|
|
weak, str = make_weakref
|
|
assert_nothing_raised(WeakRef::RefError) {weak.to_s}
|
|
ObjectSpace.garbage_collect
|
|
ObjectSpace.garbage_collect
|
|
assert_raise(WeakRef::RefError) {weak.to_s}
|
|
end
|
|
|
|
def test_not_reference_different_object
|
|
bug7304 = '[ruby-core:49044]'
|
|
weakrefs = []
|
|
3.times do
|
|
obj = Object.new
|
|
def obj.foo; end
|
|
weakrefs << WeakRef.new(obj)
|
|
ObjectSpace.garbage_collect
|
|
end
|
|
assert_nothing_raised(NoMethodError, bug7304) {
|
|
weakrefs.each do |weak|
|
|
begin
|
|
weak.foo
|
|
rescue WeakRef::RefError
|
|
end
|
|
end
|
|
}
|
|
end
|
|
end
|