Project

General

Profile

Feature #11292 ยป objspace_dump_type_special_consts.diff

sorah (Sorah Fukumori), 06/20/2015 09:02 PM

View differences:

ext/objspace/objspace_dump.c
92 92
static inline const char *
93 93
obj_type(VALUE obj)
94 94
{
95
    if (IMMEDIATE_P(obj)) {
96
	if (FIXNUM_P(obj)) return "FIXNUM";
97
        if (FLONUM_P(obj)) return "FLOAT";
98
        if (obj == Qtrue)  return "TRUE";
99
	if (STATIC_SYM_P(obj)) return "SYMBOL";
100
	if (obj == Qundef) return "UNDEF";
101
    }
102
    else if (!RTEST(obj)) {
103
	if (obj == Qnil)   return "NIL";
104
	if (obj == Qfalse) return "FALSE";
105
    }
106

  
95 107
    switch (BUILTIN_TYPE(obj)) {
96 108
#define CASE_TYPE(type) case T_##type: return #type; break
97 109
	CASE_TYPE(NONE);
......
150 162
    size_t n, i;
151 163

  
152 164
    if (SPECIAL_CONST_P(obj)) {
153
      dump_append(dc, "{}");
165
      dump_append(dc, "{\"type\":\"%s\"}",  obj_type(obj));
154 166
      return;
155 167
    }
156 168

  
test/objspace/test_objspace.rb
245 245

  
246 246
  def test_dump_special_consts
247 247
    # [ruby-core:69692] [Bug #11291]
248
    assert_equal('{}', ObjectSpace.dump(nil))
249
    assert_equal('{}', ObjectSpace.dump(true))
250
    assert_equal('{}', ObjectSpace.dump(false))
251
    assert_equal('{}', ObjectSpace.dump(0))
252
    assert_equal('{}', ObjectSpace.dump(:foo))
248
    assert_equal('{"type":"NIL"}', ObjectSpace.dump(nil))
249
    assert_equal('{"type":"TRUE"}', ObjectSpace.dump(true))
250
    assert_equal('{"type":"FALSE"}', ObjectSpace.dump(false))
251
    assert_equal('{"type":"FIXNUM"}', ObjectSpace.dump(0))
252
    assert_equal('{"type":"SYMBOL"}', ObjectSpace.dump(:foo))
253 253
  end
254 254

  
255 255
  def test_dump_all