Skip to content

Commit

Permalink
Make GC.latest_gc_info return :state for StackProf
Browse files Browse the repository at this point in the history
  • Loading branch information
peterzhu2118 committed Oct 24, 2024
1 parent 612beaa commit 14e8f4d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
11 changes: 11 additions & 0 deletions gc/mmtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 0 additions & 3 deletions spec/mmtk.mspec
Original file line number Diff line number Diff line change
@@ -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")
Expand Down

0 comments on commit 14e8f4d

Please sign in to comment.