Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion ext/zstdruby/streaming_decompress.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ struct streaming_decompress_t {
size_t buf_size;
};

static void
streaming_decompress_mark(void *p)
{
struct streaming_decompress_t *sd = p;
// rb_gc_mark((VALUE)sd->ctx);
rb_gc_mark(sd->buf);
// rb_gc_mark(sd->buf_size);
}

static void
streaming_decompress_free(void *p)
{
Expand All @@ -25,7 +34,7 @@ streaming_decompress_memsize(const void *p)

static const rb_data_type_t streaming_decompress_type = {
"streaming_decompress",
{ 0, streaming_decompress_free, streaming_decompress_memsize, },
{ streaming_decompress_mark, streaming_decompress_free, streaming_decompress_memsize, },
0, 0, RUBY_TYPED_FREE_IMMEDIATELY
};

Expand Down
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 @@ -16,5 +16,21 @@
expect(result).to eq(str)
end
end

describe 'streaming decompress + GC.compact' do
it 'shoud work' do
# str = SecureRandom.hex(150)
str = "foo bar buzz" * 100
cstr = Zstd.compress(str)
stream = Zstd::StreamingDecompress.new
result = ''
result << stream.decompress(cstr[0, 5])
result << stream.decompress(cstr[5, 5])
GC.compact
result << stream.decompress(cstr[10..-1])
expect(result).to eq(str)
end
end

end