diff --git a/ext/objspace/objspace_dump.c b/ext/objspace/objspace_dump.c index 4e46988..798d0da 100644 --- a/ext/objspace/objspace_dump.c +++ b/ext/objspace/objspace_dump.c @@ -92,6 +92,18 @@ dump_append_string_value(struct dump_config *dc, VALUE obj) static inline const char * obj_type(VALUE obj) { + if (IMMEDIATE_P(obj)) { + if (FIXNUM_P(obj)) return "FIXNUM"; + if (FLONUM_P(obj)) return "FLOAT"; + if (obj == Qtrue) return "TRUE"; + if (STATIC_SYM_P(obj)) return "SYMBOL"; + if (obj == Qundef) return "UNDEF"; + } + else if (!RTEST(obj)) { + if (obj == Qnil) return "NIL"; + if (obj == Qfalse) return "FALSE"; + } + switch (BUILTIN_TYPE(obj)) { #define CASE_TYPE(type) case T_##type: return #type; break CASE_TYPE(NONE); @@ -150,7 +162,7 @@ dump_object(VALUE obj, struct dump_config *dc) size_t n, i; if (SPECIAL_CONST_P(obj)) { - dump_append(dc, "{}"); + dump_append(dc, "{\"type\":\"%s\"}", obj_type(obj)); return; } diff --git a/test/objspace/test_objspace.rb b/test/objspace/test_objspace.rb index 01f31cc..d5c8cb4 100644 --- a/test/objspace/test_objspace.rb +++ b/test/objspace/test_objspace.rb @@ -245,11 +245,11 @@ class TestObjSpace < Test::Unit::TestCase def test_dump_special_consts # [ruby-core:69692] [Bug #11291] - assert_equal('{}', ObjectSpace.dump(nil)) - assert_equal('{}', ObjectSpace.dump(true)) - assert_equal('{}', ObjectSpace.dump(false)) - assert_equal('{}', ObjectSpace.dump(0)) - assert_equal('{}', ObjectSpace.dump(:foo)) + assert_equal('{"type":"NIL"}', ObjectSpace.dump(nil)) + assert_equal('{"type":"TRUE"}', ObjectSpace.dump(true)) + assert_equal('{"type":"FALSE"}', ObjectSpace.dump(false)) + assert_equal('{"type":"FIXNUM"}', ObjectSpace.dump(0)) + assert_equal('{"type":"SYMBOL"}', ObjectSpace.dump(:foo)) end def test_dump_all