summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenta Murata <mrkn@mrkn.jp>2020-12-17 10:05:07 +0900
committerKenta Murata <mrkn@mrkn.jp>2020-12-18 22:00:07 +0900
commit3d3194412918012ddab185751b84ebb64fe6e5d5 (patch)
treef841830f40a363a07a4a31c1e15da8191d768ca3
parent14ca7f633cae9938b7d8bc722fe1c5c96f6bcd95 (diff)
[stringio] Make stringio Ractor safe
https://github.com/ruby/stringio/commit/ee3fec7512 https://github.com/ruby/stringio/commit/18dcd045ef https://github.com/ruby/stringio/commit/18dcd045ef
-rw-r--r--ext/stringio/stringio.c5
-rw-r--r--test/stringio/test_ractor.rb23
2 files changed, 28 insertions, 0 deletions
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c
index bb7c0e6e4e..228063d79b 100644
--- a/ext/stringio/stringio.c
+++ b/ext/stringio/stringio.c
@@ -1750,6 +1750,11 @@ void
Init_stringio(void)
{
#undef rb_intern
+
+#ifdef HAVE_RB_EXT_RACTOR_SAFE
+ rb_ext_ractor_safe(true);
+#endif
+
VALUE StringIO = rb_define_class("StringIO", rb_cData);
rb_define_const(StringIO, "VERSION", rb_str_new_cstr(STRINGIO_VERSION));
diff --git a/test/stringio/test_ractor.rb b/test/stringio/test_ractor.rb
new file mode 100644
index 0000000000..1c334e2c3f
--- /dev/null
+++ b/test/stringio/test_ractor.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+require 'test/unit'
+
+class TestStringIOInRactor < Test::Unit::TestCase
+ def setup
+ omit unless defined? Ractor
+ end
+
+ def test_ractor
+ assert_in_out_err([], <<-"end;", ["true"], [])
+ require "stringio"
+ $VERBOSE = nil
+ r = Ractor.new do
+ io = StringIO.new("")
+ io.puts "abc"
+ io.truncate(0)
+ io.puts "def"
+ "\0\0\0\0def\n" == io.string
+ end
+ puts r.take
+ end;
+ end
+end