summaryrefslogtreecommitdiff
path: root/ext/objspace/objspace.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-30 08:37:06 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-30 08:37:06 +0000
commit3b32735546e989557a8992063f9f1bbdcd999beb (patch)
treed50174a9d0b68736565c429eb95e715315b94229 /ext/objspace/objspace.c
parentd49a61e68f1d6ffe448ec3244c63d48adc101cea (diff)
* 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(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32323 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/objspace/objspace.c')
-rw-r--r--ext/objspace/objspace.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/ext/objspace/objspace.c b/ext/objspace/objspace.c
index 3434a0ae07..a0859a7325 100644
--- a/ext/objspace/objspace.c
+++ b/ext/objspace/objspace.c
@@ -547,14 +547,24 @@ cto_i(void *vstart, void *vend, size_t stride, void *data)
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 @@ cto_i(void *vstart, void *vend, size_t stride, void *data)
* 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 @@ cto_i(void *vstart, void *vend, size_t stride, void *data)
* 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.
*
*/