looksee 3.1.0 → 4.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG +25 -0
  3. data/README.markdown +75 -79
  4. data/ext/extconf.rb +7 -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/2.7.0/internal.h +2697 -0
  8. data/ext/mri/2.7.0/method.h +229 -0
  9. data/ext/mri/3.0.0/id_table.h +36 -0
  10. data/ext/mri/3.0.0/internal.h +107 -0
  11. data/ext/mri/3.0.0/internal/array.h +119 -0
  12. data/ext/mri/3.0.0/internal/class.h +174 -0
  13. data/ext/mri/3.0.0/internal/compilers.h +108 -0
  14. data/ext/mri/3.0.0/internal/gc.h +161 -0
  15. data/ext/mri/3.0.0/internal/imemo.h +243 -0
  16. data/ext/mri/3.0.0/internal/serial.h +24 -0
  17. data/ext/mri/3.0.0/internal/static_assert.h +17 -0
  18. data/ext/mri/3.0.0/internal/warnings.h +17 -0
  19. data/ext/mri/3.0.0/method.h +246 -0
  20. data/ext/mri/mri.c +20 -261
  21. data/ext/rbx/rbx.c +0 -9
  22. data/lib/looksee/adapter/base.rb +19 -54
  23. data/lib/looksee/adapter/rubinius.rb +3 -62
  24. data/lib/looksee/clean.rb +5 -1
  25. data/lib/looksee/editor.rb +1 -1
  26. data/lib/looksee/help.rb +3 -2
  27. data/lib/looksee/lookup_path.rb +7 -3
  28. data/lib/looksee/mri.bundle +0 -0
  29. data/lib/looksee/version.rb +1 -1
  30. data/spec/looksee/adapter_spec.rb +78 -367
  31. data/spec/looksee/editor_spec.rb +1 -1
  32. data/spec/looksee/inspector_spec.rb +21 -21
  33. data/spec/looksee/lookup_path_spec.rb +34 -21
  34. data/spec/spec_helper.rb +2 -0
  35. data/spec/support/temporary_classes.rb +10 -14
  36. data/spec/support/test_adapter.rb +2 -53
  37. metadata +24 -33
  38. data/ext/mri/1.9.2/debug.h +0 -36
  39. data/ext/mri/1.9.2/id.h +0 -170
  40. data/ext/mri/1.9.2/method.h +0 -103
  41. data/ext/mri/1.9.2/node.h +0 -483
  42. data/ext/mri/1.9.2/thread_pthread.h +0 -27
  43. data/ext/mri/1.9.2/vm_core.h +0 -707
  44. data/ext/mri/1.9.2/vm_opts.h +0 -51
  45. data/ext/mri/1.9.3/atomic.h +0 -56
  46. data/ext/mri/1.9.3/debug.h +0 -41
  47. data/ext/mri/1.9.3/id.h +0 -175
  48. data/ext/mri/1.9.3/internal.h +0 -227
  49. data/ext/mri/1.9.3/internal_falcon.h +0 -248
  50. data/ext/mri/1.9.3/method.h +0 -105
  51. data/ext/mri/1.9.3/node.h +0 -503
  52. data/ext/mri/1.9.3/thread_pthread.h +0 -51
  53. data/ext/mri/1.9.3/vm_core.h +0 -755
  54. data/ext/mri/1.9.3/vm_opts.h +0 -51
  55. data/ext/mri/2.0.0/internal.h +0 -378
  56. data/ext/mri/2.0.0/method.h +0 -138
  57. data/ext/mri/env-1.8.h +0 -27
  58. data/ext/mri/eval_c-1.8.h +0 -27
  59. data/ext/mri/node-1.9.h +0 -35
  60. data/lib/looksee/JRuby.jar +0 -0
  61. data/lib/looksee/rbx.bundle +0 -0
@@ -0,0 +1,24 @@
1
+ #ifndef INTERNAL_SERIAL_H /*-*-C-*-vi:se ft=c:*/
2
+ #define INTERNAL_SERIAL_H
3
+ /**
4
+ * @file
5
+ * @author Ruby developers <ruby-core@ruby-lang.org>
6
+ * @copyright This file is a part of the programming language Ruby.
7
+ * Permission is hereby granted, to either redistribute and/or
8
+ * modify this file, provided that the conditions mentioned in the
9
+ * file COPYING are met. Consult the file for details.
10
+ * @brief Internal header for rb_serial_t.
11
+ */
12
+ #include "ruby/internal/config.h" /* for HAVE_LONG_LONG */
13
+ #include "ruby/defines.h" /* for LONG_LONG */
14
+
15
+ #ifndef HAVE_LONG_LONG
16
+ # error need C99+
17
+ #endif
18
+
19
+ typedef unsigned LONG_LONG rb_serial_t;
20
+ #define SERIALT2NUM ULL2NUM
21
+ #define PRI_SERIALT_PREFIX PRI_LL_PREFIX
22
+ #define SIZEOF_SERIAL_T SIZEOF_LONG_LONG
23
+
24
+ #endif /* INTERNAL_SERIAL_H */
@@ -0,0 +1,17 @@
1
+ #ifndef INTERNAL_STATIC_ASSERT_H /*-*-C-*-vi:se ft=c:*/
2
+ #define INTERNAL_STATIC_ASSERT_H
3
+ /**
4
+ * @file
5
+ * @author Ruby developers <ruby-core@ruby-lang.org>
6
+ * @copyright This file is a part of the programming language Ruby.
7
+ * Permission is hereby granted, to either redistribute and/or
8
+ * modify this file, provided that the conditions mentioned in the
9
+ * file COPYING are met. Consult the file for details.
10
+ * @brief C11 shim for _Static_assert.
11
+ */
12
+ #include "ruby/internal/static_assert.h"
13
+ #ifndef STATIC_ASSERT
14
+ # define STATIC_ASSERT RBIMPL_STATIC_ASSERT
15
+ #endif
16
+
17
+ #endif /* INTERNAL_STATIC_ASSERT_H */
@@ -0,0 +1,17 @@
1
+ #ifndef INTERNAL_WARNINGS_H /*-*-C-*-vi:se ft=c:*/
2
+ #define INTERNAL_WARNINGS_H
3
+ /**
4
+ * @file
5
+ * @author Ruby developers <ruby-core@ruby-lang.org>
6
+ * @copyright This file is a part of the programming language Ruby.
7
+ * Permission is hereby granted, to either redistribute and/or
8
+ * modify this file, provided that the conditions mentioned in the
9
+ * file COPYING are met. Consult the file for details.
10
+ * @brief Internal header to suppres / mandate warnings.
11
+ */
12
+ #include "ruby/internal/warning_push.h"
13
+ #define COMPILER_WARNING_PUSH RBIMPL_WARNING_PUSH()
14
+ #define COMPILER_WARNING_POP RBIMPL_WARNING_POP()
15
+ #define COMPILER_WARNING_ERROR(flag) RBIMPL_WARNING_ERROR(flag)
16
+ #define COMPILER_WARNING_IGNORED(flag) RBIMPL_WARNING_IGNORED(flag)
17
+ #endif /* INTERNAL_WARNINGS_H */
@@ -0,0 +1,246 @@
1
+ #ifndef RUBY_METHOD_H
2
+ #define RUBY_METHOD_H 1
3
+ /**********************************************************************
4
+ *
5
+ * method.h -
6
+ *
7
+ * $Author$
8
+ * created at: Wed Jul 15 20:02:33 2009
9
+ *
10
+ * Copyright (C) 2009 Koichi Sasada
11
+ *
12
+ **********************************************************************/
13
+
14
+ #include "internal.h"
15
+ #include "internal/imemo.h"
16
+ #include "internal/compilers.h"
17
+ #include "internal/static_assert.h"
18
+ #include "internal/class.h"
19
+
20
+ #ifndef END_OF_ENUMERATION
21
+ # if defined(__GNUC__) &&! defined(__STRICT_ANSI__)
22
+ # define END_OF_ENUMERATION(key)
23
+ # else
24
+ # define END_OF_ENUMERATION(key) END_OF_##key##_PLACEHOLDER = 0
25
+ # endif
26
+ #endif
27
+
28
+ /* cref */
29
+
30
+ typedef enum {
31
+ METHOD_VISI_UNDEF = 0x00,
32
+ METHOD_VISI_PUBLIC = 0x01,
33
+ METHOD_VISI_PRIVATE = 0x02,
34
+ METHOD_VISI_PROTECTED = 0x03,
35
+
36
+ METHOD_VISI_MASK = 0x03
37
+ } rb_method_visibility_t;
38
+
39
+ typedef struct rb_scope_visi_struct {
40
+ BITFIELD(rb_method_visibility_t, method_visi, 3);
41
+ unsigned int module_func : 1;
42
+ } rb_scope_visibility_t;
43
+
44
+ /*! CREF (Class REFerence) */
45
+ typedef struct rb_cref_struct {
46
+ VALUE flags;
47
+ VALUE refinements;
48
+ VALUE klass;
49
+ struct rb_cref_struct * next;
50
+ const rb_scope_visibility_t scope_visi;
51
+ } rb_cref_t;
52
+
53
+ /* method data type */
54
+
55
+ typedef struct rb_method_entry_struct {
56
+ VALUE flags;
57
+ VALUE defined_class;
58
+ struct rb_method_definition_struct * const def;
59
+ ID called_id;
60
+ VALUE owner;
61
+ } rb_method_entry_t;
62
+
63
+ typedef struct rb_callable_method_entry_struct { /* same fields with rb_method_entry_t */
64
+ VALUE flags;
65
+ const VALUE defined_class;
66
+ struct rb_method_definition_struct * const def;
67
+ ID called_id;
68
+ const VALUE owner;
69
+ } rb_callable_method_entry_t;
70
+
71
+ #define METHOD_ENTRY_VISI(me) (rb_method_visibility_t)(((me)->flags & (IMEMO_FL_USER0 | IMEMO_FL_USER1)) >> (IMEMO_FL_USHIFT+0))
72
+ #define METHOD_ENTRY_BASIC(me) (int) (((me)->flags & (IMEMO_FL_USER2 )) >> (IMEMO_FL_USHIFT+2))
73
+ #define METHOD_ENTRY_COMPLEMENTED(me) ((me)->flags & IMEMO_FL_USER3)
74
+ #define METHOD_ENTRY_COMPLEMENTED_SET(me) ((me)->flags |= IMEMO_FL_USER3)
75
+ #define METHOD_ENTRY_CACHED(me) ((me)->flags & IMEMO_FL_USER4)
76
+ #define METHOD_ENTRY_CACHED_SET(me) ((me)->flags |= IMEMO_FL_USER4)
77
+ #define METHOD_ENTRY_INVALIDATED(me) ((me)->flags & IMEMO_FL_USER5)
78
+ #define METHOD_ENTRY_INVALIDATED_SET(me) ((me)->flags |= IMEMO_FL_USER5)
79
+ #define METHOD_ENTRY_CACHEABLE(me) !(METHOD_ENTRY_VISI(me) == METHOD_VISI_PROTECTED)
80
+
81
+ static inline void
82
+ METHOD_ENTRY_VISI_SET(rb_method_entry_t *me, rb_method_visibility_t visi)
83
+ {
84
+ VM_ASSERT((int)visi >= 0 && visi <= 3);
85
+ me->flags = (me->flags & ~(IMEMO_FL_USER0 | IMEMO_FL_USER1)) | (visi << (IMEMO_FL_USHIFT+0));
86
+ }
87
+ static inline void
88
+ METHOD_ENTRY_BASIC_SET(rb_method_entry_t *me, unsigned int basic)
89
+ {
90
+ VM_ASSERT(basic <= 1);
91
+ me->flags = (me->flags & ~(IMEMO_FL_USER2 )) | (basic << (IMEMO_FL_USHIFT+2));
92
+ }
93
+ static inline void
94
+ METHOD_ENTRY_FLAGS_SET(rb_method_entry_t *me, rb_method_visibility_t visi, unsigned int basic)
95
+ {
96
+ VM_ASSERT((int)visi >= 0 && visi <= 3);
97
+ VM_ASSERT(basic <= 1);
98
+ me->flags =
99
+ (me->flags & ~(IMEMO_FL_USER0|IMEMO_FL_USER1|IMEMO_FL_USER2)) |
100
+ ((visi << (IMEMO_FL_USHIFT+0)) | (basic << (IMEMO_FL_USHIFT+2)));
101
+ }
102
+ static inline void
103
+ METHOD_ENTRY_FLAGS_COPY(rb_method_entry_t *dst, const rb_method_entry_t *src)
104
+ {
105
+ dst->flags =
106
+ (dst->flags & ~(IMEMO_FL_USER0|IMEMO_FL_USER1|IMEMO_FL_USER2)) |
107
+ (src->flags & (IMEMO_FL_USER0|IMEMO_FL_USER1|IMEMO_FL_USER2));
108
+ }
109
+
110
+ typedef enum {
111
+ VM_METHOD_TYPE_ISEQ, /*!< Ruby method */
112
+ VM_METHOD_TYPE_CFUNC, /*!< C method */
113
+ VM_METHOD_TYPE_ATTRSET, /*!< attr_writer or attr_accessor */
114
+ VM_METHOD_TYPE_IVAR, /*!< attr_reader or attr_accessor */
115
+ VM_METHOD_TYPE_BMETHOD,
116
+ VM_METHOD_TYPE_ZSUPER,
117
+ VM_METHOD_TYPE_ALIAS,
118
+ VM_METHOD_TYPE_UNDEF,
119
+ VM_METHOD_TYPE_NOTIMPLEMENTED,
120
+ VM_METHOD_TYPE_OPTIMIZED, /*!< Kernel#send, Proc#call, etc */
121
+ VM_METHOD_TYPE_MISSING, /*!< wrapper for method_missing(id) */
122
+ VM_METHOD_TYPE_REFINED, /*!< refinement */
123
+
124
+ END_OF_ENUMERATION(VM_METHOD_TYPE)
125
+ } rb_method_type_t;
126
+ #define VM_METHOD_TYPE_MINIMUM_BITS 4
127
+ STATIC_ASSERT(VM_METHOD_TYPE_MINIMUM_BITS,
128
+ VM_METHOD_TYPE_REFINED <= (1<<VM_METHOD_TYPE_MINIMUM_BITS));
129
+
130
+ #ifndef rb_iseq_t
131
+ typedef struct rb_iseq_struct rb_iseq_t;
132
+ #define rb_iseq_t rb_iseq_t
133
+ #endif
134
+
135
+ typedef struct rb_method_iseq_struct {
136
+ rb_iseq_t * iseqptr; /*!< iseq pointer, should be separated from iseqval */
137
+ rb_cref_t * cref; /*!< class reference, should be marked */
138
+ } rb_method_iseq_t; /* check rb_add_method_iseq() when modify the fields */
139
+
140
+ typedef struct rb_method_cfunc_struct {
141
+ VALUE (*func)(ANYARGS);
142
+ VALUE (*invoker)(VALUE recv, int argc, const VALUE *argv, VALUE (*func)(ANYARGS));
143
+ int argc;
144
+ } rb_method_cfunc_t;
145
+
146
+ typedef struct rb_method_attr_struct {
147
+ ID id;
148
+ VALUE location; /* should be marked */
149
+ } rb_method_attr_t;
150
+
151
+ typedef struct rb_method_alias_struct {
152
+ struct rb_method_entry_struct * original_me; /* original_me->klass is original owner */
153
+ } rb_method_alias_t;
154
+
155
+ typedef struct rb_method_refined_struct {
156
+ struct rb_method_entry_struct * orig_me;
157
+ VALUE owner;
158
+ } rb_method_refined_t;
159
+
160
+ typedef struct rb_method_bmethod_struct {
161
+ VALUE proc; /* should be marked */
162
+ struct rb_hook_list_struct *hooks;
163
+ VALUE defined_ractor;
164
+ } rb_method_bmethod_t;
165
+
166
+ enum method_optimized_type {
167
+ OPTIMIZED_METHOD_TYPE_SEND,
168
+ OPTIMIZED_METHOD_TYPE_CALL,
169
+ OPTIMIZED_METHOD_TYPE_BLOCK_CALL,
170
+ OPTIMIZED_METHOD_TYPE__MAX
171
+ };
172
+
173
+ struct rb_method_definition_struct {
174
+ BITFIELD(rb_method_type_t, type, VM_METHOD_TYPE_MINIMUM_BITS);
175
+ int alias_count : 28;
176
+ int complemented_count : 28;
177
+
178
+ union {
179
+ rb_method_iseq_t iseq;
180
+ rb_method_cfunc_t cfunc;
181
+ rb_method_attr_t attr;
182
+ rb_method_alias_t alias;
183
+ rb_method_refined_t refined;
184
+ rb_method_bmethod_t bmethod;
185
+
186
+ enum method_optimized_type optimize_type;
187
+ } body;
188
+
189
+ ID original_id;
190
+ uintptr_t method_serial;
191
+ };
192
+
193
+ struct rb_id_table;
194
+
195
+ typedef struct rb_method_definition_struct rb_method_definition_t;
196
+ STATIC_ASSERT(sizeof_method_def, offsetof(rb_method_definition_t, body)==8);
197
+
198
+ #define UNDEFINED_METHOD_ENTRY_P(me) (!(me) || !(me)->def || (me)->def->type == VM_METHOD_TYPE_UNDEF)
199
+ #define UNDEFINED_REFINED_METHOD_P(def) \
200
+ ((def)->type == VM_METHOD_TYPE_REFINED && \
201
+ UNDEFINED_METHOD_ENTRY_P((def)->body.refined.orig_me))
202
+
203
+ void rb_add_method_cfunc(VALUE klass, ID mid, VALUE (*func)(ANYARGS), int argc, rb_method_visibility_t visi);
204
+ void rb_add_method_iseq(VALUE klass, ID mid, const rb_iseq_t *iseq, rb_cref_t *cref, rb_method_visibility_t visi);
205
+ void rb_add_refined_method_entry(VALUE refined_class, ID mid);
206
+ void rb_add_method(VALUE klass, ID mid, rb_method_type_t type, void *option, rb_method_visibility_t visi);
207
+
208
+ rb_method_entry_t *rb_method_entry_set(VALUE klass, ID mid, const rb_method_entry_t *, rb_method_visibility_t noex);
209
+ rb_method_entry_t *rb_method_entry_create(ID called_id, VALUE klass, rb_method_visibility_t visi, const rb_method_definition_t *def);
210
+
211
+ const rb_method_entry_t *rb_method_entry_at(VALUE obj, ID id);
212
+
213
+ const rb_method_entry_t *rb_method_entry(VALUE klass, ID id);
214
+ const rb_method_entry_t *rb_method_entry_with_refinements(VALUE klass, ID id, VALUE *defined_class);
215
+ const rb_method_entry_t *rb_method_entry_without_refinements(VALUE klass, ID id, VALUE *defined_class);
216
+ const rb_method_entry_t *rb_resolve_refined_method(VALUE refinements, const rb_method_entry_t *me);
217
+ RUBY_SYMBOL_EXPORT_BEGIN
218
+ const rb_method_entry_t *rb_resolve_me_location(const rb_method_entry_t *, VALUE[5]);
219
+ RUBY_SYMBOL_EXPORT_END
220
+
221
+ const rb_callable_method_entry_t *rb_callable_method_entry(VALUE klass, ID id);
222
+ const rb_callable_method_entry_t *rb_callable_method_entry_with_refinements(VALUE klass, ID id, VALUE *defined_class);
223
+ const rb_callable_method_entry_t *rb_callable_method_entry_without_refinements(VALUE klass, ID id, VALUE *defined_class);
224
+
225
+ int rb_method_entry_arity(const rb_method_entry_t *me);
226
+ int rb_method_entry_eq(const rb_method_entry_t *m1, const rb_method_entry_t *m2);
227
+ st_index_t rb_hash_method_entry(st_index_t hash, const rb_method_entry_t *me);
228
+
229
+ VALUE rb_method_entry_location(const rb_method_entry_t *me);
230
+
231
+ void rb_free_method_entry(const rb_method_entry_t *me);
232
+
233
+ const rb_method_entry_t *rb_method_entry_clone(const rb_method_entry_t *me);
234
+ const rb_callable_method_entry_t *rb_method_entry_complement_defined_class(const rb_method_entry_t *src_me, ID called_id, VALUE defined_class);
235
+ void rb_method_entry_copy(rb_method_entry_t *dst, const rb_method_entry_t *src);
236
+
237
+ void rb_method_table_insert(VALUE klass, struct rb_id_table *table, ID method_id, const rb_method_entry_t *me);
238
+
239
+ void rb_scope_visibility_set(rb_method_visibility_t);
240
+
241
+ VALUE rb_unnamed_parameters(int arity);
242
+
243
+ void rb_clear_method_cache(VALUE klass_or_module, ID mid);
244
+ void rb_clear_method_cache_all(void);
245
+
246
+ #endif /* RUBY_METHOD_H */
@@ -1,91 +1,18 @@
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
-
15
+ #if RUBY_VERSION < 230
89
16
  static int add_method_if_undefined(ID method_name, rb_method_entry_t *me, VALUE *names) {
90
17
  # ifdef ID_ALLOCATOR
91
18
  /* The allocator can be undefined with rb_undef_alloc_func, e.g. Struct. */
@@ -97,213 +24,45 @@ static int add_method_if_undefined(ID method_name, rb_method_entry_t *me, VALUE
97
24
  rb_ary_push(*names, ID2SYM(method_name));
98
25
  return ST_CONTINUE;
99
26
  }
100
-
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
27
  #endif
148
28
 
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
29
  /*
183
30
  * Return the list of undefined instance methods (as Symbols) of the
184
31
  * given internal class.
185
32
  */
186
33
  VALUE Looksee_internal_undefined_instance_methods(VALUE self, VALUE klass) {
34
+ #if RUBY_VERSION >= 230
35
+ static int warned = 0;
36
+ if (!warned) {
37
+ rb_warn("Looksee cannot display undef-ed methods on MRI 2.3 or later");
38
+ warned = 1;
39
+ }
40
+ return rb_ary_new();
41
+ #else
187
42
  VALUE names = rb_ary_new();
43
+ if (RCLASS_ORIGIN(klass) != klass)
44
+ klass = RCLASS_ORIGIN(klass);
188
45
  Looksee_method_table_foreach(RCLASS_M_TBL(klass), add_method_if_undefined, (st_data_t)&names);
189
46
  return names;
47
+ #endif
190
48
  }
191
49
 
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)) {
50
+ VALUE Looksee_singleton_instance(VALUE self, VALUE klass) {
51
+ if (!SPECIAL_CONST_P(klass) && BUILTIN_TYPE(klass) == T_CLASS && FL_TEST(klass, FL_SINGLETON)) {
207
52
  VALUE object;
208
- if (!Looksee_method_table_lookup(RCLASS_IV_TBL(singleton_class), rb_intern("__attached__"), (st_data_t *)&object))
53
+ if (!Looksee_method_table_lookup(RCLASS_IV_TBL(klass), rb_intern("__attached__"), (st_data_t *)&object))
209
54
  rb_raise(rb_eRuntimeError, "[looksee bug] can't find singleton object");
210
55
  return object;
211
56
  } 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
57
  return Qnil;
279
58
  }
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
59
  }
287
60
 
288
- #endif
289
-
290
61
  void Init_mri(void) {
291
62
  VALUE mLooksee = rb_const_get(rb_cObject, rb_intern("Looksee"));
292
63
  VALUE mAdapter = rb_const_get(mLooksee, rb_intern("Adapter"));
293
64
  VALUE mBase = rb_const_get(mAdapter, rb_intern("Base"));
294
65
  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
66
  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
67
  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
68
  }