Add missing write barrier in set_i_initialize_copy

When we copy the table from one set to another we need to run write
barriers.
This commit is contained in:
John Hawthorn 2025-06-08 12:17:53 -07:00
parent 4b80f56f60
commit c962735fe8
Notes: git 2025-06-09 17:07:00 +00:00
2 changed files with 7 additions and 0 deletions

1
set.c
View File

@ -528,6 +528,7 @@ set_i_initialize_copy(VALUE set, VALUE other)
set_free_embedded(sobj);
set_copy(&sobj->table, RSET_TABLE(other));
rb_gc_writebarrier_remember(set);
return set;
}

View File

@ -129,6 +129,12 @@ class TC_Set < Test::Unit::TestCase
assert_same(set, ret)
assert_equal(Set['a','b','c'], set)
set = Set[1,2]
ret = set.replace(Set.new('a'..'c'))
assert_same(set, ret)
assert_equal(Set['a','b','c'], set)
set = Set[1,2]
assert_raise(ArgumentError) {
set.replace(3)