summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authorYusuke Endoh <mame@ruby-lang.org>2021-11-09 17:06:01 +0900
committerYusuke Endoh <mame@ruby-lang.org>2021-11-10 10:08:30 +0900
commit5c892da7d7974aeed8e7dd97bb31d2394cc19356 (patch)
tree4bbfbe05b8c6704ce4b8333b7c53a437e89eea17 /test/ruby
parent0d3898ec7b94b737fd9e0a9df1d0a944a9709564 (diff)
class.c: descendants must not cause GC until the result array is created
Follow up of 428227472fc6563046d8138aab17f07bef6af753. The previous fix uses `rb_ary_new_from_values` to create the result array, but it may trigger the GC. This second try is to create the result array by `rb_ary_new_capa` before the second iteration, and assume that `rb_ary_push` does not trigger GC. This assumption is very fragile, so should be improved in future. [Bug #18282] [Feature #14394]
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/5097
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_class.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/test/ruby/test_class.rb b/test/ruby/test_class.rb
index 034f4c6d20..4ae230f91e 100644
--- a/test/ruby/test_class.rb
+++ b/test/ruby/test_class.rb
@@ -761,4 +761,12 @@ class TestClass < Test::Unit::TestCase
100000.times { Class.new(c) }
assert(c.descendants.size <= 100000)
end
+
+ def test_descendants_gc_stress
+ 10000.times do
+ c = Class.new
+ 100.times { Class.new(c) }
+ assert(c.descendants.size <= 100)
+ end
+ end
end