Skip to content

Commit a1e43dc

Browse files
authored
Merge pull request #58 from Watson1978/gc-compaction
Support GC compaction
2 parents 682f60b + 3dc1036 commit a1e43dc

File tree

3 files changed

+48
-6
lines changed

3 files changed

+48
-6
lines changed

ext/zstdruby/extconf.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
require "mkmf"
22

3+
have_func('rb_gc_mark_movable')
4+
35
$CFLAGS = '-I. -O3 -std=c99 -DZSTD_STATIC_LINKING_ONLY'
46
$CPPFLAGS += " -fdeclspec" if CONFIG['CXX'] =~ /clang/
57

ext/zstdruby/streaming_compress.c

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ static void
1111
streaming_compress_mark(void *p)
1212
{
1313
struct streaming_compress_t *sc = p;
14+
#ifdef HAVE_RB_GC_MARK_MOVABLE
15+
rb_gc_mark_movable(sc->buf);
16+
#else
1417
rb_gc_mark(sc->buf);
18+
#endif
1519
}
1620

1721
static void
@@ -31,10 +35,26 @@ streaming_compress_memsize(const void *p)
3135
return sizeof(struct streaming_compress_t);
3236
}
3337

38+
#ifdef HAVE_RB_GC_MARK_MOVABLE
39+
static size_t
40+
streaming_compress_compact(void *p)
41+
{
42+
struct streaming_compress_t *sc = p;
43+
sc->buf = rb_gc_location(sc->buf);
44+
}
45+
#endif
46+
3447
static const rb_data_type_t streaming_compress_type = {
35-
"streaming_compress",
36-
{ streaming_compress_mark, streaming_compress_free, streaming_compress_memsize, },
37-
0, 0, RUBY_TYPED_FREE_IMMEDIATELY
48+
"streaming_compress",
49+
{
50+
streaming_compress_mark,
51+
streaming_compress_free,
52+
streaming_compress_memsize,
53+
#ifdef HAVE_RB_GC_MARK_MOVABLE
54+
streaming_compress_compact,
55+
#endif
56+
},
57+
0, 0, RUBY_TYPED_FREE_IMMEDIATELY
3858
};
3959

4060
static VALUE

ext/zstdruby/streaming_decompress.c

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ static void
1010
streaming_decompress_mark(void *p)
1111
{
1212
struct streaming_decompress_t *sd = p;
13+
#ifdef HAVE_RB_GC_MARK_MOVABLE
14+
rb_gc_mark_movable(sd->buf);
15+
#else
1316
rb_gc_mark(sd->buf);
17+
#endif
1418
}
1519

1620
static void
@@ -30,10 +34,26 @@ streaming_decompress_memsize(const void *p)
3034
return sizeof(struct streaming_decompress_t);
3135
}
3236

37+
#ifdef HAVE_RB_GC_MARK_MOVABLE
38+
static size_t
39+
streaming_decompress_compact(void *p)
40+
{
41+
struct streaming_decompress_t *sd = p;
42+
sd->buf = rb_gc_location(sd->buf);
43+
}
44+
#endif
45+
3346
static const rb_data_type_t streaming_decompress_type = {
34-
"streaming_decompress",
35-
{ streaming_decompress_mark, streaming_decompress_free, streaming_decompress_memsize, },
36-
0, 0, RUBY_TYPED_FREE_IMMEDIATELY
47+
"streaming_decompress",
48+
{
49+
streaming_decompress_mark,
50+
streaming_decompress_free,
51+
streaming_decompress_memsize,
52+
#ifdef HAVE_RB_GC_MARK_MOVABLE
53+
streaming_decompress_compact,
54+
#endif
55+
},
56+
0, 0, RUBY_TYPED_FREE_IMMEDIATELY
3757
};
3858

3959
static VALUE

0 commit comments

Comments
 (0)