Guard array when appending

This prevents early collection of the array.  The GC doesn't see the
array on the stack when Ruby is compiled with optimizations enabled

Thanks @jhaberman for the test case

[ruby-core:105099] [Bug #18140]
This commit is contained in:
Aaron Patterson 2021-08-31 16:58:29 -07:00
parent 0aa82b592f
commit 8db269edb3
No known key found for this signature in database
GPG key ID: 953170BCB4FFAFC6
4 changed files with 407 additions and 0 deletions

View file

@ -0,0 +1,20 @@
# frozen_string_literal: false
require 'test/unit'
require '-test-/array/to_ary_concat'
class TestConcatStress < Test::Unit::TestCase
def setup
@stress_level = GC.stress
GC.stress = true
end
def teardown
GC.stress = @stress_level
end
def test_concat
arr = [nil]
bar = Bug::Bar.new
arr.concat(bar)
end
end