ruby-changes:64265
From: Kenta <ko1@a...>
Date: Fri, 18 Dec 2020 14:26:31 +0900 (JST)
Subject: [ruby-changes:64265] 985f0af257 (master): [strscan] Make strscan Ractor safe (#17)
https://git.ruby-lang.org/ruby.git/commit/?id=985f0af257 From 985f0af2576c4b4f9f4e75dce7299ba9d55d9419 Mon Sep 17 00:00:00 2001 From: Kenta Murata <mrkn@u...> Date: Thu, 17 Dec 2020 18:29:21 +0900 Subject: [strscan] Make strscan Ractor safe (#17) * Make strscan Ractor safe * Add test-unit in the development dependencies https://github.com/ruby/strscan/commit/3c93c2bebe diff --git a/ext/strscan/strscan.c b/ext/strscan/strscan.c index db87818..0eb51e7 100644 --- a/ext/strscan/strscan.c +++ b/ext/strscan/strscan.c @@ -1571,6 +1571,10 @@ strscan_fixed_anchor_p(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/strscan/strscan.c#L1571 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; diff --git a/ext/strscan/strscan.gemspec b/ext/strscan/strscan.gemspec index 61c28a4..734d439 100644 --- a/ext/strscan/strscan.gemspec +++ b/ext/strscan/strscan.gemspec @@ -17,4 +17,5 @@ Gem::Specification.new do |s| https://github.com/ruby/ruby/blob/trunk/ext/strscan/strscan.gemspec#L17 s.add_development_dependency "rake-compiler" s.add_development_dependency "benchmark-driver" + s.add_development_dependency "test-unit" end diff --git a/test/strscan/test_ractor.rb b/test/strscan/test_ractor.rb new file mode 100644 index 0000000..0d44242 --- /dev/null +++ b/test/strscan/test_ractor.rb @@ -0,0 +1,28 @@ https://github.com/ruby/ruby/blob/trunk/test/strscan/test_ractor.rb#L1 +# 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 -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/