ruby-changes:63257
From: Kazuhiro <ko1@a...>
Date: Sat, 3 Oct 2020 00:00:21 +0900 (JST)
Subject: [ruby-changes:63257] d0a7189f26 (master): Fix ObjectSpace.dump(obj, output: :stdout)
https://git.ruby-lang.org/ruby.git/commit/?id=d0a7189f26 From d0a7189f26dcb185c76771823dcfd20d8d4a7e3e Mon Sep 17 00:00:00 2001 From: Kazuhiro NISHIYAMA <zn@m...> Date: Fri, 2 Oct 2020 18:19:04 +0900 Subject: Fix ObjectSpace.dump(obj, output: :stdout) RDoc says `ObjectSpace.dump(obj, output: :stdout) # => nil`, but it returns STDOUT since fbba6bd4e3dff7a61965208fecae908f10c4edbe. I think it is unintentional change. diff --git a/ext/objspace/lib/objspace.rb b/ext/objspace/lib/objspace.rb index 7cd7507..0298b06 100644 --- a/ext/objspace/lib/objspace.rb +++ b/ext/objspace/lib/objspace.rb @@ -36,7 +36,9 @@ module ObjectSpace https://github.com/ruby/ruby/blob/trunk/ext/objspace/lib/objspace.rb#L36 raise ArgumentError, "wrong output option: #{output.inspect}" end - _dump(obj, out) + ret = _dump(obj, out) + return nil if output == :stdout + ret end @@ -82,6 +84,8 @@ module ObjectSpace https://github.com/ruby/ruby/blob/trunk/ext/objspace/lib/objspace.rb#L84 raise ArgumentError, "wrong output option: #{output.inspect}" end - _dump_all(out, full, since) + ret = _dump_all(out, full, since) + return nil if output == :stdout + ret end end diff --git a/test/objspace/test_objspace.rb b/test/objspace/test_objspace.rb index b3f7a56..230c1d0 100644 --- a/test/objspace/test_objspace.rb +++ b/test/objspace/test_objspace.rb @@ -318,8 +318,9 @@ class TestObjSpace < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/objspace/test_objspace.rb#L318 ObjectSpace.dump_all(output: :stdout) end - dump_my_heap_please + p dump_my_heap_please end; + assert_equal 'nil', output.pop heap = output.find_all { |l| obj = JSON.parse(l) obj['type'] == "IMEMO" && obj['imemo_type'] @@ -335,8 +336,9 @@ class TestObjSpace < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/objspace/test_objspace.rb#L336 ObjectSpace.dump_all(output: :stdout, full: true) end - dump_my_heap_please + p dump_my_heap_please end; + assert_equal 'nil', output.pop heap = output.find_all { |l| JSON.parse(l)['type'] == "NONE" } assert_operator heap.length, :>, 0 end @@ -356,8 +358,9 @@ class TestObjSpace < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/objspace/test_objspace.rb#L358 ObjectSpace.dump_all(output: :stdout, since: gc_gen) end - dump_my_heap_please + p dump_my_heap_please end; + assert_equal 'nil', output.pop since = output.shift.to_i assert_operator output.size, :>, 0 generations = output.map { |l| JSON.parse(l)["generation"] }.uniq.sort @@ -374,8 +377,9 @@ class TestObjSpace < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/objspace/test_objspace.rb#L377 ObjectSpace.dump_all(output: $stdout) end - dump_my_heap_please + p $stdout == dump_my_heap_please end; + assert_equal 'true', output.pop needle = JSON.parse(output.first) addr = needle['address'] found = output.drop(1).find { |l| JSON.parse(l)['address'] == addr } @@ -392,8 +396,9 @@ class TestObjSpace < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/objspace/test_objspace.rb#L396 ObjectSpace.dump_all(output: $stdout) end - dump_my_heap_please + p $stdout == dump_my_heap_please end; + assert_equal 'true', output.pop needle = JSON.parse(output.first) addr = needle['class'] found = output.drop(1).find { |l| JSON.parse(l)['address'] == addr } @@ -430,8 +435,9 @@ class TestObjSpace < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/objspace/test_objspace.rb#L435 ObjectSpace.dump_all(output: $stdout) end - dump_my_heap_please + p $stdout == dump_my_heap_please end; + assert_equal 'true', output.pop needle = JSON.parse(output.first) addr = needle['address'] found = output.drop(1).find { |l| (JSON.parse(l)['references'] || []).include? addr } @@ -452,8 +458,9 @@ class TestObjSpace < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/objspace/test_objspace.rb#L458 ObjectSpace.dump_all(output: :stdout) end - dump_my_heap_please + p dump_my_heap_please end; + assert_equal 'nil', output.pop assert_match(entry, output.grep(/TEST STRING/).join("\n")) end -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/