From 5427b08381fb0d644ec69d5aa94234f90a4fbed1 Mon Sep 17 00:00:00 2001 From: nagachika Date: Sat, 16 Oct 2021 13:28:27 +0900 Subject: merge revision(s) 76228191474c76810043b294a74bbb2f1808b3d9: [Backport #18023] 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] --- bootstraptest/test_ractor.rb | 22 ++++++++++++++++++++++ vm.c | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) --- bootstraptest/test_ractor.rb | 22 ++++++++++++++++++++++ version.h | 2 +- vm.c | 2 +- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/bootstraptest/test_ractor.rb b/bootstraptest/test_ractor.rb index f733877319..e4e476d560 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 diff --git a/version.h b/version.h index 1e1725ea88..288aad629b 100644 --- a/version.h +++ b/version.h @@ -12,7 +12,7 @@ # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR #define RUBY_VERSION_TEENY 3 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR -#define RUBY_PATCHLEVEL 144 +#define RUBY_PATCHLEVEL 145 #define RUBY_RELEASE_YEAR 2021 #define RUBY_RELEASE_MONTH 10 diff --git a/vm.c b/vm.c index 9ee5f1f795..c807c8afb2 100644 --- a/vm.c +++ b/vm.c @@ -1005,7 +1005,7 @@ env_copy(const VALUE *src_ep, VALUE read_only_variables) volatile VALUE prev_env = Qnil; if (read_only_variables) { - for (int i=0; i=0; i--) { ID id = SYM2ID(rb_str_intern(RARRAY_AREF(read_only_variables, i))); for (unsigned int j=0; jiseq->body->local_table_size; j++) { -- cgit v1.2.3