Skip to content

Commit e6974be

Browse files
tenderlovetekknolagibyroot
committed
Don't call hash tombstone compaction from GC compaction
Tombstone removal may possibly require allocation, and we're not allowed to allocate during GC. This commit also renames `set_compact` to `set_update_references` to differentiate tombstone removal compaction with GC object compaction. Co-Authored-By: Max Bernstein <[email protected]> Co-authored-by: Jean Boussier <[email protected]>
1 parent 9cdc465 commit e6974be

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

set.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,9 @@ set_replace_ref(st_data_t *key, st_data_t argp, int existing)
179179
}
180180

181181
static void
182-
set_compact(void *ptr)
182+
set_update_references(void *ptr)
183183
{
184184
struct set_object *sobj = ptr;
185-
set_compact_table(&sobj->table);
186185
set_foreach_with_replace(&sobj->table, set_foreach_replace, set_replace_ref, 0);
187186
}
188187

@@ -192,7 +191,7 @@ static const rb_data_type_t set_data_type = {
192191
.dmark = set_mark,
193192
.dfree = set_free,
194193
.dsize = set_size,
195-
.dcompact = set_compact,
194+
.dcompact = set_update_references,
196195
},
197196
.flags = RUBY_TYPED_EMBEDDABLE | RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_FROZEN_SHAREABLE
198197
};

test/ruby/test_set.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,19 @@ def test_reset
864864
assert_equal(klass.new([a]), set, klass.name)
865865
}
866866
end
867+
868+
def test_set_gc_compact_does_not_allocate
869+
assert_in_out_err([], <<-"end;", [], [])
870+
def x
871+
s = Set.new
872+
s << Object.new
873+
s
874+
end
875+
876+
x
877+
GC.compact
878+
end;
879+
end
867880
end
868881

869882
class TC_Enumerable < Test::Unit::TestCase

0 commit comments

Comments
 (0)