diff options
| author | Peter Zhu <peter@peterzhu.ca> | 2025-08-08 11:15:15 -0400 |
|---|---|---|
| committer | Peter Zhu <peter@peterzhu.ca> | 2025-08-11 10:20:33 -0400 |
| commit | 61fff8a92f5b7fbcdd0bea46150ce0845637483e (patch) | |
| tree | 295eb6c3908ddd1739f2f1f5a02524c4bc3786be | |
| parent | 4775d1ffa8a34f0bca3f6124c98426d56eb8e1b6 (diff) | |
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.
| -rw-r--r-- | gc.c | 2 | ||||
| -rw-r--r-- | gc.rb | 8 | ||||
| -rw-r--r-- | test/ruby/test_gc.rb | 9 |
3 files changed, 8 insertions, 11 deletions
@@ -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 @@ -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: diff --git a/test/ruby/test_gc.rb b/test/ruby/test_gc.rb index 85022cbc4d..ccccd212b6 100644 --- a/test/ruby/test_gc.rb +++ b/test/ruby/test_gc.rb @@ -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 |
