diff options
-rw-r--r-- | ext/objspace/objspace_dump.c | 10 | ||||
-rw-r--r-- | test/objspace/test_objspace.rb | 21 |
2 files changed, 28 insertions, 3 deletions
diff --git a/ext/objspace/objspace_dump.c b/ext/objspace/objspace_dump.c index 14d78c862b..50dead5773 100644 --- a/ext/objspace/objspace_dump.c +++ b/ext/objspace/objspace_dump.c @@ -379,6 +379,7 @@ dump_object(VALUE obj, struct dump_config *dc) rb_io_t *fptr; ID flags[RB_OBJ_GC_FLAGS_MAX]; size_t n, i; + ID mid; if (SPECIAL_CONST_P(obj)) { dump_append_special_const(dc, obj); @@ -433,9 +434,12 @@ dump_object(VALUE obj, struct dump_config *dc) switch (imemo_type(obj)) { case imemo_callinfo: - dump_append(dc, ", \"mid\":\""); - dump_append(dc, RSTRING_PTR(rb_id2str(vm_ci_mid((const struct rb_callinfo *)obj)))); - dump_append(dc, "\""); + mid = vm_ci_mid((const struct rb_callinfo *)obj); + if (mid != 0) { + dump_append(dc, ", \"mid\":\""); + dump_append(dc, rb_id2name(mid)); + dump_append(dc, "\""); + } break; default: diff --git a/test/objspace/test_objspace.rb b/test/objspace/test_objspace.rb index 43ccac7920..bc6799b49f 100644 --- a/test/objspace/test_objspace.rb +++ b/test/objspace/test_objspace.rb @@ -562,6 +562,27 @@ class TestObjSpace < Test::Unit::TestCase end end + def test_dump_callinfo_includes_mid + assert_in_out_err(%w[-robjspace], "#{<<-"begin;"}\n#{<<-'end;'}") do |output, error| + begin; + class Foo + def foo + super(bar: 123) # should not crash on 0 mid + end + + def bar + baz(bar: 123) # mid: baz + end + end + + ObjectSpace.dump_all(output: $stdout) + end; + assert_empty error + assert(output.count > 1) + assert_equal 1, output.count { |l| l.include?('"mid":"baz"') } + end + end + def test_dump_string_coderange assert_includes ObjectSpace.dump("TEST STRING"), '"coderange":"7bit"' unknown = "TEST STRING".dup.force_encoding(Encoding::BINARY) |