Fix return value of setting in GC.config

gc_config_set returned rb_gc_impl_config_get, but gc_config_get also added
the implementation key to the return value. This caused the return value
of GC.config to differ depending on whether the optional hash argument is
provided or not.
This commit is contained in:
Peter Zhu 2025-08-08 11:15:15 -04:00
parent 4775d1ffa8
commit 61fff8a92f
3 changed files with 8 additions and 11 deletions

2
gc.c
View file

@ -4357,7 +4357,7 @@ gc_config_set(rb_execution_context_t *ec, VALUE self, VALUE hash)
rb_gc_impl_config_set(objspace, hash);
return rb_gc_impl_config_get(objspace);
return Qnil;
}
static VALUE

8
gc.rb
View file

@ -312,17 +312,17 @@ module GC
# before setting this parameter to +false+.
#
def self.config hash = nil
return Primitive.gc_config_get unless hash
if(Primitive.cexpr!("RBOOL(RB_TYPE_P(hash, T_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
elsif hash != nil
raise ArgumentError
end
Primitive.gc_config_get
end
# call-seq:

View file

@ -75,12 +75,9 @@ class TestGc < Test::Unit::TestCase
GC.start
end
def test_gc_config_setting_returns_nil_for_missing_keys
missing_value = GC.config(no_such_key: true)[:no_such_key]
assert_nil(missing_value)
ensure
GC.config(full_mark: true)
GC.start
def test_gc_config_setting_returns_config_hash
hash = GC.config(no_such_key: true)
assert_equal(GC.config, hash)
end
def test_gc_config_disable_major