diff options
author | Aaron Patterson <tenderlove@ruby-lang.org> | 2021-08-31 16:58:29 -0700 |
---|---|---|
committer | Aaron Patterson <tenderlove@ruby-lang.org> | 2021-09-01 10:58:20 -0700 |
commit | 8db269edb3550a85dfab9b193ea115ca36912ced (patch) | |
tree | b50e4f3043f1aa0a7d3c6f87c00cdfe6832b9dcc /test/-ext-/array/test_to_ary_concat.rb | |
parent | 0aa82b592fc3296ffde1f3fff59018a998c3ade0 (diff) | |
download | ruby-8db269edb3550a85dfab9b193ea115ca36912ced.tar.gz |
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]
Diffstat (limited to 'test/-ext-/array/test_to_ary_concat.rb')
-rw-r--r-- | test/-ext-/array/test_to_ary_concat.rb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/test/-ext-/array/test_to_ary_concat.rb b/test/-ext-/array/test_to_ary_concat.rb new file mode 100644 index 0000000000..feb1bc1109 --- /dev/null +++ b/test/-ext-/array/test_to_ary_concat.rb @@ -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 |