diff options
-rw-r--r-- | ext/io/console/console.c | 4 | ||||
-rw-r--r-- | test/io/console/test_ractor.rb | 24 |
2 files changed, 28 insertions, 0 deletions
diff --git a/ext/io/console/console.c b/ext/io/console/console.c index 38f6b5b7af..489869894e 100644 --- a/ext/io/console/console.c +++ b/ext/io/console/console.c @@ -1764,6 +1764,10 @@ io_getpass(int argc, VALUE *argv, VALUE io) void Init_console(void) { +#ifdef HAVE_RB_EXT_RACTOR_SAFE + RB_EXT_RACTOR_SAFE(true); +#endif + #undef rb_intern id_getc = rb_intern("getc"); id_gets = rb_intern("gets"); diff --git a/test/io/console/test_ractor.rb b/test/io/console/test_ractor.rb new file mode 100644 index 0000000000..0bbd39cdee --- /dev/null +++ b/test/io/console/test_ractor.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true +require 'test/unit' +require 'rbconfig' + +class TestIOConsoleInRactor < Test::Unit::TestCase + def test_ractor + ext = "/io/console.#{RbConfig::CONFIG['DLEXT']}" + path = $".find {|path| path.end_with?(ext)} + assert_in_out_err(%W[-r#{path}], "#{<<~"begin;"}\n#{<<~'end;'}", ["true"], []) + begin; + $VERBOSE = nil + r = Ractor.new do + $stdout.console_mode + rescue SystemCallError + true + rescue Ractor::UnsafeError + false + else + true # should not success + end + puts r.take + end; + end +end if defined? Ractor |