ruby-changes:52760
From: naruse <ko1@a...>
Date: Tue, 9 Oct 2018 11:02:00 +0900 (JST)
Subject: [ruby-changes:52760] naruse:r64972 (trunk): Revert "ext/objspace/objspace_dump.c: print addresses consistently"
naruse 2018-10-09 11:01:54 +0900 (Tue, 09 Oct 2018) New Revision: 64972 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=64972 Log: Revert "ext/objspace/objspace_dump.c: print addresses consistently" This reverts commit r64970. Visual C++ 12.0 doesn't have PRIxPTR. Anyway we have our own vfprintf implementation BSD_vfprintf(). If you want to have portable vfprintf, replace it with BSD_vfprintf like vsnprintf or just use BSD_vfprintf. Modified files: trunk/ext/objspace/objspace_dump.c trunk/test/objspace/test_objspace.rb Index: test/objspace/test_objspace.rb =================================================================== --- test/objspace/test_objspace.rb (revision 64971) +++ test/objspace/test_objspace.rb (revision 64972) @@ -318,62 +318,6 @@ class TestObjSpace < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/objspace/test_objspace.rb#L318 end end - def test_dump_addresses_match_dump_all_addresses - assert_in_out_err(%w[-robjspace], "#{<<-"begin;"}\n#{<<-'end;'}") do |output, error| - begin; - def dump_my_heap_please - obj = Object.new - puts ObjectSpace.dump(obj) - ObjectSpace.dump_all(output: $stdout) - end - - dump_my_heap_please - end; - needle = JSON.parse(output.first) - addr = needle['address'] - found = output.drop(1).find { |l| JSON.parse(l)['address'] == addr } - assert found, "object #{addr} should be findable in full heap dump" - end - end - - def test_dump_class_addresses_match_dump_all_addresses - assert_in_out_err(%w[-robjspace], "#{<<-"begin;"}\n#{<<-'end;'}") do |output, error| - begin; - def dump_my_heap_please - obj = Object.new - puts ObjectSpace.dump(obj) - ObjectSpace.dump_all(output: $stdout) - end - - dump_my_heap_please - end; - needle = JSON.parse(output.first) - addr = needle['class'] - found = output.drop(1).find { |l| JSON.parse(l)['address'] == addr } - assert found, "object #{addr} should be findable in full heap dump" - end - end - - def test_dump_reference_addresses_match_dump_all_addresses - assert_in_out_err(%w[-robjspace], "#{<<-"begin;"}\n#{<<-'end;'}") do |output, error| - begin; - def dump_my_heap_please - obj = Object.new - obj2 = Object.new - obj2.instance_variable_set(:@ref, obj) - puts ObjectSpace.dump(obj) - ObjectSpace.dump_all(output: $stdout) - end - - dump_my_heap_please - end; - needle = JSON.parse(output.first) - addr = needle['address'] - found = output.drop(1).find { |l| (JSON.parse(l)['references'] || []).include? addr } - assert found, "object #{addr} should be findable in full heap dump" - end - end - def test_dump_all entry = /"bytesize":11, "value":"TEST STRING", "encoding":"UTF-8", "file":"-", "line":4, "method":"dump_my_heap_please", "generation":/ Index: ext/objspace/objspace_dump.c =================================================================== --- ext/objspace/objspace_dump.c (revision 64971) +++ ext/objspace/objspace_dump.c (revision 64972) @@ -172,9 +172,9 @@ reachable_object_i(VALUE ref, void *data https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace_dump.c#L172 return; if (dc->cur_obj_references == 0) - dump_append(dc, ", \"references\":[\"0x%"PRIxPTR"\"", ref); + dump_append(dc, ", \"references\":[\"%p\"", (void *)ref); else - dump_append(dc, ", \"0x%"PRIxPTR"\"", ref); + dump_append(dc, ", \"%p\"", (void *)ref); dc->cur_obj_references++; } @@ -235,10 +235,10 @@ dump_object(VALUE obj, struct dump_confi https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace_dump.c#L235 if (dc->cur_obj == dc->string) return; - dump_append(dc, "{\"address\":\"0x%"PRIxPTR"\", \"type\":\"%s\"", obj, obj_type(obj)); + dump_append(dc, "{\"address\":\"%p\", \"type\":\"%s\"", (void *)obj, obj_type(obj)); if (dc->cur_obj_klass) - dump_append(dc, ", \"class\":\"0x%"PRIxPTR"\"", dc->cur_obj_klass); + dump_append(dc, ", \"class\":\"%p\"", (void *)dc->cur_obj_klass); if (rb_obj_frozen_p(obj)) dump_append(dc, ", \"frozen\":true"); @@ -274,7 +274,7 @@ dump_object(VALUE obj, struct dump_confi https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace_dump.c#L274 case T_HASH: dump_append(dc, ", \"size\":%"PRIuSIZE, (size_t)RHASH_SIZE(obj)); if (FL_TEST(obj, HASH_PROC_DEFAULT)) - dump_append(dc, ", \"default\":\"0x%"PRIxPTR"\"", RHASH_IFNONE(obj)); + dump_append(dc, ", \"default\":\"%p\"", (void *)RHASH_IFNONE(obj)); break; case T_ARRAY: @@ -363,9 +363,9 @@ root_obj_i(const char *category, VALUE o https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace_dump.c#L363 if (dc->root_category != NULL && category != dc->root_category) dump_append(dc, "]}\n"); if (dc->root_category == NULL || category != dc->root_category) - dump_append(dc, "{\"type\":\"ROOT\", \"root\":\"%s\", \"references\":[\"0x%"PRIxPTR"\"", category, obj); + dump_append(dc, "{\"type\":\"ROOT\", \"root\":\"%s\", \"references\":[\"%p\"", category, (void *)obj); else - dump_append(dc, ", \"0x%"PRIxPTR"\"", obj); + dump_append(dc, ", \"%p\"", (void *)obj); dc->root_category = category; dc->roots++; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/