From 14e8f4d5190e4ebba9de16a74bb4ed0ca632506a Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Thu, 24 Oct 2024 17:09:06 -0400 Subject: [PATCH] Make GC.latest_gc_info return :state for StackProf --- gc/mmtk.c | 11 +++++++++++ spec/mmtk.mspec | 3 --- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/gc/mmtk.c b/gc/mmtk.c index 87079c99837ed1..8b92701aae9ded 100644 --- a/gc/mmtk.c +++ b/gc/mmtk.c @@ -1223,6 +1223,17 @@ rb_gc_impl_latest_gc_info(void *objspace_ptr, VALUE hash_or_key) rb_bug("gc_info_decode: non-hash or symbol given"); } +#define SET(name, attr) \ + if (key == ID2SYM(rb_intern_const(#name))) \ + return (attr); \ + else if (hash != Qnil) \ + rb_hash_aset(hash, ID2SYM(rb_intern_const(#name)), (attr)); + + /* Hack to get StackProf working because it calls rb_gc_latest_gc_info with + * the :state key and expects a result. This always returns the :none state. */ + SET(state, ID2SYM(rb_intern_const("none"))); +#undef SET + if (!NIL_P(key)) { // Matched key should return above return Qundef; diff --git a/spec/mmtk.mspec b/spec/mmtk.mspec index 82af0c786d5b31..ac0998708cb9c6 100644 --- a/spec/mmtk.mspec +++ b/spec/mmtk.mspec @@ -1,8 +1,5 @@ # frozen_string_literal: true -# GC.latest_gc_info doesn't return anything -MSpec.register(:exclude, "CApiGCSpecs rb_gc_latest_gc_info returns a value when symbol is given") -MSpec.register(:exclude, "CApiGCSpecs rb_gc_latest_gc_info returns the populated hash when a hash is given") # Testing behaviour specific to default GC MSpec.register(:exclude, "GC.stat increases major_gc_count after GC is run") MSpec.register(:exclude, "GC.stat provides some number for heap_free_slots")