From ef9301a6b747035a113f3c9dfb805214e9285026 Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Wed, 11 Jun 2025 13:35:28 -0700 Subject: [PATCH] Ensure crr->feature is an fstring --- ractor.c | 4 ++-- test/ruby/test_ractor.rb | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/ractor.c b/ractor.c index 694cae5a00..2b9d5b3d5b 100644 --- a/ractor.c +++ b/ractor.c @@ -2339,8 +2339,8 @@ rb_ractor_require(VALUE feature) VALUE crr_obj = TypedData_Make_Struct(0, struct cross_ractor_require, &cross_ractor_require_data_type, crr); FL_SET_RAW(crr_obj, RUBY_FL_SHAREABLE); - // TODO: make feature shareable - crr->feature = feature; + // Convert feature to proper file path and make it shareable as fstring + crr->feature = rb_fstring(FilePathValue(feature)); crr->port = ractor_port_new(GET_RACTOR()); crr->result = Qundef; crr->exception = Qundef; diff --git a/test/ruby/test_ractor.rb b/test/ruby/test_ractor.rb index 9ad74ef3c9..e463b504d1 100644 --- a/test/ruby/test_ractor.rb +++ b/test/ruby/test_ractor.rb @@ -118,6 +118,21 @@ class TestRactor < Test::Unit::TestCase RUBY end + def test_require_non_string + assert_ractor(<<~'RUBY') + require "tempfile" + require "pathname" + f = Tempfile.new(["file_to_require_from_ractor", ".rb"]) + f.write("puts 'success'") + f.flush + result = Ractor.new(f.path) do |path| + require Pathname.new(path) + "success" + end.value + assert_equal "success", result + RUBY + end + def assert_make_shareable(obj) refute Ractor.shareable?(obj), "object was already shareable" Ractor.make_shareable(obj)