ruby-changes:26209
From: ko1 <ko1@a...>
Date: Sat, 8 Dec 2012 09:19:33 +0900 (JST)
Subject: [ruby-changes:26209] ko1:r38266 (trunk): * ext/objspace/objspace.c (iow_size): return size of internal object
ko1 2012-12-08 09:18:42 +0900 (Sat, 08 Dec 2012) New Revision: 38266 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38266 Log: * ext/objspace/objspace.c (iow_size): return size of internal object for ObjectSpace.memsize_of(). * test/objspace/test_objspace.rb: add a test. Modified files: trunk/ChangeLog trunk/ext/objspace/objspace.c trunk/test/objspace/test_objspace.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 38265) +++ ChangeLog (revision 38266) @@ -1,3 +1,10 @@ +Sat Dec 8 07:57:12 2012 Koichi Sasada <ko1@a...> + + * ext/objspace/objspace.c (iow_size): return size of internal object + for ObjectSpace.memsize_of(). + + * test/objspace/test_objspace.rb: add a test. + Tue Dec 08 02:39:23 2012 James Edward Gray II <james@g...> * lib/csv.rb: A fix for row comparison by Stephen Wattam. [Bug #7528] Index: ext/objspace/objspace.c =================================================================== --- ext/objspace/objspace.c (revision 38265) +++ ext/objspace/objspace.c (revision 38266) @@ -639,9 +639,16 @@ rb_gc_mark((VALUE)ptr); } +static size_t +iow_size(const void *ptr) +{ + VALUE obj = (VALUE)ptr; + return memsize_of(obj); +} + static const rb_data_type_t iow_data_type = { "ObjectSpace::InternalObjectWrapper", - {iow_mark, 0, 0,}, + {iow_mark, 0, iow_size,}, }; static VALUE rb_mInternalObjectWrapper; Index: test/objspace/test_objspace.rb =================================================================== --- test/objspace/test_objspace.rb (revision 38265) +++ test/objspace/test_objspace.rb (revision 38266) @@ -92,4 +92,14 @@ } assert_operator(max, :>=, 1_001, "1000 elems + Array class") end + + def test_reachable_objects_size + ObjectSpace.each_object{|o| + ObjectSpace.reachable_objects_from(o).each{|reached_obj| + size = ObjectSpace.memsize_of(reached_obj) + assert_kind_of(Integer, size) + assert_operator(size, :>=, 0) + } + } + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/