diff options
author | Alan Wu <XrXr@users.noreply.github.com> | 2021-10-06 15:38:33 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-06 15:38:33 -0400 |
commit | 76228191474c76810043b294a74bbb2f1808b3d9 (patch) | |
tree | 4efb8ad85ffd1750b3cd589eec96872f600d4ef7 /bootstraptest/test_ractor.rb | |
parent | d53493715cd1a1463b98291e0ad92e2723236698 (diff) |
Fix Ractor.make_shareable changing locals for Procs
env_copy() uses rb_ary_delete_at() with a loop counting up while
iterating through the list of read only locals. rb_ary_delete_at() can
shift elements in the array to an index lesser than the loop index,
causing locals to be missed and set to Qfalse in the returned
environment.
Iterate through the locals in reverse instead, this way the shifting
never happens for locals that are yet to be visited and we process all
the locals in the array.
[Bug #18023]
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/4940
Merged-By: XrXr
Diffstat (limited to 'bootstraptest/test_ractor.rb')
-rw-r--r-- | bootstraptest/test_ractor.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/bootstraptest/test_ractor.rb b/bootstraptest/test_ractor.rb index 01d02dce77..4da348df67 100644 --- a/bootstraptest/test_ractor.rb +++ b/bootstraptest/test_ractor.rb @@ -187,6 +187,28 @@ assert_equal '[:ok, :ok, :ok]', %q{ }.map(&:take) } +# Ractor.make_shareable issue for locals in proc [Bug #18023] +assert_equal '[:a, :b, :c, :d, :e]', %q{ + v1, v2, v3, v4, v5 = :a, :b, :c, :d, :e + closure = Proc.new { [v1, v2, v3, v4, v5] } + + Ractor.make_shareable(closure).call +} + +# Ractor.make_shareable issue for locals in proc [Bug #18023] +assert_equal '[:a, :b, :c, :d, :e, :f, :g]', %q{ + a = :a + closure = -> { + b, c, d = :b, :c, :d + -> { + e, f, g = :e, :f, :g + -> { [a, b, c, d, e, f, g] } + }.call + }.call + + Ractor.make_shareable(closure).call +} + ### ### # Ractor still has several memory corruption so skip huge number of tests |