Skip to content

Commit

Permalink
Make strscan Ractor safe (#17)
Browse files Browse the repository at this point in the history
* Make strscan Ractor safe

* Add test-unit in the development dependencies
  • Loading branch information
mrkn committed Dec 17, 2020
1 parent 2c90471 commit 3c93c2b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions Rakefile
Expand Up @@ -8,6 +8,7 @@ Rake::ExtensionTask.new("strscan")

desc "Run test"
task :test do
ENV["RUBYOPT"] = "-Ilib"
ruby("run-test.rb")
end

Expand Down
4 changes: 4 additions & 0 deletions ext/strscan/strscan.c
Expand Up @@ -1568,6 +1568,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;
Expand Down
1 change: 1 addition & 0 deletions strscan.gemspec
Expand Up @@ -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
28 changes: 28 additions & 0 deletions test/strscan/test_ractor.rb
@@ -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

0 comments on commit 3c93c2b

Please sign in to comment.