Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Ractor.make_shareable changing locals for Procs #4940

Merged
merged 1 commit into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions bootstraptest/test_ractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,28 @@
}.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
Expand Down
2 changes: 1 addition & 1 deletion vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,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<RARRAY_LENINT(read_only_variables); i++) {
for (int i=RARRAY_LENINT(read_only_variables)-1; i>=0; i--) {
ID id = SYM2ID(rb_str_intern(RARRAY_AREF(read_only_variables, i)));

for (unsigned int j=0; j<src_env->iseq->body->local_table_size; j++) {
Expand Down