Feature #11292 ยป objspace_dump_type_special_consts.diff
ext/objspace/objspace_dump.c | ||
---|---|---|
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);
|
||
... | ... | |
size_t n, i;
|
||
if (SPECIAL_CONST_P(obj)) {
|
||
dump_append(dc, "{}");
|
||
dump_append(dc, "{\"type\":\"%s\"}", obj_type(obj));
|
||
return;
|
||
}
|
||
test/objspace/test_objspace.rb | ||
---|---|---|
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
|