ruby-changes:16989
From: nari <ko1@a...>
Date: Sat, 14 Aug 2010 18:01:28 +0900 (JST)
Subject: [ruby-changes:16989] Ruby:r28986 (trunk): * test/objspace/test_objspace.rb: added test for objspace.
nari 2010-08-14 18:01:12 +0900 (Sat, 14 Aug 2010) New Revision: 28986 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=28986 Log: * test/objspace/test_objspace.rb: added test for objspace. * ext/objspace/objspace.c: considers T_ZOMBIE by lazy sweep GC. * gc.c: considers that dsize was 0. [ruby-dev:42022] Added directories: trunk/test/objspace/ Added files: trunk/test/objspace/test_objspace.rb Modified files: trunk/ChangeLog trunk/ext/objspace/objspace.c trunk/gc.c Index: ChangeLog =================================================================== --- ChangeLog (revision 28985) +++ ChangeLog (revision 28986) @@ -1,3 +1,11 @@ +Sat Aug 14 17:48:41 2010 Narihiro Nakamura <authorNari@g...> + + * test/objspace/test_objspace.rb: added test for objspace. + + * ext/objspace/objspace.c: considers T_ZOMBIE by lazy sweep GC. + + * gc.c: considers that dsize was 0. [ruby-dev:42022] + Sat Aug 14 15:33:02 2010 Nobuyoshi Nakada <nobu@r...> * configure.in, include/ruby/defines.h (RUBY_FUNC_EXPORTED): macro Index: gc.c =================================================================== --- gc.c (revision 28985) +++ gc.c (revision 28986) @@ -1176,7 +1176,7 @@ size_t rb_objspace_data_type_memsize(VALUE obj) { - if (RTYPEDDATA_P(obj)) { + if (RTYPEDDATA_P(obj) && RTYPEDDATA_TYPE(obj)->function.dsize) { return RTYPEDDATA_TYPE(obj)->function.dsize(RTYPEDDATA_DATA(obj)); } else { Index: ext/objspace/objspace.c =================================================================== --- ext/objspace/objspace.c (revision 28985) +++ ext/objspace/objspace.c (revision 28986) @@ -138,6 +138,9 @@ } break; + case T_ZOMBIE: + break; + default: rb_bug("objspace/memsize_of(): unknown data type 0x%x(%p)", BUILTIN_TYPE(obj), (void*)obj); Index: test/objspace/test_objspace.rb =================================================================== --- test/objspace/test_objspace.rb (revision 0) +++ test/objspace/test_objspace.rb (revision 28986) @@ -0,0 +1,44 @@ +require "test/unit" +require "objspace" + +class TestObjSpace < Test::Unit::TestCase + def test_memsize_of + assert_equal(0, ObjectSpace.memsize_of(true)) + assert_kind_of(Integer, ObjectSpace.memsize_of(Object.new)) + assert_kind_of(Integer, ObjectSpace.memsize_of(Class)) + assert_kind_of(Integer, ObjectSpace.memsize_of("")) + assert_kind_of(Integer, ObjectSpace.memsize_of([])) + assert_kind_of(Integer, ObjectSpace.memsize_of({})) + assert_kind_of(Integer, ObjectSpace.memsize_of(//)) + f = File.new(__FILE__) + assert_kind_of(Integer, ObjectSpace.memsize_of(f)) + f.close + assert_kind_of(Integer, ObjectSpace.memsize_of(/a/.match("a"))) + assert_kind_of(Integer, ObjectSpace.memsize_of(Struct.new(:a))) + end + + def test_count_objects_size + res = ObjectSpace.count_objects_size + assert_equal(false, res.empty?) + assert_equal(true, res[:TOTAL] > 0) + arg = {} + ObjectSpace.count_objects_size(arg) + assert_equal(false, arg.empty?) + end + + def test_count_nodes + res = ObjectSpace.count_nodes + assert_equal(false, res.empty?) + arg = {} + ObjectSpace.count_nodes(arg) + assert_equal(false, arg.empty?) + end + + def test_count_tdata_objects + res = ObjectSpace.count_tdata_objects + assert_equal(false, res.empty?) + arg = {} + ObjectSpace.count_tdata_objects(arg) + assert_equal(false, arg.empty?) + end +end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/