diff options
author | Jean Boussier <byroot@ruby-lang.org> | 2023-11-22 09:16:43 +0100 |
---|---|---|
committer | Jean Boussier <jean.boussier@gmail.com> | 2023-11-22 10:24:35 +0100 |
commit | 6391ae9ebc0b7a6668e57aa9f3c7b76ff83fab70 (patch) | |
tree | 8ff9da8f72febd8d7fe0d71b44111ac8acb19429 | |
parent | 2d7fb9c2fa5ab6c967f8ff1bc350ce5d3d5344a2 (diff) | |
download | ruby-6391ae9ebc0b7a6668e57aa9f3c7b76ff83fab70.tar.gz |
objspace_dump.c: dump call cache ids with dump_append_id
Not all `ID` have an associated string.
Fixes a SEGFAULT in ObjectSpace.dump_all spec.
-rw-r--r-- | ext/objspace/objspace_dump.c | 9 | ||||
-rw-r--r-- | test/objspace/test_objspace.rb | 4 |
2 files changed, 7 insertions, 6 deletions
diff --git a/ext/objspace/objspace_dump.c b/ext/objspace/objspace_dump.c index 9eb14be9e3..866a49eff4 100644 --- a/ext/objspace/objspace_dump.c +++ b/ext/objspace/objspace_dump.c @@ -366,8 +366,9 @@ dump_append_string_content(struct dump_config *dc, VALUE obj) static inline void dump_append_id(struct dump_config *dc, ID id) { - if (is_instance_id(id)) { - dump_append_string_value(dc, rb_sym2str(ID2SYM(id))); + VALUE str = rb_sym2str(ID2SYM(id)); + if (RTEST(str)) { + dump_append_string_value(dc, str); } else { dump_append(dc, "\"ID_INTERNAL("); @@ -443,7 +444,7 @@ dump_object(VALUE obj, struct dump_config *dc) mid = vm_ci_mid((const struct rb_callinfo *)obj); if (mid != 0) { dump_append(dc, ", \"mid\":"); - dump_append_string_value(dc, rb_id2str(mid)); + dump_append_id(dc, mid); } break; @@ -451,7 +452,7 @@ dump_object(VALUE obj, struct dump_config *dc) mid = vm_cc_cme((const struct rb_callcache *)obj)->called_id; if (mid != 0) { dump_append(dc, ", \"called_id\":"); - dump_append_string_value(dc, rb_id2str(mid)); + dump_append_id(dc, mid); VALUE klass = ((const struct rb_callcache *)obj)->klass; if (klass != 0) { diff --git a/test/objspace/test_objspace.rb b/test/objspace/test_objspace.rb index 1f1709fb76..5f7bfd0971 100644 --- a/test/objspace/test_objspace.rb +++ b/test/objspace/test_objspace.rb @@ -563,7 +563,7 @@ class TestObjSpace < Test::Unit::TestCase end def test_dump_callinfo_includes_mid - assert_in_out_err(%w[-robjspace], "#{<<-"begin;"}\n#{<<-'end;'}") do |output, error| + assert_in_out_err(%w[-robjspace --disable-gems], "#{<<-"begin;"}\n#{<<-'end;'}") do |output, error| begin; class Foo def foo @@ -579,7 +579,7 @@ class TestObjSpace < Test::Unit::TestCase end; assert_empty error assert(output.count > 1) - assert_equal 1, output.count { |l| l.include?('"mid":"baz"') } + assert_includes output.grep(/"imemo_type":"callinfo"/).join("\n"), '"mid":"baz"' end end |