summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorshirosaki <shirosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-24 12:26:54 +0000
committershirosaki <shirosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-24 12:26:54 +0000
commit1cdeab5cdd4b84cc0d97ee1a148beeb11bdd2d44 (patch)
treedb35f8ee395b34c1b1a8b8a82a13afb8c4fd2ef3 /test
parente6c2ffa981f00c249a9a6a1595ecab18d0a6f741 (diff)
Fix WeakRef finalize
* array.c (rb_ary_delete_same_obj): new function for WeakRef. This deletes same objects as item argument in the array. * internal.h (rb_ary_delete_same_obj): add a declaration. * gc.c (wmap_final_func): remove WeakRef object reference from the array. rb_ary_delete() is not usable because it uses rb_equal() to compare object references. * 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, TestWeakRef#test_weakref_finalize): add tests for above. [ruby-core:49044] [Bug #7304] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37834 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/test_weakref.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/test/test_weakref.rb b/test/test_weakref.rb
index 0f943cdf12..d0d40d470b 100644
--- a/test/test_weakref.rb
+++ b/test/test_weakref.rb
@@ -1,5 +1,6 @@
require 'test/unit'
require 'weakref'
+require_relative './ruby/envutil'
class TestWeakRef < Test::Unit::TestCase
def make_weakref(level = 10)
@@ -21,4 +22,35 @@ class TestWeakRef < Test::Unit::TestCase
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
+
+ def test_weakref_finalize
+ bug7304 = '[ruby-core:49044]'
+ assert_normal_exit %q{
+ require 'weakref'
+ obj = Object.new
+ 3.times do
+ WeakRef.new(obj)
+ ObjectSpace.garbage_collect
+ end
+ }, bug7304
+ end
end