looksee 3.1.1 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +9 -0
  3. data/README.markdown +61 -81
  4. data/ext/extconf.rb +3 -7
  5. data/ext/mri/2.3.0/internal.h +1404 -0
  6. data/ext/mri/2.3.0/method.h +213 -0
  7. data/ext/mri/mri.c +21 -264
  8. data/ext/rbx/rbx.c +0 -9
  9. data/lib/looksee/JRuby.jar +0 -0
  10. data/lib/looksee/adapter/base.rb +19 -54
  11. data/lib/looksee/adapter/rubinius.rb +3 -62
  12. data/lib/looksee/clean.rb +5 -1
  13. data/lib/looksee/editor.rb +1 -1
  14. data/lib/looksee/help.rb +3 -2
  15. data/lib/looksee/lookup_path.rb +7 -3
  16. data/lib/looksee/version.rb +1 -1
  17. data/spec/looksee/adapter_spec.rb +72 -365
  18. data/spec/looksee/editor_spec.rb +1 -1
  19. data/spec/looksee/inspector_spec.rb +21 -21
  20. data/spec/looksee/lookup_path_spec.rb +34 -21
  21. data/spec/spec_helper.rb +2 -0
  22. data/spec/support/temporary_classes.rb +10 -14
  23. data/spec/support/test_adapter.rb +2 -53
  24. metadata +6 -29
  25. data/ext/mri/1.9.2/debug.h +0 -36
  26. data/ext/mri/1.9.2/id.h +0 -170
  27. data/ext/mri/1.9.2/method.h +0 -103
  28. data/ext/mri/1.9.2/node.h +0 -483
  29. data/ext/mri/1.9.2/thread_pthread.h +0 -27
  30. data/ext/mri/1.9.2/vm_core.h +0 -707
  31. data/ext/mri/1.9.2/vm_opts.h +0 -51
  32. data/ext/mri/1.9.3/atomic.h +0 -56
  33. data/ext/mri/1.9.3/debug.h +0 -41
  34. data/ext/mri/1.9.3/id.h +0 -175
  35. data/ext/mri/1.9.3/internal.h +0 -227
  36. data/ext/mri/1.9.3/internal_falcon.h +0 -248
  37. data/ext/mri/1.9.3/method.h +0 -105
  38. data/ext/mri/1.9.3/node.h +0 -503
  39. data/ext/mri/1.9.3/thread_pthread.h +0 -51
  40. data/ext/mri/1.9.3/vm_core.h +0 -755
  41. data/ext/mri/1.9.3/vm_opts.h +0 -51
  42. data/ext/mri/2.0.0/internal.h +0 -378
  43. data/ext/mri/2.0.0/method.h +0 -138
  44. data/ext/mri/env-1.8.h +0 -27
  45. data/ext/mri/eval_c-1.8.h +0 -27
  46. data/ext/mri/node-1.9.h +0 -35
  47. data/lib/looksee/mri.bundle +0 -0
@@ -0,0 +1,213 @@
1
+ /**********************************************************************
2
+
3
+ method.h -
4
+
5
+ $Author: ko1 $
6
+ created at: Wed Jul 15 20:02:33 2009
7
+
8
+ Copyright (C) 2009 Koichi Sasada
9
+
10
+ **********************************************************************/
11
+ #ifndef RUBY_METHOD_H
12
+ #define RUBY_METHOD_H 1
13
+
14
+ #include "internal.h"
15
+
16
+ #ifndef END_OF_ENUMERATION
17
+ # if defined(__GNUC__) &&! defined(__STRICT_ANSI__)
18
+ # define END_OF_ENUMERATION(key)
19
+ # else
20
+ # define END_OF_ENUMERATION(key) END_OF_##key##_PLACEHOLDER = 0
21
+ # endif
22
+ #endif
23
+
24
+ /* cref */
25
+
26
+ typedef enum {
27
+ METHOD_VISI_UNDEF = 0x00,
28
+ METHOD_VISI_PUBLIC = 0x01,
29
+ METHOD_VISI_PRIVATE = 0x02,
30
+ METHOD_VISI_PROTECTED = 0x03,
31
+
32
+ METHOD_VISI_MASK = 0x03
33
+ } rb_method_visibility_t;
34
+
35
+ typedef struct rb_scope_visi_struct {
36
+ rb_method_visibility_t method_visi : 3;
37
+ unsigned int module_func : 1;
38
+ } rb_scope_visibility_t;
39
+
40
+ typedef struct rb_cref_struct {
41
+ VALUE flags;
42
+ const VALUE refinements;
43
+ const VALUE klass;
44
+ struct rb_cref_struct * const next;
45
+ const rb_scope_visibility_t scope_visi;
46
+ } rb_cref_t;
47
+
48
+ /* method data type */
49
+
50
+ typedef struct rb_method_entry_struct {
51
+ VALUE flags;
52
+ const VALUE defined_class;
53
+ struct rb_method_definition_struct * const def;
54
+ ID called_id;
55
+ const VALUE owner;
56
+ } rb_method_entry_t;
57
+
58
+ typedef struct rb_callable_method_entry_struct { /* same fields with rb_method_entry_t */
59
+ VALUE flags;
60
+ const VALUE defined_class;
61
+ struct rb_method_definition_struct * const def;
62
+ ID called_id;
63
+ const VALUE owner;
64
+ } rb_callable_method_entry_t;
65
+
66
+ #define METHOD_ENTRY_VISI(me) (rb_method_visibility_t)(((me)->flags & (IMEMO_FL_USER0 | IMEMO_FL_USER1)) >> (IMEMO_FL_USHIFT+0))
67
+ #define METHOD_ENTRY_BASIC(me) (int) (((me)->flags & (IMEMO_FL_USER2 )) >> (IMEMO_FL_USHIFT+2))
68
+ #define METHOD_ENTRY_COMPLEMENTED(me) ((me)->flags & IMEMO_FL_USER3)
69
+ #define METHOD_ENTRY_COMPLEMENTED_SET(me) ((me)->flags = (me)->flags | IMEMO_FL_USER3)
70
+
71
+ static inline void
72
+ METHOD_ENTRY_VISI_SET(rb_method_entry_t *me, rb_method_visibility_t visi)
73
+ {
74
+ VM_ASSERT((int)visi >= 0 && visi <= 3);
75
+ me->flags = (me->flags & ~(IMEMO_FL_USER0 | IMEMO_FL_USER1)) | (visi << (IMEMO_FL_USHIFT+0));
76
+ }
77
+ static inline void
78
+ METHOD_ENTRY_BASIC_SET(rb_method_entry_t *me, unsigned int basic)
79
+ {
80
+ VM_ASSERT(basic <= 1);
81
+ me->flags = (me->flags & ~(IMEMO_FL_USER2 )) | (basic << (IMEMO_FL_USHIFT+2));
82
+ }
83
+ static inline void
84
+ METHOD_ENTRY_FLAGS_SET(rb_method_entry_t *me, rb_method_visibility_t visi, unsigned int basic)
85
+ {
86
+ VM_ASSERT((int)visi >= 0 && visi <= 3);
87
+ VM_ASSERT(basic <= 1);
88
+ me->flags =
89
+ (me->flags & ~(IMEMO_FL_USER0|IMEMO_FL_USER1|IMEMO_FL_USER2)) |
90
+ ((visi << (IMEMO_FL_USHIFT+0)) | (basic << (IMEMO_FL_USHIFT+2)));
91
+ }
92
+ static inline void
93
+ METHOD_ENTRY_FLAGS_COPY(rb_method_entry_t *dst, const rb_method_entry_t *src)
94
+ {
95
+ dst->flags =
96
+ (dst->flags & ~(IMEMO_FL_USER0|IMEMO_FL_USER1|IMEMO_FL_USER2)) |
97
+ (src->flags & (IMEMO_FL_USER0|IMEMO_FL_USER1|IMEMO_FL_USER2));
98
+ }
99
+
100
+ typedef enum {
101
+ VM_METHOD_TYPE_ISEQ,
102
+ VM_METHOD_TYPE_CFUNC,
103
+ VM_METHOD_TYPE_ATTRSET,
104
+ VM_METHOD_TYPE_IVAR,
105
+ VM_METHOD_TYPE_BMETHOD,
106
+ VM_METHOD_TYPE_ZSUPER,
107
+ VM_METHOD_TYPE_ALIAS,
108
+ VM_METHOD_TYPE_UNDEF,
109
+ VM_METHOD_TYPE_NOTIMPLEMENTED,
110
+ VM_METHOD_TYPE_OPTIMIZED, /* Kernel#send, Proc#call, etc */
111
+ VM_METHOD_TYPE_MISSING, /* wrapper for method_missing(id) */
112
+ VM_METHOD_TYPE_REFINED,
113
+
114
+ END_OF_ENUMERATION(VM_METHOD_TYPE)
115
+ } rb_method_type_t;
116
+
117
+ #ifndef rb_iseq_t
118
+ typedef struct rb_iseq_struct rb_iseq_t;
119
+ #define rb_iseq_t rb_iseq_t
120
+ #endif
121
+
122
+ typedef struct rb_method_iseq_struct {
123
+ const rb_iseq_t * const iseqptr; /* should be separated from iseqval */
124
+ rb_cref_t * const cref; /* should be marked */
125
+ } rb_method_iseq_t; /* check rb_add_method_iseq() when modify the fields */
126
+
127
+ typedef struct rb_method_cfunc_struct {
128
+ VALUE (*func)(ANYARGS);
129
+ VALUE (*invoker)(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv);
130
+ int argc;
131
+ } rb_method_cfunc_t;
132
+
133
+ typedef struct rb_method_attr_struct {
134
+ ID id;
135
+ const VALUE location; /* should be marked */
136
+ } rb_method_attr_t;
137
+
138
+ typedef struct rb_method_alias_struct {
139
+ const struct rb_method_entry_struct * const original_me; /* original_me->klass is original owner */
140
+ } rb_method_alias_t;
141
+
142
+ typedef struct rb_method_refined_struct {
143
+ const struct rb_method_entry_struct * const orig_me;
144
+ const VALUE owner;
145
+ } rb_method_refined_t;
146
+
147
+ typedef struct rb_method_definition_struct {
148
+ rb_method_type_t type : 8; /* method type */
149
+ int alias_count : 28;
150
+ int complemented_count: 28;
151
+
152
+ union {
153
+ rb_method_iseq_t iseq;
154
+ rb_method_cfunc_t cfunc;
155
+ rb_method_attr_t attr;
156
+ rb_method_alias_t alias;
157
+ rb_method_refined_t refined;
158
+
159
+ const VALUE proc; /* should be marked */
160
+ enum method_optimized_type {
161
+ OPTIMIZED_METHOD_TYPE_SEND,
162
+ OPTIMIZED_METHOD_TYPE_CALL,
163
+
164
+ OPTIMIZED_METHOD_TYPE__MAX
165
+ } optimize_type;
166
+ } body;
167
+
168
+ ID original_id;
169
+ } rb_method_definition_t;
170
+
171
+ #define UNDEFINED_METHOD_ENTRY_P(me) (!(me) || !(me)->def || (me)->def->type == VM_METHOD_TYPE_UNDEF)
172
+ #define UNDEFINED_REFINED_METHOD_P(def) \
173
+ ((def)->type == VM_METHOD_TYPE_REFINED && \
174
+ UNDEFINED_METHOD_ENTRY_P((def)->body.refined.orig_me))
175
+
176
+ void rb_add_method_cfunc(VALUE klass, ID mid, VALUE (*func)(ANYARGS), int argc, rb_method_visibility_t visi);
177
+ void rb_add_method_iseq(VALUE klass, ID mid, const rb_iseq_t *iseq, rb_cref_t *cref, rb_method_visibility_t visi);
178
+ void rb_add_refined_method_entry(VALUE refined_class, ID mid);
179
+
180
+ rb_method_entry_t *rb_add_method(VALUE klass, ID mid, rb_method_type_t type, void *option, rb_method_visibility_t visi);
181
+ rb_method_entry_t *rb_method_entry_set(VALUE klass, ID mid, const rb_method_entry_t *, rb_method_visibility_t noex);
182
+ rb_method_entry_t *rb_method_entry_create(ID called_id, VALUE klass, rb_method_visibility_t visi, const rb_method_definition_t *def);
183
+
184
+ const rb_method_entry_t *rb_method_entry_at(VALUE obj, ID id);
185
+
186
+ const rb_method_entry_t *rb_method_entry(VALUE klass, ID id);
187
+ const rb_method_entry_t *rb_method_entry_with_refinements(VALUE klass, ID id);
188
+ const rb_method_entry_t *rb_method_entry_without_refinements(VALUE klass, ID id);
189
+ const rb_method_entry_t *rb_resolve_refined_method(VALUE refinements, const rb_method_entry_t *me);
190
+
191
+ const rb_callable_method_entry_t *rb_callable_method_entry(VALUE klass, ID id);
192
+ const rb_callable_method_entry_t *rb_callable_method_entry_with_refinements(VALUE klass, ID id);
193
+ const rb_callable_method_entry_t *rb_callable_method_entry_without_refinements(VALUE klass, ID id);
194
+ const rb_callable_method_entry_t *rb_resolve_refined_method_callable(VALUE refinements, const rb_callable_method_entry_t *me);
195
+
196
+ int rb_method_entry_arity(const rb_method_entry_t *me);
197
+ int rb_method_entry_eq(const rb_method_entry_t *m1, const rb_method_entry_t *m2);
198
+ st_index_t rb_hash_method_entry(st_index_t hash, const rb_method_entry_t *me);
199
+
200
+ VALUE rb_method_entry_location(const rb_method_entry_t *me);
201
+ VALUE rb_mod_method_location(VALUE mod, ID id);
202
+ VALUE rb_obj_method_location(VALUE obj, ID id);
203
+
204
+ void rb_free_method_entry(const rb_method_entry_t *me);
205
+ void rb_sweep_method_entry(void *vm);
206
+
207
+ const rb_method_entry_t *rb_method_entry_clone(const rb_method_entry_t *me);
208
+ const rb_callable_method_entry_t *rb_method_entry_complement_defined_class(const rb_method_entry_t *src_me, VALUE defined_class);
209
+ void rb_method_entry_copy(rb_method_entry_t *dst, const rb_method_entry_t *src);
210
+
211
+ void rb_scope_visibility_set(rb_method_visibility_t);
212
+
213
+ #endif /* RUBY_METHOD_H */
@@ -1,309 +1,66 @@
1
1
  #include "ruby.h"
2
2
 
3
- #if RUBY_VERSION >= 200
4
- # include "method.h"
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
15
- # include "vm_core.h"
16
- # include "method.h"
17
- #elif RUBY_VERSION >= 192
18
- # include "vm_core.h"
19
- # include "method.h"
20
- # include "ruby/st.h"
21
- #elif RUBY_VERSION >= 190
22
- # include "node-1.9.h"
23
- # include "ruby/st.h"
24
- #else
25
- # include "node.h"
26
- # include "st.h"
3
+ #if RUBY_VERSION >= 230
4
+ # define VM_ASSERT(expr) ((void)0)
27
5
  #endif
28
6
 
7
+ #include "method.h"
8
+ #include "internal.h"
9
+
29
10
  #ifndef Looksee_method_table_foreach
30
11
  # define Looksee_method_table_foreach st_foreach
31
12
  # define Looksee_method_table_lookup st_lookup
32
13
  #endif
33
14
 
34
- #if RUBY_VERSION < 187
35
- # define RCLASS_IV_TBL(c) (RCLASS(c)->iv_tbl)
36
- # define RCLASS_M_TBL(c) (RCLASS(c)->m_tbl)
37
- # define RCLASS_SUPER(c) (RCLASS(c)->super)
38
- #endif
39
-
40
- /*
41
- * Return the internal superclass of this class.
42
- *
43
- * This is either a Class or "IClass." IClasses represent Modules
44
- * included in the ancestry, and should be treated as opaque objects
45
- * in ruby space. Convert the IClass to a Module using #iclass_to_module
46
- * before using it in ruby.
47
- */
48
- VALUE Looksee_internal_superclass(VALUE self, VALUE internal_class) {
49
- VALUE super = RCLASS_SUPER(internal_class);
50
- if (!super)
51
- return Qnil;
52
- return super;
53
- }
54
-
55
- /*
56
- * Return the internal class of the given object.
57
- *
58
- * This is either the object's singleton class, if it exists, or the
59
- * object's birth class.
60
- */
61
- VALUE Looksee_internal_class(VALUE self, VALUE object) {
62
- return CLASS_OF(object);
63
- }
64
-
65
- #if RUBY_VERSION >= 192
66
-
67
- # define VISIBILITY_TYPE rb_method_flag_t
68
-
69
- typedef struct add_method_if_matching_arg {
70
- VALUE names;
71
- VISIBILITY_TYPE visibility;
72
- } add_method_if_matching_arg_t;
73
-
74
- static int add_method_if_matching(ID method_name, rb_method_entry_t *me, add_method_if_matching_arg_t *arg) {
75
- # ifdef ID_ALLOCATOR
76
- if (method_name == ID_ALLOCATOR)
77
- return ST_CONTINUE;
78
- # endif
79
-
80
- if (UNDEFINED_METHOD_ENTRY_P(me))
81
- return ST_CONTINUE;
82
-
83
- if ((me->flag & NOEX_MASK) == arg->visibility)
84
- rb_ary_push(arg->names, ID2SYM(method_name));
85
-
86
- return ST_CONTINUE;
87
- }
88
-
89
15
  static int add_method_if_undefined(ID method_name, rb_method_entry_t *me, VALUE *names) {
90
- # ifdef ID_ALLOCATOR
16
+ #ifdef ID_ALLOCATOR
91
17
  /* The allocator can be undefined with rb_undef_alloc_func, e.g. Struct. */
92
18
  if (method_name == ID_ALLOCATOR)
93
19
  return ST_CONTINUE;
94
- # endif
20
+ #endif
95
21
 
96
22
  if (UNDEFINED_METHOD_ENTRY_P(me))
97
23
  rb_ary_push(*names, ID2SYM(method_name));
98
24
  return ST_CONTINUE;
99
25
  }
100
26
 
101
- #else
102
-
103
- # if RUBY_VERSION >= 190
104
- # define VISIBILITY(node) ((node)->nd_body->nd_noex & NOEX_MASK)
105
- # else
106
- # define VISIBILITY(node) ((node)->nd_noex & NOEX_MASK)
107
- # endif
108
-
109
- # define VISIBILITY_TYPE unsigned long
110
-
111
- typedef struct add_method_if_matching_arg {
112
- VALUE names;
113
- VISIBILITY_TYPE visibility;
114
- } add_method_if_matching_arg_t;
115
-
116
- static int add_method_if_matching(ID method_name, NODE *body, add_method_if_matching_arg_t *arg) {
117
- # ifdef ID_ALLOCATOR
118
- /* This entry is for the internal allocator function. */
119
- if (method_name == ID_ALLOCATOR)
120
- return ST_CONTINUE;
121
- # endif
122
-
123
- /* Module#undef_method:
124
- * * sets body->nd_body to NULL in ruby <= 1.8
125
- * * sets body to NULL in ruby >= 1.9
126
- */
127
- if (!body || !body->nd_body)
128
- return ST_CONTINUE;
129
-
130
- if (VISIBILITY(body) == arg->visibility)
131
- rb_ary_push(arg->names, ID2SYM(method_name));
132
- return ST_CONTINUE;
133
- }
134
-
135
- static int add_method_if_undefined(ID method_name, NODE *body, VALUE *names) {
136
- # ifdef ID_ALLOCATOR
137
- /* The allocator can be undefined with rb_undef_alloc_func, e.g. Struct. */
138
- if (method_name == ID_ALLOCATOR)
139
- return ST_CONTINUE;
140
- # endif
141
-
142
- if (!body || !body->nd_body)
143
- rb_ary_push(*names, ID2SYM(method_name));
144
- return ST_CONTINUE;
145
- }
146
-
147
- #endif
148
-
149
- static VALUE internal_instance_methods(VALUE klass, VISIBILITY_TYPE visibility) {
150
- add_method_if_matching_arg_t arg;
151
- arg.names = rb_ary_new();
152
- arg.visibility = visibility;
153
-
154
- Looksee_method_table_foreach(RCLASS_M_TBL(klass), add_method_if_matching, (st_data_t)&arg);
155
- return arg.names;
156
- }
157
-
158
- /*
159
- * Return the list of public instance methods (as Symbols) of the
160
- * given internal class.
161
- */
162
- VALUE Looksee_internal_public_instance_methods(VALUE self, VALUE klass) {
163
- return internal_instance_methods(klass, NOEX_PUBLIC);
164
- }
165
-
166
- /*
167
- * Return the list of protected instance methods (as Symbols) of the
168
- * given internal class.
169
- */
170
- VALUE Looksee_internal_protected_instance_methods(VALUE self, VALUE klass) {
171
- return internal_instance_methods(klass, NOEX_PROTECTED);
172
- }
173
-
174
- /*
175
- * Return the list of private instance methods (as Symbols) of the
176
- * given internal class.
177
- */
178
- VALUE Looksee_internal_private_instance_methods(VALUE self, VALUE klass) {
179
- return internal_instance_methods(klass, NOEX_PRIVATE);
180
- }
181
-
182
27
  /*
183
28
  * Return the list of undefined instance methods (as Symbols) of the
184
29
  * given internal class.
185
30
  */
186
31
  VALUE Looksee_internal_undefined_instance_methods(VALUE self, VALUE klass) {
32
+ #if RUBY_VERSION >= 230
33
+ static int warned = 0;
34
+ if (!warned) {
35
+ rb_warn("Looksee cannot display undef'd methods on MRI 2.3");
36
+ warned = 1;
37
+ }
38
+ return rb_ary_new();
39
+ #else
187
40
  VALUE names = rb_ary_new();
41
+ if (RCLASS_ORIGIN(klass) != klass)
42
+ klass = RCLASS_ORIGIN(klass);
188
43
  Looksee_method_table_foreach(RCLASS_M_TBL(klass), add_method_if_undefined, (st_data_t)&names);
189
44
  return names;
45
+ #endif
190
46
  }
191
47
 
192
- /*
193
- * Return true if the given object is an included class or origin class, false
194
- * otherwise.
195
- */
196
- VALUE Looksee_included_class_p(VALUE self, VALUE object) {
197
- return !SPECIAL_CONST_P(object) && BUILTIN_TYPE(object) == T_ICLASS ?
198
- Qtrue : Qfalse;
199
- }
200
-
201
- VALUE Looksee_singleton_class_p(VALUE self, VALUE object) {
202
- return BUILTIN_TYPE(object) == T_CLASS && FL_TEST(object, FL_SINGLETON) ? Qtrue : Qfalse;
203
- }
204
-
205
- VALUE Looksee_singleton_instance(VALUE self, VALUE singleton_class) {
206
- if (BUILTIN_TYPE(singleton_class) == T_CLASS && FL_TEST(singleton_class, FL_SINGLETON)) {
48
+ VALUE Looksee_singleton_instance(VALUE self, VALUE klass) {
49
+ if (!SPECIAL_CONST_P(klass) && BUILTIN_TYPE(klass) == T_CLASS && FL_TEST(klass, FL_SINGLETON)) {
207
50
  VALUE object;
208
- if (!Looksee_method_table_lookup(RCLASS_IV_TBL(singleton_class), rb_intern("__attached__"), (st_data_t *)&object))
51
+ if (!Looksee_method_table_lookup(RCLASS_IV_TBL(klass), rb_intern("__attached__"), (st_data_t *)&object))
209
52
  rb_raise(rb_eRuntimeError, "[looksee bug] can't find singleton object");
210
53
  return object;
211
54
  } else {
212
- rb_raise(rb_eTypeError, "expected singleton class, got %s", rb_obj_classname(singleton_class));
213
- }
214
- }
215
-
216
- VALUE Looksee_real_module(VALUE self, VALUE module_or_included_class) {
217
- if (BUILTIN_TYPE(module_or_included_class) == T_ICLASS)
218
- return RBASIC(module_or_included_class)->klass;
219
- else
220
- return module_or_included_class;
221
- }
222
-
223
- VALUE Looksee_module_name(VALUE self, VALUE module) {
224
- if (BUILTIN_TYPE(module) == T_CLASS || BUILTIN_TYPE(module) == T_MODULE) {
225
- VALUE name = rb_mod_name(module);
226
- return name == Qnil ? rb_str_new2("") : name;
227
- } else if (BUILTIN_TYPE(module) == T_ICLASS) {
228
- VALUE wrapped = RBASIC(module)->klass;
229
- VALUE name = Looksee_module_name(self, wrapped);
230
- if (BUILTIN_TYPE(wrapped) == T_CLASS)
231
- name = rb_str_cat2(name, " (origin)");
232
- return name;
233
- } else {
234
- rb_raise(rb_eTypeError, "expected module, got %s", rb_obj_classname(module));
235
- }
236
- }
237
-
238
- #if RUBY_VERSION < 190
239
-
240
- #include "env-1.8.h"
241
- #include "eval_c-1.8.h"
242
-
243
- /*
244
- * Return the source file and line number of the given object and method.
245
- */
246
- VALUE Looksee_source_location(VALUE self, VALUE unbound_method) {
247
- if (!rb_obj_is_kind_of(unbound_method, rb_cUnboundMethod))
248
- rb_raise(rb_eTypeError, "expected UnboundMethod, got %s", rb_obj_classname(unbound_method));
249
-
250
- struct METHOD *method;
251
- Data_Get_Struct(unbound_method, struct METHOD, method);
252
-
253
- NODE *node;
254
- switch (nd_type(method->body)) {
255
- // Can't be a FBODY or ZSUPER.
256
- case NODE_SCOPE:
257
- node = method->body->nd_defn;
258
- break;
259
- case NODE_BMETHOD:
260
- {
261
- struct BLOCK *block;
262
- Data_Get_Struct(method->body->nd_orig, struct BLOCK, block);
263
- (node = block->frame.node) || (node = block->body);
264
- // Proc#to_s suggests this may be NULL sometimes.
265
- if (!node)
266
- return Qnil;
267
- }
268
- break;
269
- case NODE_DMETHOD:
270
- {
271
- struct METHOD *original_method;
272
- NODE *body = method->body;
273
- Data_Get_Struct(body->nd_orig, struct METHOD, original_method);
274
- node = original_method->body->nd_defn;
275
- }
276
- break;
277
- default:
278
55
  return Qnil;
279
56
  }
280
- VALUE file = rb_str_new2(node->nd_file);
281
- VALUE line = INT2NUM(nd_line(node));
282
- VALUE location = rb_ary_new2(2);
283
- rb_ary_store(location, 0, file);
284
- rb_ary_store(location, 1, line);
285
- return location;
286
57
  }
287
58
 
288
- #endif
289
-
290
59
  void Init_mri(void) {
291
60
  VALUE mLooksee = rb_const_get(rb_cObject, rb_intern("Looksee"));
292
61
  VALUE mAdapter = rb_const_get(mLooksee, rb_intern("Adapter"));
293
62
  VALUE mBase = rb_const_get(mAdapter, rb_intern("Base"));
294
63
  VALUE mMRI = rb_define_class_under(mAdapter, "MRI", mBase);
295
- rb_define_method(mMRI, "internal_superclass", Looksee_internal_superclass, 1);
296
- rb_define_method(mMRI, "internal_class", Looksee_internal_class, 1);
297
- rb_define_method(mMRI, "internal_public_instance_methods", Looksee_internal_public_instance_methods, 1);
298
- rb_define_method(mMRI, "internal_protected_instance_methods", Looksee_internal_protected_instance_methods, 1);
299
- rb_define_method(mMRI, "internal_private_instance_methods", Looksee_internal_private_instance_methods, 1);
300
64
  rb_define_method(mMRI, "internal_undefined_instance_methods", Looksee_internal_undefined_instance_methods, 1);
301
- rb_define_method(mMRI, "included_class?", Looksee_included_class_p, 1);
302
- rb_define_method(mMRI, "singleton_class?", Looksee_singleton_class_p, 1);
303
65
  rb_define_method(mMRI, "singleton_instance", Looksee_singleton_instance, 1);
304
- rb_define_method(mMRI, "real_module", Looksee_real_module, 1);
305
- rb_define_method(mMRI, "module_name", Looksee_module_name, 1);
306
- #if RUBY_VERSION < 190
307
- rb_define_method(mMRI, "source_location", Looksee_source_location, 1);
308
- #endif
309
66
  }