[前][次][番号順一覧][スレッド一覧]

ruby-changes:20275

From: ko1 <ko1@a...>
Date: Thu, 30 Jun 2011 17:37:12 +0900 (JST)
Subject: [ruby-changes:20275] ko1:r32323 (trunk): * ext/objspace/objspace.c (ObjectSpace.count_tdata_objects):

ko1	2011-06-30 17:37:06 +0900 (Thu, 30 Jun 2011)

  New Revision: 32323

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=32323

  Log:
    * ext/objspace/objspace.c (ObjectSpace.count_tdata_objects):
      Fix rdoc.
    * ext/objspace/objspace.c (ObjectSpace.count_tdata_objects):
      Change key type if the klass of a object is zero (internal object).
      Read rdoc for details.
    * internal.h: export rb_objspace_data_type_name().

  Modified files:
    trunk/ChangeLog
    trunk/ext/objspace/objspace.c
    trunk/internal.h

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 32322)
+++ ChangeLog	(revision 32323)
@@ -1,3 +1,14 @@
+Thu Jun 30 17:33:25 2011  Koichi Sasada  <ko1@a...>
+
+	* ext/objspace/objspace.c (ObjectSpace.count_tdata_objects): 
+	  Fix rdoc.
+
+	* ext/objspace/objspace.c (ObjectSpace.count_tdata_objects): 
+	  Change key type if the klass of a object is zero (internal object).
+	  Read rdoc for details.
+
+	* internal.h: export rb_objspace_data_type_name().
+
 Thu Jun 30 17:25:08 2011  Koichi Sasada  <ko1@a...>
 
 	* thread_pthread.c (ping_signal_thread_list, thread_timer): 
Index: ext/objspace/objspace.c
===================================================================
--- ext/objspace/objspace.c	(revision 32322)
+++ ext/objspace/objspace.c	(revision 32323)
@@ -547,14 +547,24 @@
 
     for (; v != (VALUE)vend; v += stride) {
 	if (RBASIC(v)->flags && BUILTIN_TYPE(v) == T_DATA) {
-	    VALUE counter = rb_hash_aref(hash, RBASIC(v)->klass);
+	    VALUE counter;
+	    VALUE key = RBASIC(v)->klass;
+
+	    if (key == 0) {
+		const char *name = rb_objspace_data_type_name(v);
+		if (name == 0) name = "unknown";
+		key = ID2SYM(rb_intern(name));
+	    }
+
+	    counter = rb_hash_aref(hash, key);
 	    if (NIL_P(counter)) {
 		counter = INT2FIX(1);
 	    }
 	    else {
 		counter = INT2FIX(FIX2INT(counter) + 1);
 	    }
-	    rb_hash_aset(hash, RBASIC(v)->klass, counter);
+
+	    rb_hash_aset(hash, key, counter);
 	}
     }
 
@@ -565,13 +575,17 @@
  *  call-seq:
  *     ObjectSpace.count_tdata_objects([result_hash]) -> hash
  *
- *  Counts nodes for each node type.
+ *  Counts objects for each T_DATA type.
  *
  *  This method is not for ordinary Ruby programmers, but for MRI developers
  *  who interest on MRI performance.
  *
  *  It returns a hash as:
- *  {:NODE_METHOD=>2027, :NODE_FBODY=>1927, :NODE_CFUNC=>1798, ...}
+ *  {RubyVM::InstructionSequence=>504, :parser=>5, :barrier=>6,
+ *   :mutex=>6, Proc=>60, RubyVM::Env=>57, Mutex=>1, Encoding=>99,
+ *   ThreadGroup=>1, Binding=>1, Thread=>1, RubyVM=>1, :iseq=>1,
+ *   Random=>1, ARGF.class=>1, Data=>1, :autoload=>3, Time=>2}
+ *  # T_DATA objects existing at startup on r32276.
  *
  *  If the optional argument, result_hash, is given,
  *  it is overwritten and returned.
@@ -580,6 +594,11 @@
  *  The contents of the returned hash is implementation defined.
  *  It may be changed in future.
  *
+ *  In this version, keys are Class object or Symbol object.
+ *  If object is kind of normal (accessible) object, the key is Class object.
+ *  If object is not a kind of normal (internal) object, the key is symbol
+ *  name, registered by rb_data_type_struct.
+ *
  *  This method is not expected to work except C Ruby.
  *
  */
Index: internal.h
===================================================================
--- internal.h	(revision 32322)
+++ internal.h	(revision 32323)
@@ -192,6 +192,7 @@
 #pragma GCC visibility push(default)
 #endif
 VALUE rb_thread_io_blocking_region(rb_blocking_function_t *func, void *data1, int fd);
+const char *rb_objspace_data_type_name(VALUE obj);
 #if defined __GNUC__ && __GNUC__ >= 4
 #pragma GCC visibility pop
 #endif

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]