Skip to content

Commit e327026

Browse files
committed
fix: bug for gc
1 parent 1128917 commit e327026

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

benchmarks/zstd_streaming_compress_memory.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
i = 0
1616
while true do
1717
stream = Zstd::StreamingCompress.new
18-
stream << json_string
18+
stream << json_string[0, 5]
1919
res = stream.flush
20+
stream << json_string[5..-1]
2021
res << stream.finish
2122
if ((i % 1000) == 0 )
2223
GC.start

ext/zstdruby/streaming_compress.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ struct streaming_compress_t {
77
size_t buf_size;
88
};
99

10+
static void
11+
streaming_compress_mark(void *p)
12+
{
13+
struct streaming_compress_t *sc = p;
14+
// rb_gc_mark((VALUE)sc->ctx);
15+
rb_gc_mark(sc->buf);
16+
rb_gc_mark(sc->buf_size);
17+
}
18+
1019
static void
1120
streaming_compress_free(void *p)
1221
{
@@ -26,7 +35,7 @@ streaming_compress_memsize(const void *p)
2635

2736
static const rb_data_type_t streaming_compress_type = {
2837
"streaming_compress",
29-
{ 0, streaming_compress_free, streaming_compress_memsize, },
38+
{ streaming_compress_mark, streaming_compress_free, streaming_compress_memsize, },
3039
0, 0, RUBY_TYPED_FREE_IMMEDIATELY
3140
};
3241

0 commit comments

Comments
 (0)