Skip to content

Commit 61fff8a

Browse files
committed
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.
1 parent 4775d1f commit 61fff8a

3 files changed

Lines changed: 8 additions & 11 deletions

File tree

gc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4357,7 +4357,7 @@ gc_config_set(rb_execution_context_t *ec, VALUE self, VALUE hash)
43574357

43584358
rb_gc_impl_config_set(objspace, hash);
43594359

4360-
return rb_gc_impl_config_get(objspace);
4360+
return Qnil;
43614361
}
43624362

43634363
static VALUE

gc.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,17 +312,17 @@ def self.stat_heap heap_name = nil, hash_or_key = nil
312312
# before setting this parameter to +false+.
313313
#
314314
def self.config hash = nil
315-
return Primitive.gc_config_get unless hash
316-
317-
if(Primitive.cexpr!("RBOOL(RB_TYPE_P(hash, T_HASH))"))
315+
if Primitive.cexpr!("RBOOL(RB_TYPE_P(hash, T_HASH))")
318316
if hash.include?(:implementation)
319317
raise ArgumentError, 'Attempting to set read-only key "Implementation"'
320318
end
321319

322320
Primitive.gc_config_set hash
323-
else
321+
elsif hash != nil
324322
raise ArgumentError
325323
end
324+
325+
Primitive.gc_config_get
326326
end
327327

328328
# call-seq:

test/ruby/test_gc.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,9 @@ def test_gc_config_setting_returns_updated_config_hash
7575
GC.start
7676
end
7777

78-
def test_gc_config_setting_returns_nil_for_missing_keys
79-
missing_value = GC.config(no_such_key: true)[:no_such_key]
80-
assert_nil(missing_value)
81-
ensure
82-
GC.config(full_mark: true)
83-
GC.start
78+
def test_gc_config_setting_returns_config_hash
79+
hash = GC.config(no_such_key: true)
80+
assert_equal(GC.config, hash)
8481
end
8582

8683
def test_gc_config_disable_major

0 commit comments

Comments
 (0)