1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[strscan] Make strscan Ractor safe (#17)

* Make strscan Ractor safe

* Add test-unit in the development dependencies

https://github.com/ruby/strscan/commit/3c93c2bebe
This commit is contained in:
Kenta Murata 2020-12-17 18:29:21 +09:00 committed by Kenta Murata
parent cfa124ef05
commit 985f0af257
No known key found for this signature in database
GPG key ID: CEFE8AFB6081B062
3 changed files with 33 additions and 0 deletions

View file

@ -1571,6 +1571,10 @@ strscan_fixed_anchor_p(VALUE self)
void
Init_strscan(void)
{
#ifdef HAVE_RB_EXT_RACTOR_SAFE
rb_ext_ractor_safe(true);
#endif
#undef rb_intern
ID id_scanerr = rb_intern("ScanError");
VALUE tmp;

View file

@ -17,4 +17,5 @@ Gem::Specification.new do |s|
s.add_development_dependency "rake-compiler"
s.add_development_dependency "benchmark-driver"
s.add_development_dependency "test-unit"
end

View file

@ -0,0 +1,28 @@
# frozen_string_literal: true
require 'test/unit'
class TestStringScannerRactor < Test::Unit::TestCase
def setup
skip unless defined? Ractor
end
def test_ractor
assert_in_out_err([], <<-"end;", ["stra", " ", "strb", " ", "strc"], [])
require "strscan"
$VERBOSE = nil
r = Ractor.new do
s = StringScanner.new("stra strb strc", true)
[
s.scan(/\\w+/),
s.scan(/\\s+/),
s.scan(/\\w+/),
s.scan(/\\s+/),
s.scan(/\\w+/),
s.scan(/\\w+/),
s.scan(/\\w+/)
]
end
puts r.take.compact
end;
end
end