Skip to content

Commit

Permalink
Merge pull request #52 from Watson1978/ractor
Browse files Browse the repository at this point in the history
Add Ractor support
  • Loading branch information
SpringMT authored Sep 3, 2022
2 parents 44ac00f + 3a49d9f commit 198582d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ext/zstdruby/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ void zstd_ruby_streaming_decompress_init(void);
void
Init_zstdruby(void)
{
#ifdef HAVE_RB_EXT_RACTOR_SAFE
rb_ext_ractor_safe(true);
#endif

rb_mZstd = rb_define_module("Zstd");
zstd_ruby_init();
zstd_ruby_streaming_compress_init();
Expand Down
13 changes: 13 additions & 0 deletions spec/zstd-ruby-streaming-compress_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,18 @@
expect(Zstd.decompress(res)).to eq('abcdef')
end
end

if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.0.0')
describe 'Ractor' do
it 'should be supported' do
r = Ractor.new {
stream = Zstd::StreamingCompress.new(5)
stream << "abc" << "def"
res = stream.finish
}
expect(Zstd.decompress(r.take)).to eq('abcdef')
end
end
end
end

16 changes: 16 additions & 0 deletions spec/zstd-ruby-streaming-decompress_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,21 @@
end
end

if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.0.0')
describe 'Ractor' do
it 'should be supported' do
r = Ractor.new {
cstr = Zstd.compress('foo bar buzz')
stream = Zstd::StreamingDecompress.new
result = ''
result << stream.decompress(cstr[0, 5])
result << stream.decompress(cstr[5, 5])
result << stream.decompress(cstr[10..-1])
result
}
expect(r.take).to eq('foo bar buzz')
end
end
end
end

9 changes: 9 additions & 0 deletions spec/zstd-ruby_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,14 @@ def to_str
expect(Zstd.decompress(DummyForDecompress.new)).to eq('abc')
end
end

if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.0.0')
describe 'Ractor' do
it 'should be supported' do
r = Ractor.new { Zstd.compress('abc') }
expect(Zstd.decompress(r.take)).to eq('abc')
end
end
end
end

0 comments on commit 198582d

Please sign in to comment.