looksee 1.0.3 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,138 @@
1
+ /**********************************************************************
2
+
3
+ method.h -
4
+
5
+ $Author: nobu $
6
+ created at: Wed Jul 15 20:02:33 2009
7
+
8
+ Copyright (C) 2009 Koichi Sasada
9
+
10
+ **********************************************************************/
11
+ #ifndef METHOD_H
12
+ #define METHOD_H
13
+
14
+ #ifndef END_OF_ENUMERATION
15
+ # ifdef __GNUC__
16
+ # define END_OF_ENUMERATION(key)
17
+ # else
18
+ # define END_OF_ENUMERATION(key) END_OF_##key##_PLACEHOLDER = 0
19
+ # endif
20
+ #endif
21
+
22
+ typedef enum {
23
+ NOEX_PUBLIC = 0x00,
24
+ NOEX_NOSUPER = 0x01,
25
+ NOEX_PRIVATE = 0x02,
26
+ NOEX_PROTECTED = 0x04,
27
+ NOEX_MASK = 0x06,
28
+ NOEX_BASIC = 0x08,
29
+ NOEX_UNDEF = NOEX_NOSUPER,
30
+ NOEX_MODFUNC = 0x12,
31
+ NOEX_SUPER = 0x20,
32
+ NOEX_VCALL = 0x40,
33
+ NOEX_RESPONDS = 0x80,
34
+
35
+ NOEX_BIT_WIDTH = 8,
36
+ NOEX_SAFE_SHIFT_OFFSET = ((NOEX_BIT_WIDTH+3)/4)*4 /* round up to nibble */
37
+ } rb_method_flag_t;
38
+
39
+ #define NOEX_SAFE(n) ((int)((n) >> NOEX_SAFE_SHIFT_OFFSET) & 0x0F)
40
+ #define NOEX_WITH(n, s) (((s) << NOEX_SAFE_SHIFT_OFFSET) | (n) | (ruby_running ? 0 : NOEX_BASIC))
41
+ #define NOEX_WITH_SAFE(n) NOEX_WITH((n), rb_safe_level())
42
+
43
+ /* method data type */
44
+
45
+ typedef enum {
46
+ VM_METHOD_TYPE_ISEQ,
47
+ VM_METHOD_TYPE_CFUNC,
48
+ VM_METHOD_TYPE_ATTRSET,
49
+ VM_METHOD_TYPE_IVAR,
50
+ VM_METHOD_TYPE_BMETHOD,
51
+ VM_METHOD_TYPE_ZSUPER,
52
+ VM_METHOD_TYPE_UNDEF,
53
+ VM_METHOD_TYPE_NOTIMPLEMENTED,
54
+ VM_METHOD_TYPE_OPTIMIZED, /* Kernel#send, Proc#call, etc */
55
+ VM_METHOD_TYPE_MISSING, /* wrapper for method_missing(id) */
56
+ VM_METHOD_TYPE_REFINED,
57
+
58
+ END_OF_ENUMERATION(VM_METHOD_TYPE)
59
+ } rb_method_type_t;
60
+
61
+ struct rb_call_info_struct;
62
+
63
+ typedef struct rb_method_cfunc_struct {
64
+ VALUE (*func)(ANYARGS);
65
+ VALUE (*invoker)(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv);
66
+ int argc;
67
+ } rb_method_cfunc_t;
68
+
69
+ typedef struct rb_method_attr_struct {
70
+ ID id;
71
+ VALUE location;
72
+ } rb_method_attr_t;
73
+
74
+ typedef struct rb_iseq_struct rb_iseq_t;
75
+
76
+ typedef struct rb_method_definition_struct {
77
+ rb_method_type_t type; /* method type */
78
+ ID original_id;
79
+ union {
80
+ rb_iseq_t *iseq; /* should be mark */
81
+ rb_method_cfunc_t cfunc;
82
+ rb_method_attr_t attr;
83
+ VALUE proc; /* should be mark */
84
+ enum method_optimized_type {
85
+ OPTIMIZED_METHOD_TYPE_SEND,
86
+ OPTIMIZED_METHOD_TYPE_CALL,
87
+
88
+ OPTIMIZED_METHOD_TYPE__MAX
89
+ } optimize_type;
90
+ struct rb_method_entry_struct *orig_me;
91
+ } body;
92
+ int alias_count;
93
+ } rb_method_definition_t;
94
+
95
+ typedef struct rb_method_entry_struct {
96
+ rb_method_flag_t flag;
97
+ char mark;
98
+ rb_method_definition_t *def;
99
+ ID called_id;
100
+ VALUE klass; /* should be mark */
101
+ } rb_method_entry_t;
102
+
103
+ struct unlinked_method_entry_list_entry {
104
+ struct unlinked_method_entry_list_entry *next;
105
+ rb_method_entry_t *me;
106
+ };
107
+
108
+ #define UNDEFINED_METHOD_ENTRY_P(me) (!(me) || !(me)->def || (me)->def->type == VM_METHOD_TYPE_UNDEF)
109
+
110
+ void rb_add_method_cfunc(VALUE klass, ID mid, VALUE (*func)(ANYARGS), int argc, rb_method_flag_t noex);
111
+ rb_method_entry_t *rb_add_method(VALUE klass, ID mid, rb_method_type_t type, void *option, rb_method_flag_t noex);
112
+ rb_method_entry_t *rb_method_entry(VALUE klass, ID id, VALUE *define_class_ptr);
113
+ void rb_add_refined_method_entry(VALUE refined_class, ID mid);
114
+ rb_method_entry_t *rb_resolve_refined_method(VALUE refinements,
115
+ rb_method_entry_t *me,
116
+ VALUE *defined_class_ptr);
117
+ rb_method_entry_t *rb_method_entry_with_refinements(VALUE klass, ID id,
118
+ VALUE *defined_class_ptr);
119
+ rb_method_entry_t *rb_method_entry_without_refinements(VALUE klass, ID id,
120
+ VALUE *defined_class_ptr);
121
+
122
+ rb_method_entry_t *rb_method_entry_get_without_cache(VALUE klass, ID id, VALUE *define_class_ptr);
123
+ rb_method_entry_t *rb_method_entry_set(VALUE klass, ID mid, const rb_method_entry_t *, rb_method_flag_t noex);
124
+
125
+ int rb_method_entry_arity(const rb_method_entry_t *me);
126
+ int rb_method_entry_eq(const rb_method_entry_t *m1, const rb_method_entry_t *m2);
127
+ st_index_t rb_hash_method_entry(st_index_t hash, const rb_method_entry_t *me);
128
+
129
+ VALUE rb_method_entry_location(rb_method_entry_t *me);
130
+ VALUE rb_mod_method_location(VALUE mod, ID id);
131
+ VALUE rb_obj_method_location(VALUE obj, ID id);
132
+
133
+ void rb_mark_method_entry(const rb_method_entry_t *me);
134
+ void rb_free_method_entry(rb_method_entry_t *me);
135
+ void rb_sweep_method_entry(void *vm);
136
+ void rb_free_m_table(st_table *tbl);
137
+
138
+ #endif /* METHOD_H */
@@ -1,10 +1,19 @@
1
1
  #include "ruby.h"
2
2
 
3
- #if RUBY_VERSION >= 193
3
+ #if RUBY_VERSION >= 200
4
+ # include "method.h"
4
5
  # include "internal.h"
6
+ #elif RUBY_VERSION >= 193
7
+ # include "ruby/st.h"
8
+ # ifdef SA_EMPTY
9
+ # include "internal_falcon.h"
10
+ # define Looksee_method_table_foreach sa_foreach
11
+ # define Looksee_method_table_lookup sa_lookup
12
+ # else
13
+ # include "internal.h"
14
+ # endif
5
15
  # include "vm_core.h"
6
16
  # include "method.h"
7
- # include "ruby/st.h"
8
17
  #elif RUBY_VERSION >= 192
9
18
  # include "vm_core.h"
10
19
  # include "method.h"
@@ -17,6 +26,11 @@
17
26
  # include "st.h"
18
27
  #endif
19
28
 
29
+ #ifndef Looksee_method_table_foreach
30
+ # define Looksee_method_table_foreach st_foreach
31
+ # define Looksee_method_table_lookup st_lookup
32
+ #endif
33
+
20
34
  #if RUBY_VERSION < 187
21
35
  # define RCLASS_IV_TBL(c) (RCLASS(c)->iv_tbl)
22
36
  # define RCLASS_M_TBL(c) (RCLASS(c)->m_tbl)
@@ -77,8 +91,10 @@ typedef struct add_method_if_matching_arg {
77
91
  } add_method_if_matching_arg_t;
78
92
 
79
93
  static int add_method_if_matching(ID method_name, rb_method_entry_t *me, add_method_if_matching_arg_t *arg) {
94
+ # ifdef ID_ALLOCATOR
80
95
  if (method_name == ID_ALLOCATOR)
81
96
  return ST_CONTINUE;
97
+ # endif
82
98
 
83
99
  if (UNDEFINED_METHOD_ENTRY_P(me))
84
100
  return ST_CONTINUE;
@@ -90,6 +106,12 @@ static int add_method_if_matching(ID method_name, rb_method_entry_t *me, add_met
90
106
  }
91
107
 
92
108
  static int add_method_if_undefined(ID method_name, rb_method_entry_t *me, VALUE *names) {
109
+ # ifdef ID_ALLOCATOR
110
+ /* The allocator can be undefined with rb_undef_alloc_func, e.g. Struct. */
111
+ if (method_name == ID_ALLOCATOR)
112
+ return ST_CONTINUE;
113
+ # endif
114
+
93
115
  if (UNDEFINED_METHOD_ENTRY_P(me))
94
116
  rb_ary_push(*names, ID2SYM(method_name));
95
117
  return ST_CONTINUE;
@@ -111,9 +133,11 @@ typedef struct add_method_if_matching_arg {
111
133
  } add_method_if_matching_arg_t;
112
134
 
113
135
  static int add_method_if_matching(ID method_name, NODE *body, add_method_if_matching_arg_t *arg) {
136
+ # ifdef ID_ALLOCATOR
114
137
  /* This entry is for the internal allocator function. */
115
138
  if (method_name == ID_ALLOCATOR)
116
139
  return ST_CONTINUE;
140
+ # endif
117
141
 
118
142
  /* Module#undef_method:
119
143
  * * sets body->nd_body to NULL in ruby <= 1.8
@@ -128,6 +152,12 @@ static int add_method_if_matching(ID method_name, NODE *body, add_method_if_matc
128
152
  }
129
153
 
130
154
  static int add_method_if_undefined(ID method_name, NODE *body, VALUE *names) {
155
+ # ifdef ID_ALLOCATOR
156
+ /* The allocator can be undefined with rb_undef_alloc_func, e.g. Struct. */
157
+ if (method_name == ID_ALLOCATOR)
158
+ return ST_CONTINUE;
159
+ # endif
160
+
131
161
  if (!body || !body->nd_body)
132
162
  rb_ary_push(*names, ID2SYM(method_name));
133
163
  return ST_CONTINUE;
@@ -139,7 +169,8 @@ static VALUE internal_instance_methods(VALUE klass, VISIBILITY_TYPE visibility)
139
169
  add_method_if_matching_arg_t arg;
140
170
  arg.names = rb_ary_new();
141
171
  arg.visibility = visibility;
142
- st_foreach(RCLASS_M_TBL(klass), add_method_if_matching, (st_data_t)&arg);
172
+
173
+ Looksee_method_table_foreach(RCLASS_M_TBL(klass), add_method_if_matching, (st_data_t)&arg);
143
174
  return arg.names;
144
175
  }
145
176
 
@@ -173,7 +204,7 @@ VALUE Looksee_internal_private_instance_methods(VALUE self, VALUE klass) {
173
204
  */
174
205
  VALUE Looksee_internal_undefined_instance_methods(VALUE self, VALUE klass) {
175
206
  VALUE names = rb_ary_new();
176
- st_foreach(RCLASS_M_TBL(klass), add_method_if_undefined, (st_data_t)&names);
207
+ Looksee_method_table_foreach(RCLASS_M_TBL(klass), add_method_if_undefined, (st_data_t)&names);
177
208
  return names;
178
209
  }
179
210
 
@@ -184,7 +215,7 @@ VALUE Looksee_singleton_class_p(VALUE self, VALUE object) {
184
215
  VALUE Looksee_singleton_instance(VALUE self, VALUE singleton_class) {
185
216
  if (BUILTIN_TYPE(singleton_class) == T_CLASS && FL_TEST(singleton_class, FL_SINGLETON)) {
186
217
  VALUE object;
187
- if (!st_lookup(RCLASS_IV_TBL(singleton_class), rb_intern("__attached__"), (st_data_t *)&object))
218
+ if (!Looksee_method_table_lookup(RCLASS_IV_TBL(singleton_class), rb_intern("__attached__"), (st_data_t *)&object))
188
219
  rb_raise(rb_eRuntimeError, "[looksee bug] can't find singleton object");
189
220
  return object;
190
221
  } else {
@@ -0,0 +1,92 @@
1
+ !RBIX
2
+ 9595534255132031488
3
+ x
4
+ M
5
+ 1
6
+ n
7
+ n
8
+ x
9
+ 10
10
+ __script__
11
+ i
12
+ 29
13
+ 5
14
+ 7
15
+ 0
16
+ 64
17
+ 47
18
+ 49
19
+ 1
20
+ 1
21
+ 15
22
+ 5
23
+ 7
24
+ 2
25
+ 64
26
+ 47
27
+ 49
28
+ 1
29
+ 1
30
+ 15
31
+ 45
32
+ 3
33
+ 4
34
+ 43
35
+ 5
36
+ 49
37
+ 6
38
+ 0
39
+ 15
40
+ 2
41
+ 11
42
+ I
43
+ 2
44
+ I
45
+ 0
46
+ I
47
+ 0
48
+ I
49
+ 0
50
+ n
51
+ p
52
+ 7
53
+ s
54
+ 13
55
+ looksee/clean
56
+ x
57
+ 7
58
+ require
59
+ s
60
+ 16
61
+ looksee/core_ext
62
+ x
63
+ 7
64
+ Looksee
65
+ n
66
+ x
67
+ 19
68
+ WirbleCompatibility
69
+ x
70
+ 4
71
+ init
72
+ p
73
+ 7
74
+ I
75
+ 0
76
+ I
77
+ 1
78
+ I
79
+ 9
80
+ I
81
+ 2
82
+ I
83
+ 12
84
+ I
85
+ 5
86
+ I
87
+ 1d
88
+ x
89
+ 35
90
+ /Users/g/src/looksee/lib/looksee.rb
91
+ p
92
+ 0
Binary file
@@ -0,0 +1,303 @@
1
+ !RBIX
2
+ 9595534255132031488
3
+ x
4
+ M
5
+ 1
6
+ n
7
+ n
8
+ x
9
+ 10
10
+ __script__
11
+ i
12
+ 28
13
+ 99
14
+ 7
15
+ 0
16
+ 65
17
+ 49
18
+ 1
19
+ 2
20
+ 13
21
+ 99
22
+ 12
23
+ 7
24
+ 2
25
+ 12
26
+ 7
27
+ 3
28
+ 12
29
+ 65
30
+ 12
31
+ 49
32
+ 4
33
+ 4
34
+ 15
35
+ 49
36
+ 2
37
+ 0
38
+ 15
39
+ 2
40
+ 11
41
+ I
42
+ 6
43
+ I
44
+ 0
45
+ I
46
+ 0
47
+ I
48
+ 0
49
+ n
50
+ p
51
+ 5
52
+ x
53
+ 7
54
+ Looksee
55
+ x
56
+ 11
57
+ open_module
58
+ x
59
+ 15
60
+ __module_init__
61
+ M
62
+ 1
63
+ n
64
+ n
65
+ x
66
+ 7
67
+ Looksee
68
+ i
69
+ 28
70
+ 5
71
+ 66
72
+ 99
73
+ 7
74
+ 0
75
+ 65
76
+ 49
77
+ 1
78
+ 2
79
+ 13
80
+ 99
81
+ 12
82
+ 7
83
+ 2
84
+ 12
85
+ 7
86
+ 3
87
+ 12
88
+ 65
89
+ 12
90
+ 49
91
+ 4
92
+ 4
93
+ 15
94
+ 49
95
+ 2
96
+ 0
97
+ 11
98
+ I
99
+ 6
100
+ I
101
+ 0
102
+ I
103
+ 0
104
+ I
105
+ 0
106
+ n
107
+ p
108
+ 5
109
+ x
110
+ 7
111
+ Adapter
112
+ x
113
+ 11
114
+ open_module
115
+ x
116
+ 15
117
+ __module_init__
118
+ M
119
+ 1
120
+ n
121
+ n
122
+ x
123
+ 7
124
+ Adapter
125
+ i
126
+ 63
127
+ 5
128
+ 66
129
+ 5
130
+ 7
131
+ 0
132
+ 7
133
+ 1
134
+ 64
135
+ 47
136
+ 49
137
+ 2
138
+ 2
139
+ 15
140
+ 5
141
+ 7
142
+ 3
143
+ 7
144
+ 4
145
+ 45
146
+ 5
147
+ 6
148
+ 43
149
+ 7
150
+ 43
151
+ 8
152
+ 7
153
+ 9
154
+ 64
155
+ 49
156
+ 10
157
+ 1
158
+ 47
159
+ 101
160
+ 11
161
+ 63
162
+ 2
163
+ 47
164
+ 49
165
+ 2
166
+ 2
167
+ 15
168
+ 5
169
+ 7
170
+ 12
171
+ 7
172
+ 13
173
+ 64
174
+ 47
175
+ 49
176
+ 2
177
+ 2
178
+ 15
179
+ 5
180
+ 7
181
+ 14
182
+ 7
183
+ 15
184
+ 64
185
+ 47
186
+ 49
187
+ 2
188
+ 2
189
+ 11
190
+ I
191
+ 5
192
+ I
193
+ 0
194
+ I
195
+ 0
196
+ I
197
+ 0
198
+ n
199
+ p
200
+ 16
201
+ x
202
+ 4
203
+ Base
204
+ s
205
+ 20
206
+ looksee/adapter/base
207
+ x
208
+ 8
209
+ autoload
210
+ x
211
+ 3
212
+ MRI
213
+ s
214
+ 12
215
+ looksee/mri.
216
+ x
217
+ 7
218
+ Looksee
219
+ n
220
+ x
221
+ 6
222
+ Config
223
+ x
224
+ 6
225
+ CONFIG
226
+ s
227
+ 5
228
+ DLEXT
229
+ x
230
+ 2
231
+ []
232
+ x
233
+ 4
234
+ to_s
235
+ x
236
+ 5
237
+ JRuby
238
+ s
239
+ 17
240
+ looksee/JRuby.jar
241
+ x
242
+ 8
243
+ Rubinius
244
+ s
245
+ 24
246
+ looksee/adapter/rubinius
247
+ p
248
+ 9
249
+ I
250
+ 2
251
+ I
252
+ 3
253
+ I
254
+ d
255
+ I
256
+ 4
257
+ I
258
+ 29
259
+ I
260
+ 5
261
+ I
262
+ 34
263
+ I
264
+ 6
265
+ I
266
+ 3f
267
+ x
268
+ 43
269
+ /Users/g/src/looksee/lib/looksee/adapter.rb
270
+ p
271
+ 0
272
+ x
273
+ 13
274
+ attach_method
275
+ p
276
+ 3
277
+ I
278
+ 2
279
+ I
280
+ 2
281
+ I
282
+ 1c
283
+ x
284
+ 43
285
+ /Users/g/src/looksee/lib/looksee/adapter.rb
286
+ p
287
+ 0
288
+ x
289
+ 13
290
+ attach_method
291
+ p
292
+ 3
293
+ I
294
+ 0
295
+ I
296
+ 1
297
+ I
298
+ 1c
299
+ x
300
+ 43
301
+ /Users/g/src/looksee/lib/looksee/adapter.rb
302
+ p
303
+ 0