Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix the exception when trying to copy procs for Ractors #13703

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions bootstraptest/test_ractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,8 @@ def test n
r = Ractor.new obj do |msg|
msg
end
rescue TypeError => e
e.message #=> no _dump_data is defined for class Thread
rescue Ractor::IsolationError => e
e.cause.message #=> no _dump_data is defined for class Thread
else
'ng'
end
Expand Down Expand Up @@ -1403,7 +1403,7 @@ class C
end
begin
Ractor.new{} << err
rescue TypeError
rescue Ractor::IsolationError
'ok'
end
}
Expand Down
7 changes: 6 additions & 1 deletion ractor.c
Original file line number Diff line number Diff line change
Expand Up @@ -1925,7 +1925,12 @@ copy_enter(VALUE obj, struct obj_traverse_replace_data *data)
return traverse_skip;
}
else {
data->replacement = rb_obj_clone(obj);
int state;
VALUE result = rb_protect(rb_obj_clone, obj, &state);
if (state) {
rb_raise(rb_eRactorIsolationError, "cannot copy %"PRIsVALUE"", obj);
}
data->replacement = result;
return traverse_cont;
}
}
Expand Down
8 changes: 6 additions & 2 deletions test/ruby/test_ractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ def test_shareability_of_curried_proc
assert_make_shareable(x)
end

def test_cannot_copy_proc
assert_unshareable(-> { }, /cannot copy/, copy: true)
end

def test_shareability_of_method_proc
str = +""

Expand Down Expand Up @@ -150,10 +154,10 @@ def assert_make_shareable(obj)
assert Ractor.shareable?(obj), "object didn't become shareable"
end

def assert_unshareable(obj, msg=nil, exception: Ractor::IsolationError)
def assert_unshareable(obj, msg=nil, copy: false, exception: Ractor::IsolationError)
refute Ractor.shareable?(obj), "object is already shareable"
assert_raise_with_message(exception, msg) do
Ractor.make_shareable(obj)
Ractor.make_shareable(obj, copy:)
end
refute Ractor.shareable?(obj), "despite raising, object became shareable"
end
Expand Down
Loading