Output object_id in ObjectSpace.dump
Outputs the object ID in the dump for objects that have it seen.
This commit is contained in:
parent
f0dc9dcdc7
commit
d729c1575e
Notes:
git
2025-01-30 16:48:31 +00:00
@ -638,6 +638,11 @@ dump_object(VALUE obj, struct dump_config *dc)
|
|||||||
dump_append_sizet(dc, memsize);
|
dump_append_sizet(dc, memsize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (FL_TEST(obj, FL_SEEN_OBJ_ID)) {
|
||||||
|
dump_append(dc, ", \"object_id\":");
|
||||||
|
dump_append_lu(dc, RB_NUM2ULONG(rb_obj_id(obj)));
|
||||||
|
}
|
||||||
|
|
||||||
if ((n = rb_obj_gc_flags(obj, flags, sizeof(flags))) > 0) {
|
if ((n = rb_obj_gc_flags(obj, flags, sizeof(flags))) > 0) {
|
||||||
dump_append(dc, ", \"flags\":{");
|
dump_append(dc, ", \"flags\":{");
|
||||||
for (i=0; i<n; i++) {
|
for (i=0; i<n; i++) {
|
||||||
|
@ -486,6 +486,20 @@ class TestObjSpace < Test::Unit::TestCase
|
|||||||
assert_match(/"value":"foobar\h+"/, dump)
|
assert_match(/"value":"foobar\h+"/, dump)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_dump_outputs_object_id
|
||||||
|
obj = Object.new
|
||||||
|
|
||||||
|
# Doesn't output object_id when it has not been seen
|
||||||
|
dump = ObjectSpace.dump(obj)
|
||||||
|
assert_not_include(dump, "\"object_id\"")
|
||||||
|
|
||||||
|
id = obj.object_id
|
||||||
|
|
||||||
|
# Outputs object_id when it has been seen
|
||||||
|
dump = ObjectSpace.dump(obj)
|
||||||
|
assert_include(dump, "\"object_id\":#{id}")
|
||||||
|
end
|
||||||
|
|
||||||
def test_dump_includes_imemo_type
|
def test_dump_includes_imemo_type
|
||||||
assert_in_out_err(%w[-robjspace], "#{<<-"begin;"}\n#{<<-'end;'}") do |output, error|
|
assert_in_out_err(%w[-robjspace], "#{<<-"begin;"}\n#{<<-'end;'}") do |output, error|
|
||||||
begin;
|
begin;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user