class_stat 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0bf4b1b0fe06e8381456cbbb41f2fe53501b8f77
4
- data.tar.gz: 4e8ed794604d320399ab37c39b6f4e2e789f06f6
3
+ metadata.gz: 1f795b0aefd1a72e5316344aa64b238f6e5ebb4a
4
+ data.tar.gz: 0ece78825bdaef2d74d7e535d6103aec2e3217db
5
5
  SHA512:
6
- metadata.gz: e106e86e0a6f936ad2f7bcb21abad4b9d21590abdac2b2043120e52529f3fed380015fae5f4adc5acdce375064e6d2fa22fc8764a6795c2007658f3d2b27e76b
7
- data.tar.gz: 92493db59285b5c2c0d066134de7c420d242618444a50aacc671661ee5a43e83e049d5651a67a57e1adf760921e53429bd03ed5ca5389f59dcd722aeed3855b8
6
+ metadata.gz: b9bc8e2229f3a66a52b10c98f610c37763cb87ebebe6e69702df6862f0d90cf0cc874b6309fcc79f41150c0047a30020f42c0017bd5eebf7e1806f1b3c06a262
7
+ data.tar.gz: b056358effdc2e29b55304a9bc667e94d3803a47c94407ca03cd0bd30e5079e4f0f876b352775136406920a0333adfe398d3de719b504af3a06da6e471feeef6
@@ -1,86 +1,97 @@
1
-
2
- #include <ruby/ruby.h>
3
-
4
- void rb_objspace_each_objects(
5
- int (*callback)(void *start, void *end, size_t stride, void *data),
6
- void *data);
7
-
8
- struct class_stat_struct {
9
- VALUE klass_iclassnum; /* { klass => iclassnum } */
10
- VALUE klass_msize; /* { klass => method_count_size } */
11
- };
12
-
13
- #define RICLASS_IS_ORIGIN FL_USER5
14
-
15
- static void
16
- countup(VALUE h, VALUE k, int n)
17
- {
18
- VALUE cn = INT2FIX(0);
19
-
20
- if (!RBASIC_CLASS(k)) {
21
- k = rb_sprintf("#<hidden_class:%p>", (void *)k);
22
- }
23
-
24
- cn = rb_hash_lookup2(h, k, cn);
25
- cn = INT2FIX(FIX2INT(cn) + n);
26
- rb_hash_aset(h, k, cn);
27
- }
28
-
29
- static int
30
- msize(VALUE klass)
31
- {
32
- if (RCLASS(klass)->m_tbl) {
33
- return RCLASS(klass)->m_tbl->num_entries;
34
- }
35
- else {
36
- return 0;
37
- }
38
- }
39
-
40
- static int
41
- stat_i(void *vstart, void *vend, size_t stride, void *data)
42
- {
43
- struct class_stat_struct *d = (struct class_stat_struct *)data;
44
- VALUE v = (VALUE)vstart;
45
-
46
- for (;v != (VALUE)vend; v += stride) {
47
- if (RBASIC(v)->flags) {
48
- switch (BUILTIN_TYPE(v)) {
49
- case T_ICLASS: {
50
- VALUE klass = RBASIC_CLASS(v);
51
- if (FL_TEST(v, RICLASS_IS_ORIGIN)) {
52
- countup(d->klass_msize, klass, msize(klass));
53
- }
54
- else {
55
- countup(d->klass_iclassnum, klass, 1);
56
- }
57
- break;
58
- }
59
- case T_CLASS:
60
- case T_MODULE:
61
- countup(d->klass_msize, v, msize(v));
62
- break;
63
- }
64
- }
65
- }
66
- return 0;
67
- }
68
-
69
- static VALUE
70
- class_stat(VALUE self)
71
- {
72
- struct class_stat_struct data;
73
- data.klass_iclassnum = rb_hash_new();
74
- data.klass_msize =rb_hash_new();
75
-
76
- rb_objspace_each_objects(stat_i, &data);
77
-
78
- return rb_ary_new_from_args(2, data.klass_iclassnum, data.klass_msize);
79
- }
80
-
81
- void
82
- Init_class_stat(void)
83
- {
84
- VALUE mod = rb_define_module("ClassStat");
85
- rb_define_singleton_method(mod, "stat", class_stat, 0);
86
- }
1
+
2
+ #include <ruby/ruby.h>
3
+
4
+ void rb_objspace_each_objects(
5
+ int (*callback)(void *start, void *end, size_t stride, void *data),
6
+ void *data);
7
+
8
+ struct class_stat_struct {
9
+ VALUE klass_iclassnum; /* { klass => iclassnum } */
10
+ VALUE klass_msize; /* { klass => method_count_size } */
11
+ };
12
+
13
+ #define RICLASS_IS_ORIGIN FL_USER5
14
+
15
+ static void
16
+ countup(VALUE h, VALUE k, int n)
17
+ {
18
+ VALUE cn = INT2FIX(0);
19
+
20
+ if (!RBASIC_CLASS(k)) {
21
+ k = rb_sprintf("#<hidden_class:%p>", (void *)k);
22
+ }
23
+
24
+ cn = rb_hash_lookup2(h, k, cn);
25
+ cn = INT2FIX(FIX2INT(cn) + n);
26
+ rb_hash_aset(h, k, cn);
27
+ }
28
+
29
+ static int
30
+ msize(VALUE klass)
31
+ {
32
+ #if RUBY_API_VERSION_MAJOR == 2 && (RUBY_API_VERSION_MINOR == 2 || RUBY_API_VERSION_MINOR == 1)
33
+ struct method_table_wrapper {
34
+ st_table *tbl;
35
+ size_t serial;
36
+ };
37
+ #define RCLASS_M_TBL_WRAPPER(c) (RCLASS(c)->m_tbl_wrapper)
38
+ #define RCLASS_M_TBL(c) (RCLASS_M_TBL_WRAPPER(c) ? RCLASS_M_TBL_WRAPPER(c)->tbl : 0)
39
+ #else
40
+ #define RCLASS_M_TBL(c) (RCLASS(c)->m_tbl)
41
+ #endif
42
+
43
+ if (RCLASS_M_TBL(klass)) {
44
+ return RCLASS_M_TBL(klass)->num_entries;
45
+ }
46
+ else {
47
+ return 0;
48
+ }
49
+ }
50
+
51
+ static int
52
+ stat_i(void *vstart, void *vend, size_t stride, void *data)
53
+ {
54
+ struct class_stat_struct *d = (struct class_stat_struct *)data;
55
+ VALUE v = (VALUE)vstart;
56
+
57
+ for (;v != (VALUE)vend; v += stride) {
58
+ if (RBASIC(v)->flags) {
59
+ switch (BUILTIN_TYPE(v)) {
60
+ case T_ICLASS: {
61
+ VALUE klass = RBASIC_CLASS(v);
62
+ if (FL_TEST(v, RICLASS_IS_ORIGIN)) {
63
+ countup(d->klass_msize, klass, msize(klass));
64
+ }
65
+ else {
66
+ countup(d->klass_iclassnum, klass, 1);
67
+ }
68
+ break;
69
+ }
70
+ case T_CLASS:
71
+ case T_MODULE:
72
+ countup(d->klass_msize, v, msize(v));
73
+ break;
74
+ }
75
+ }
76
+ }
77
+ return 0;
78
+ }
79
+
80
+ static VALUE
81
+ class_stat(VALUE self)
82
+ {
83
+ struct class_stat_struct data;
84
+ data.klass_iclassnum = rb_hash_new();
85
+ data.klass_msize =rb_hash_new();
86
+
87
+ rb_objspace_each_objects(stat_i, &data);
88
+
89
+ return rb_ary_new_from_args(2, data.klass_iclassnum, data.klass_msize);
90
+ }
91
+
92
+ void
93
+ Init_class_stat(void)
94
+ {
95
+ VALUE mod = rb_define_module("ClassStat");
96
+ rb_define_singleton_method(mod, "stat", class_stat, 0);
97
+ }
@@ -1,2 +1,2 @@
1
1
  require 'mkmf'
2
- create_makefile('class_stat')
2
+ create_makefile('class_stat/class_stat')
@@ -1,3 +1,3 @@
1
1
  module ClassStat
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: class_stat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Koichi Sasada