diff --git a/set.c b/set.c index 120e2c3465bc72..221b9a07e1fb3b 100644 --- a/set.c +++ b/set.c @@ -179,10 +179,9 @@ set_replace_ref(st_data_t *key, st_data_t argp, int existing) } static void -set_compact(void *ptr) +set_update_references(void *ptr) { struct set_object *sobj = ptr; - set_compact_table(&sobj->table); set_foreach_with_replace(&sobj->table, set_foreach_replace, set_replace_ref, 0); } @@ -192,7 +191,7 @@ static const rb_data_type_t set_data_type = { .dmark = set_mark, .dfree = set_free, .dsize = set_size, - .dcompact = set_compact, + .dcompact = set_update_references, }, .flags = RUBY_TYPED_EMBEDDABLE | RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_FROZEN_SHAREABLE }; diff --git a/test/ruby/test_set.rb b/test/ruby/test_set.rb index fd3ac4d9b67dda..5d77c502e076b9 100644 --- a/test/ruby/test_set.rb +++ b/test/ruby/test_set.rb @@ -864,6 +864,19 @@ def test_reset assert_equal(klass.new([a]), set, klass.name) } end + + def test_set_gc_compact_does_not_allocate + assert_in_out_err([], <<-"end;", [], []) + def x + s = Set.new + s << Object.new + s + end + + x + GC.compact + end; + end end class TC_Enumerable < Test::Unit::TestCase