Skip to content

Commit 985f0af

Browse files
committed
[strscan] Make strscan Ractor safe (#17)
* Make strscan Ractor safe * Add test-unit in the development dependencies ruby/strscan@3c93c2bebe
1 parent cfa124e commit 985f0af

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

ext/strscan/strscan.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,6 +1571,10 @@ strscan_fixed_anchor_p(VALUE self)
15711571
void
15721572
Init_strscan(void)
15731573
{
1574+
#ifdef HAVE_RB_EXT_RACTOR_SAFE
1575+
rb_ext_ractor_safe(true);
1576+
#endif
1577+
15741578
#undef rb_intern
15751579
ID id_scanerr = rb_intern("ScanError");
15761580
VALUE tmp;

ext/strscan/strscan.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ Gem::Specification.new do |s|
1717

1818
s.add_development_dependency "rake-compiler"
1919
s.add_development_dependency "benchmark-driver"
20+
s.add_development_dependency "test-unit"
2021
end

test/strscan/test_ractor.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# frozen_string_literal: true
2+
require 'test/unit'
3+
4+
class TestStringScannerRactor < Test::Unit::TestCase
5+
def setup
6+
skip unless defined? Ractor
7+
end
8+
9+
def test_ractor
10+
assert_in_out_err([], <<-"end;", ["stra", " ", "strb", " ", "strc"], [])
11+
require "strscan"
12+
$VERBOSE = nil
13+
r = Ractor.new do
14+
s = StringScanner.new("stra strb strc", true)
15+
[
16+
s.scan(/\\w+/),
17+
s.scan(/\\s+/),
18+
s.scan(/\\w+/),
19+
s.scan(/\\s+/),
20+
s.scan(/\\w+/),
21+
s.scan(/\\w+/),
22+
s.scan(/\\w+/)
23+
]
24+
end
25+
puts r.take.compact
26+
end;
27+
end
28+
end

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy