From 42501015b4ffac67671cc5e1daedbacf5840d71b Mon Sep 17 00:00:00 2001 From: Matt Valentine-House Date: Mon, 11 Nov 2024 12:04:12 +0000 Subject: [PATCH] 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. --- gc.rb | 10 +++++++++- test/ruby/test_gc.rb | 4 +--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/gc.rb b/gc.rb index 2a75e166ce..f3221c5761 100644 --- a/gc.rb +++ b/gc.rb @@ -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: diff --git a/test/ruby/test_gc.rb b/test/ruby/test_gc.rb index 1eb5451b3f..72fab5c43c 100644 --- a/test/ruby/test_gc.rb +++ b/test/ruby/test_gc.rb @@ -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