diff options
author | Yusuke Endoh <mame@ruby-lang.org> | 2021-11-02 19:23:36 +0900 |
---|---|---|
committer | Yusuke Endoh <mame@ruby-lang.org> | 2021-11-09 16:11:10 +0900 |
commit | 428227472fc6563046d8138aab17f07bef6af753 (patch) | |
tree | 57e713aa4a0c6192198ea7183f486e561b30a820 /test/ruby/test_class.rb | |
parent | 3ff0a0b40c2e1fbdad2286f1dafe837f822d0e0d (diff) | |
download | ruby-428227472fc6563046d8138aab17f07bef6af753.tar.gz |
class.c: calculate the length of Class.descendants in advance
GC must not be triggered during callback of rb_class_foreach_subclass.
To prevent GC, we can not use rb_ary_push. Instead, this changeset calls
rb_class_foreach_subclass twice: first counts the subclasses, then
allocates a buffer (which may cause GC and reduce subclasses, but not
increase), and finally stores the subclasses to the buffer.
[Bug #18282] [Feature #14394]
Diffstat (limited to 'test/ruby/test_class.rb')
-rw-r--r-- | test/ruby/test_class.rb | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/test/ruby/test_class.rb b/test/ruby/test_class.rb index 96bca08601..034f4c6d20 100644 --- a/test/ruby/test_class.rb +++ b/test/ruby/test_class.rb @@ -755,4 +755,10 @@ class TestClass < Test::Unit::TestCase assert_include(object_descendants, sc) assert_include(object_descendants, ssc) end + + def test_descendants_gc + c = Class.new + 100000.times { Class.new(c) } + assert(c.descendants.size <= 100000) + end end |