rb_raise when attempting to set the GC implementation name

Instead of silently ignoring the key, we should raise to clearly tell
the user that this key is read-only.
This commit is contained in:
Matt Valentine-House 2024-11-11 12:04:12 +00:00
parent 6795fc4981
commit 42501015b4
Notes: git 2024-11-14 10:46:53 +00:00
2 changed files with 10 additions and 4 deletions

10
gc.rb
View File

@ -306,7 +306,15 @@ module GC
def self.config hash = nil
return Primitive.gc_config_get unless hash
Primitive.gc_config_set hash
if(Primitive.cexpr!("RBOOL(RB_TYPE_P(hash, T_HASH))"))
if hash.include?(:implementation)
raise ArgumentError, 'Attempting to set read-only key "Implementation"'
end
Primitive.gc_config_set hash
else
raise ArgumentError
end
end
# call-seq:

View File

@ -127,9 +127,7 @@ class TestGc < Test::Unit::TestCase
def test_gc_config_implementation_is_readonly
omit unless /darwin|linux/.match(RUBY_PLATFORM)
impl = GC.config[:implementation]
GC.config(implementation: "somethingelse")
assert_equal(impl, GC.config[:implementation])
assert_raise(ArgumentError) { GC.config(implementation: "somethingelse") }
end
def test_start_full_mark