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); rb_gc_impl_config_set(objspace, hash);
return rb_gc_impl_config_get(objspace); return Qnil;
} }
static VALUE static VALUE

8
gc.rb
View file

@ -312,17 +312,17 @@ module GC
# before setting this parameter to +false+. # before setting this parameter to +false+.
# #
def self.config hash = nil 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) if hash.include?(:implementation)
raise ArgumentError, 'Attempting to set read-only key "Implementation"' raise ArgumentError, 'Attempting to set read-only key "Implementation"'
end end
Primitive.gc_config_set hash Primitive.gc_config_set hash
else elsif hash != nil
raise ArgumentError raise ArgumentError
end end
Primitive.gc_config_get
end end
# call-seq: # call-seq:

View file

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