Skip to content

Commit b1adc15

Browse files
committed
io-console is considered Ractor-safe
1 parent 651797f commit b1adc15

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

ext/io/console/console.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,6 +1764,10 @@ io_getpass(int argc, VALUE *argv, VALUE io)
17641764
void
17651765
Init_console(void)
17661766
{
1767+
#ifdef HAVE_RB_EXT_RACTOR_SAFE
1768+
RB_EXT_RACTOR_SAFE(true);
1769+
#endif
1770+
17671771
#undef rb_intern
17681772
id_getc = rb_intern("getc");
17691773
id_gets = rb_intern("gets");

test/io/console/test_ractor.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# frozen_string_literal: true
2+
require 'test/unit'
3+
require 'rbconfig'
4+
5+
class TestIOConsoleInRactor < Test::Unit::TestCase
6+
def test_ractor
7+
ext = "/io/console.#{RbConfig::CONFIG['DLEXT']}"
8+
path = $".find {|path| path.end_with?(ext)}
9+
assert_in_out_err(%W[-r#{path}], "#{<<~"begin;"}\n#{<<~'end;'}", ["true"], [])
10+
begin;
11+
$VERBOSE = nil
12+
r = Ractor.new do
13+
$stdout.console_mode
14+
rescue SystemCallError
15+
true
16+
rescue Ractor::UnsafeError
17+
false
18+
else
19+
true # should not success
20+
end
21+
puts r.take
22+
end;
23+
end
24+
end if defined? Ractor

0 commit comments

Comments
 (0)