iseq_collector 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/iseq_collector/iseq_collector.c +101 -0
- data/lib/iseq_collector/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 361f51f935c26f922c5470d8043546c1f7101fb2
|
4
|
+
data.tar.gz: 567c243aabeb8c264d0bd4b108ca376798f62924
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fce8a1e216b67a9bc7a2e70c40709162615625864e048c0719b391b59bdc7c8af150ebaff6c3fe94dad1efe0cce39fb0a88a447afb574caffe26abd7e5daa8d1
|
7
|
+
data.tar.gz: 571af44fa45469d851950983412d8f4886d35a8c4cd181414a279746500b19032b12458948a49dc6ee3a42d965fbd60fbaf0c878e31048c017aed3dee150a2eb
|
@@ -0,0 +1,101 @@
|
|
1
|
+
#include <ruby/ruby.h>
|
2
|
+
|
3
|
+
#ifdef T_IMEMO
|
4
|
+
|
5
|
+
VALUE rb_iseqw_new(VALUE v);
|
6
|
+
void rb_objspace_each_objects(
|
7
|
+
int (*callback)(void *start, void *end, size_t stride, void *data),
|
8
|
+
void *data);
|
9
|
+
size_t rb_obj_memsize_of(VALUE);
|
10
|
+
|
11
|
+
enum imemo_type {
|
12
|
+
imemo_none = 0,
|
13
|
+
imemo_cref = 1,
|
14
|
+
imemo_svar = 2,
|
15
|
+
imemo_throw_data = 3,
|
16
|
+
imemo_ifunc = 4,
|
17
|
+
imemo_memo = 5,
|
18
|
+
imemo_ment = 6,
|
19
|
+
imemo_iseq = 7,
|
20
|
+
imemo_mask = 0x07
|
21
|
+
};
|
22
|
+
|
23
|
+
static inline enum imemo_type
|
24
|
+
imemo_type(VALUE imemo)
|
25
|
+
{
|
26
|
+
return (RBASIC(imemo)->flags >> FL_USHIFT) & imemo_mask;
|
27
|
+
}
|
28
|
+
|
29
|
+
static inline int
|
30
|
+
rb_obj_is_iseq(VALUE iseq)
|
31
|
+
{
|
32
|
+
return RB_TYPE_P(iseq, T_IMEMO) && imemo_type(iseq) == imemo_iseq;
|
33
|
+
}
|
34
|
+
|
35
|
+
struct iseq_i_data {
|
36
|
+
void (*func)(VALUE v, void *data);
|
37
|
+
void *data;
|
38
|
+
};
|
39
|
+
|
40
|
+
int
|
41
|
+
iseq_i(void *vstart, void *vend, size_t stride, void *ptr)
|
42
|
+
{
|
43
|
+
VALUE v;
|
44
|
+
struct iseq_i_data *data = (struct iseq_i_data *)ptr;
|
45
|
+
|
46
|
+
for (v = (VALUE)vstart; v != (VALUE)vend; v += stride) {
|
47
|
+
if (RBASIC(v)->flags) {
|
48
|
+
switch (BUILTIN_TYPE(v)) {
|
49
|
+
case T_IMEMO:
|
50
|
+
if (rb_obj_is_iseq(v)) {
|
51
|
+
data->func(v, data->data);
|
52
|
+
}
|
53
|
+
continue;
|
54
|
+
default:
|
55
|
+
continue;
|
56
|
+
}
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
return 0;
|
61
|
+
}
|
62
|
+
|
63
|
+
static void
|
64
|
+
each_iseq_i(VALUE v, void *ptr)
|
65
|
+
{
|
66
|
+
rb_yield(rb_iseqw_new(v));
|
67
|
+
}
|
68
|
+
|
69
|
+
static VALUE
|
70
|
+
each_iseq(VALUE self)
|
71
|
+
{
|
72
|
+
struct iseq_i_data data = {each_iseq_i, NULL};
|
73
|
+
rb_objspace_each_objects(iseq_i, &data);
|
74
|
+
return Qnil;
|
75
|
+
}
|
76
|
+
|
77
|
+
static void
|
78
|
+
count_iseq_i(VALUE v, void *ptr)
|
79
|
+
{
|
80
|
+
size_t *sizep = (size_t *)ptr;
|
81
|
+
*sizep += 1;
|
82
|
+
}
|
83
|
+
|
84
|
+
static VALUE
|
85
|
+
count_iseq(VALUE self)
|
86
|
+
{
|
87
|
+
size_t size = 0;
|
88
|
+
struct iseq_i_data data = {count_iseq_i, &size};
|
89
|
+
rb_objspace_each_objects(iseq_i, &data);
|
90
|
+
return SIZET2NUM(size);
|
91
|
+
}
|
92
|
+
|
93
|
+
void
|
94
|
+
Init_iseq_collector(void)
|
95
|
+
{
|
96
|
+
VALUE rb_mObjSpace = rb_const_get(rb_cObject, rb_intern("ObjectSpace"));
|
97
|
+
rb_define_singleton_method(rb_mObjSpace, "each_iseq", each_iseq, 0);
|
98
|
+
rb_define_singleton_method(rb_mObjSpace, "count_iseq", count_iseq, 0);
|
99
|
+
}
|
100
|
+
|
101
|
+
#endif
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iseq_collector
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Koichi Sasada
|
@@ -83,6 +83,7 @@ files:
|
|
83
83
|
- bin/console
|
84
84
|
- bin/setup
|
85
85
|
- ext/iseq_collector/extconf.rb
|
86
|
+
- ext/iseq_collector/iseq_collector.c
|
86
87
|
- iseq_collector.gemspec
|
87
88
|
- lib/iseq_collector.rb
|
88
89
|
- lib/iseq_collector/version.rb
|