looksee 4.2.0 → 5.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 +15 -0
  3. data/Rakefile +27 -0
  4. data/ext/extconf.rb +6 -7
  5. data/ext/mri/3.0.0/id_table.h +36 -0
  6. data/ext/mri/3.0.0/internal/array.h +119 -0
  7. data/ext/mri/3.0.0/internal/class.h +174 -0
  8. data/ext/mri/3.0.0/internal/compilers.h +108 -0
  9. data/ext/mri/3.0.0/internal/gc.h +161 -0
  10. data/ext/mri/3.0.0/internal/imemo.h +243 -0
  11. data/ext/mri/3.0.0/internal/serial.h +24 -0
  12. data/ext/mri/3.0.0/internal/static_assert.h +17 -0
  13. data/ext/mri/3.0.0/internal/warnings.h +17 -0
  14. data/ext/mri/3.0.0/internal.h +107 -0
  15. data/ext/mri/3.0.0/method.h +246 -0
  16. data/ext/mri/3.2.0/id_table.h +36 -0
  17. data/ext/mri/3.2.0/internal/array.h +162 -0
  18. data/ext/mri/3.2.0/internal/class.h +212 -0
  19. data/ext/mri/3.2.0/internal/compilers.h +107 -0
  20. data/ext/mri/3.2.0/internal/gc.h +188 -0
  21. data/ext/mri/3.2.0/internal/imemo.h +242 -0
  22. data/ext/mri/3.2.0/internal/serial.h +23 -0
  23. data/ext/mri/3.2.0/internal/static_assert.h +16 -0
  24. data/ext/mri/3.2.0/internal/warnings.h +16 -0
  25. data/ext/mri/3.2.0/internal.h +113 -0
  26. data/ext/mri/{2.3.0 → 3.2.0}/method.h +95 -55
  27. data/ext/mri/mri.c +7 -37
  28. data/lib/looksee/adapter/base.rb +17 -3
  29. data/lib/looksee/adapter.rb +0 -1
  30. data/lib/looksee/clean.rb +1 -3
  31. data/lib/looksee/core_ext.rb +21 -9
  32. data/lib/looksee/help.rb +2 -2
  33. data/lib/looksee/inspector.rb +11 -0
  34. data/lib/looksee/lookup_path.rb +1 -1
  35. data/lib/looksee/version.rb +1 -1
  36. data/spec/looksee/adapter_spec.rb +53 -47
  37. data/spec/looksee/core_ext_spec.rb +2 -2
  38. data/spec/looksee/inspector_spec.rb +42 -0
  39. data/spec/looksee/lookup_path_spec.rb +1 -1
  40. metadata +34 -20
  41. data/ext/mri/2.1.0/internal.h +0 -889
  42. data/ext/mri/2.1.0/method.h +0 -142
  43. data/ext/mri/2.2.0/internal.h +0 -1182
  44. data/ext/mri/2.2.0/method.h +0 -141
  45. data/ext/mri/2.3.0/internal.h +0 -1404
  46. data/ext/rbx/rbx.c +0 -4
  47. data/lib/looksee/adapter/rubinius.rb +0 -25
@@ -0,0 +1,162 @@
1
+ #ifndef INTERNAL_ARRAY_H /*-*-C-*-vi:se ft=c:*/
2
+ #define INTERNAL_ARRAY_H
3
+ /**
4
+ * @author Ruby developers <ruby-core@ruby-lang.org>
5
+ * @copyright This file is a part of the programming language Ruby.
6
+ * Permission is hereby granted, to either redistribute and/or
7
+ * modify this file, provided that the conditions mentioned in the
8
+ * file COPYING are met. Consult the file for details.
9
+ * @brief Internal header for Array.
10
+ */
11
+ #include "ruby/internal/config.h"
12
+ #include <stddef.h> /* for size_t */
13
+ #include "internal/static_assert.h" /* for STATIC_ASSERT */
14
+ #include "ruby/internal/stdbool.h" /* for bool */
15
+ #include "ruby/ruby.h" /* for RARRAY_LEN */
16
+
17
+ #ifndef ARRAY_DEBUG
18
+ # define ARRAY_DEBUG (0+RUBY_DEBUG)
19
+ #endif
20
+
21
+ #define RARRAY_SHARED_FLAG ELTS_SHARED
22
+ #define RARRAY_SHARED_ROOT_FLAG FL_USER12
23
+ #define RARRAY_PTR_IN_USE_FLAG FL_USER14
24
+
25
+ /* array.c */
26
+ VALUE rb_ary_last(int, const VALUE *, VALUE);
27
+ void rb_ary_set_len(VALUE, long);
28
+ void rb_ary_delete_same(VALUE, VALUE);
29
+ VALUE rb_ary_hidden_new_fill(long capa);
30
+ VALUE rb_ary_at(VALUE, VALUE);
31
+ size_t rb_ary_memsize(VALUE);
32
+ VALUE rb_to_array_type(VALUE obj);
33
+ VALUE rb_to_array(VALUE obj);
34
+ void rb_ary_cancel_sharing(VALUE ary);
35
+ size_t rb_ary_size_as_embedded(VALUE ary);
36
+ void rb_ary_make_embedded(VALUE ary);
37
+ bool rb_ary_embeddable_p(VALUE ary);
38
+
39
+ static inline VALUE rb_ary_entry_internal(VALUE ary, long offset);
40
+ static inline bool ARY_PTR_USING_P(VALUE ary);
41
+ static inline void RARY_TRANSIENT_SET(VALUE ary);
42
+ static inline void RARY_TRANSIENT_UNSET(VALUE ary);
43
+
44
+ MJIT_SYMBOL_EXPORT_BEGIN
45
+ VALUE rb_ary_tmp_new_from_values(VALUE, long, const VALUE *);
46
+ VALUE rb_check_to_array(VALUE ary);
47
+ VALUE rb_ary_behead(VALUE, long);
48
+ VALUE rb_ary_aref1(VALUE ary, VALUE i);
49
+
50
+ struct rb_execution_context_struct;
51
+ VALUE rb_ec_ary_new_from_values(struct rb_execution_context_struct *ec, long n, const VALUE *elts);
52
+ MJIT_SYMBOL_EXPORT_END
53
+
54
+ // YJIT needs this function to never allocate and never raise
55
+ static inline VALUE
56
+ rb_ary_entry_internal(VALUE ary, long offset)
57
+ {
58
+ long len = RARRAY_LEN(ary);
59
+ const VALUE *ptr = RARRAY_CONST_PTR_TRANSIENT(ary);
60
+ if (len == 0) return Qnil;
61
+ if (offset < 0) {
62
+ offset += len;
63
+ if (offset < 0) return Qnil;
64
+ }
65
+ else if (len <= offset) {
66
+ return Qnil;
67
+ }
68
+ return ptr[offset];
69
+ }
70
+
71
+ static inline bool
72
+ ARY_PTR_USING_P(VALUE ary)
73
+ {
74
+ return FL_TEST_RAW(ary, RARRAY_PTR_IN_USE_FLAG);
75
+ }
76
+
77
+ RBIMPL_ATTR_MAYBE_UNUSED()
78
+ static inline int
79
+ ary_should_not_be_shared_and_embedded(VALUE ary)
80
+ {
81
+ return !FL_ALL_RAW(ary, RARRAY_SHARED_FLAG|RARRAY_EMBED_FLAG);
82
+ }
83
+
84
+ static inline bool
85
+ ARY_SHARED_P(VALUE ary)
86
+ {
87
+ assert(RB_TYPE_P(ary, T_ARRAY));
88
+ assert(ary_should_not_be_shared_and_embedded(ary));
89
+ return FL_TEST_RAW(ary, RARRAY_SHARED_FLAG);
90
+ }
91
+
92
+ static inline bool
93
+ ARY_EMBED_P(VALUE ary)
94
+ {
95
+ assert(RB_TYPE_P(ary, T_ARRAY));
96
+ assert(ary_should_not_be_shared_and_embedded(ary));
97
+ return FL_TEST_RAW(ary, RARRAY_EMBED_FLAG);
98
+ }
99
+
100
+ static inline VALUE
101
+ ARY_SHARED_ROOT(VALUE ary)
102
+ {
103
+ assert(ARY_SHARED_P(ary));
104
+ return RARRAY(ary)->as.heap.aux.shared_root;
105
+ }
106
+
107
+ static inline bool
108
+ ARY_SHARED_ROOT_P(VALUE ary)
109
+ {
110
+ assert(RB_TYPE_P(ary, T_ARRAY));
111
+ return FL_TEST_RAW(ary, RARRAY_SHARED_ROOT_FLAG);
112
+ }
113
+
114
+ static inline long
115
+ ARY_SHARED_ROOT_REFCNT(VALUE ary)
116
+ {
117
+ assert(ARY_SHARED_ROOT_P(ary));
118
+ return RARRAY(ary)->as.heap.aux.capa;
119
+ }
120
+
121
+ static inline void
122
+ RARY_TRANSIENT_SET(VALUE ary)
123
+ {
124
+ #if USE_TRANSIENT_HEAP
125
+ FL_SET_RAW(ary, RARRAY_TRANSIENT_FLAG);
126
+ #endif
127
+ }
128
+
129
+ static inline void
130
+ RARY_TRANSIENT_UNSET(VALUE ary)
131
+ {
132
+ #if USE_TRANSIENT_HEAP
133
+ FL_UNSET_RAW(ary, RARRAY_TRANSIENT_FLAG);
134
+ #endif
135
+ }
136
+
137
+ #undef rb_ary_new_from_args
138
+ #if RBIMPL_HAS_WARNING("-Wgnu-zero-variadic-macro-arguments")
139
+ # /* Skip it; clang -pedantic doesn't like the following */
140
+ #elif defined(__GNUC__) && defined(HAVE_VA_ARGS_MACRO)
141
+ #define rb_ary_new_from_args(n, ...) \
142
+ __extension__ ({ \
143
+ const VALUE args_to_new_ary[] = {__VA_ARGS__}; \
144
+ if (__builtin_constant_p(n)) { \
145
+ STATIC_ASSERT(rb_ary_new_from_args, numberof(args_to_new_ary) == (n)); \
146
+ } \
147
+ rb_ary_new_from_values(numberof(args_to_new_ary), args_to_new_ary); \
148
+ })
149
+ #endif
150
+
151
+ #undef RARRAY_AREF
152
+ RBIMPL_ATTR_PURE_UNLESS_DEBUG()
153
+ RBIMPL_ATTR_ARTIFICIAL()
154
+ static inline VALUE
155
+ RARRAY_AREF(VALUE ary, long i)
156
+ {
157
+ RBIMPL_ASSERT_TYPE(ary, RUBY_T_ARRAY);
158
+
159
+ return RARRAY_CONST_PTR_TRANSIENT(ary)[i];
160
+ }
161
+
162
+ #endif /* INTERNAL_ARRAY_H */
@@ -0,0 +1,212 @@
1
+ #ifndef INTERNAL_CLASS_H /*-*-C-*-vi:se ft=c:*/
2
+ #define INTERNAL_CLASS_H
3
+ /**
4
+ * @author Ruby developers <ruby-core@ruby-lang.org>
5
+ * @copyright This file is a part of the programming language Ruby.
6
+ * Permission is hereby granted, to either redistribute and/or
7
+ * modify this file, provided that the conditions mentioned in the
8
+ * file COPYING are met. Consult the file for details.
9
+ * @brief Internal header for Class.
10
+ */
11
+ #include "id_table.h" /* for struct rb_id_table */
12
+ #include "internal/gc.h" /* for RB_OBJ_WRITE */
13
+ #include "internal/serial.h" /* for rb_serial_t */
14
+ #include "ruby/internal/stdbool.h" /* for bool */
15
+ #include "ruby/intern.h" /* for rb_alloc_func_t */
16
+ #include "ruby/ruby.h" /* for struct RBasic */
17
+
18
+ #ifdef RCLASS_SUPER
19
+ # undef RCLASS_SUPER
20
+ #endif
21
+
22
+ struct rb_subclass_entry {
23
+ VALUE klass;
24
+ struct rb_subclass_entry *next;
25
+ struct rb_subclass_entry *prev;
26
+ };
27
+
28
+ struct rb_iv_index_tbl_entry {
29
+ uint32_t index;
30
+ rb_serial_t class_serial;
31
+ VALUE class_value;
32
+ };
33
+
34
+ struct rb_cvar_class_tbl_entry {
35
+ uint32_t index;
36
+ rb_serial_t global_cvar_state;
37
+ VALUE class_value;
38
+ };
39
+
40
+ struct rb_classext_struct {
41
+ struct st_table *iv_index_tbl; // ID -> struct rb_iv_index_tbl_entry
42
+ struct st_table *iv_tbl;
43
+ #if SIZEOF_SERIAL_T == SIZEOF_VALUE /* otherwise m_tbl is in struct RClass */
44
+ struct rb_id_table *m_tbl;
45
+ #endif
46
+ struct rb_id_table *const_tbl;
47
+ struct rb_id_table *callable_m_tbl;
48
+ struct rb_id_table *cc_tbl; /* ID -> [[ci, cc1], cc2, ...] */
49
+ struct rb_id_table *cvc_tbl;
50
+ size_t superclass_depth;
51
+ VALUE *superclasses;
52
+ struct rb_subclass_entry *subclasses;
53
+ struct rb_subclass_entry *subclass_entry;
54
+ /**
55
+ * In the case that this is an `ICLASS`, `module_subclasses` points to the link
56
+ * in the module's `subclasses` list that indicates that the klass has been
57
+ * included. Hopefully that makes sense.
58
+ */
59
+ struct rb_subclass_entry *module_subclass_entry;
60
+ #if SIZEOF_SERIAL_T != SIZEOF_VALUE && !USE_RVARGC /* otherwise class_serial is in struct RClass */
61
+ rb_serial_t class_serial;
62
+ #endif
63
+ const VALUE origin_;
64
+ const VALUE refined_class;
65
+ rb_alloc_func_t allocator;
66
+ const VALUE includer;
67
+ };
68
+
69
+ struct RClass {
70
+ struct RBasic basic;
71
+ VALUE super;
72
+ #if !USE_RVARGC
73
+ struct rb_classext_struct *ptr;
74
+ #endif
75
+ #if SIZEOF_SERIAL_T == SIZEOF_VALUE
76
+ /* Class serial is as wide as VALUE. Place it here. */
77
+ rb_serial_t class_serial;
78
+ #else
79
+ /* Class serial does not fit into struct RClass. Place m_tbl instead. */
80
+ struct rb_id_table *m_tbl;
81
+ # if USE_RVARGC
82
+ rb_serial_t *class_serial_ptr;
83
+ # endif
84
+ #endif
85
+ };
86
+
87
+ typedef struct rb_subclass_entry rb_subclass_entry_t;
88
+ typedef struct rb_classext_struct rb_classext_t;
89
+
90
+ #if USE_RVARGC
91
+ # define RCLASS_EXT(c) ((rb_classext_t *)((char *)(c) + sizeof(struct RClass)))
92
+ #else
93
+ # define RCLASS_EXT(c) (RCLASS(c)->ptr)
94
+ #endif
95
+ #define RCLASS_IV_TBL(c) (RCLASS_EXT(c)->iv_tbl)
96
+ #define RCLASS_CONST_TBL(c) (RCLASS_EXT(c)->const_tbl)
97
+ #if SIZEOF_SERIAL_T == SIZEOF_VALUE
98
+ # define RCLASS_M_TBL(c) (RCLASS_EXT(c)->m_tbl)
99
+ #else
100
+ # define RCLASS_M_TBL(c) (RCLASS(c)->m_tbl)
101
+ #endif
102
+ #define RCLASS_CALLABLE_M_TBL(c) (RCLASS_EXT(c)->callable_m_tbl)
103
+ #define RCLASS_CC_TBL(c) (RCLASS_EXT(c)->cc_tbl)
104
+ #define RCLASS_CVC_TBL(c) (RCLASS_EXT(c)->cvc_tbl)
105
+ #define RCLASS_IV_INDEX_TBL(c) (RCLASS_EXT(c)->iv_index_tbl)
106
+ #define RCLASS_ORIGIN(c) (RCLASS_EXT(c)->origin_)
107
+ #define RCLASS_REFINED_CLASS(c) (RCLASS_EXT(c)->refined_class)
108
+ #if SIZEOF_SERIAL_T == SIZEOF_VALUE
109
+ # define RCLASS_SERIAL(c) (RCLASS(c)->class_serial)
110
+ #else
111
+ # if USE_RVARGC
112
+ # define RCLASS_SERIAL(c) (*RCLASS(c)->class_serial_ptr)
113
+ # else
114
+ # define RCLASS_SERIAL(c) (RCLASS_EXT(c)->class_serial)
115
+ # endif
116
+ #endif
117
+ #define RCLASS_INCLUDER(c) (RCLASS_EXT(c)->includer)
118
+ #define RCLASS_SUBCLASS_ENTRY(c) (RCLASS_EXT(c)->subclass_entry)
119
+ #define RCLASS_MODULE_SUBCLASS_ENTRY(c) (RCLASS_EXT(c)->module_subclass_entry)
120
+ #define RCLASS_ALLOCATOR(c) (RCLASS_EXT(c)->allocator)
121
+ #define RCLASS_SUBCLASSES(c) (RCLASS_EXT(c)->subclasses)
122
+ #define RCLASS_SUPERCLASS_DEPTH(c) (RCLASS_EXT(c)->superclass_depth)
123
+ #define RCLASS_SUPERCLASSES(c) (RCLASS_EXT(c)->superclasses)
124
+
125
+ #define RICLASS_IS_ORIGIN FL_USER0
126
+ #define RCLASS_CLONED FL_USER1
127
+ #define RCLASS_SUPERCLASSES_INCLUDE_SELF FL_USER2
128
+ #define RICLASS_ORIGIN_SHARED_MTBL FL_USER3
129
+
130
+ /* class.c */
131
+ void rb_class_subclass_add(VALUE super, VALUE klass);
132
+ void rb_class_remove_from_super_subclasses(VALUE);
133
+ void rb_class_update_superclasses(VALUE);
134
+ size_t rb_class_superclasses_memsize(VALUE);
135
+ void rb_class_remove_subclass_head(VALUE);
136
+ int rb_singleton_class_internal_p(VALUE sklass);
137
+ VALUE rb_class_boot(VALUE);
138
+ VALUE rb_class_s_alloc(VALUE klass);
139
+ VALUE rb_module_s_alloc(VALUE klass);
140
+ void rb_module_set_initialized(VALUE module);
141
+ void rb_module_check_initializable(VALUE module);
142
+ VALUE rb_make_metaclass(VALUE, VALUE);
143
+ VALUE rb_include_class_new(VALUE, VALUE);
144
+ void rb_class_foreach_subclass(VALUE klass, void (*f)(VALUE, VALUE), VALUE);
145
+ void rb_class_detach_subclasses(VALUE);
146
+ void rb_class_detach_module_subclasses(VALUE);
147
+ void rb_class_remove_from_module_subclasses(VALUE);
148
+ VALUE rb_obj_methods(int argc, const VALUE *argv, VALUE obj);
149
+ VALUE rb_obj_protected_methods(int argc, const VALUE *argv, VALUE obj);
150
+ VALUE rb_obj_private_methods(int argc, const VALUE *argv, VALUE obj);
151
+ VALUE rb_obj_public_methods(int argc, const VALUE *argv, VALUE obj);
152
+ VALUE rb_class_undefined_instance_methods(VALUE mod);
153
+ VALUE rb_special_singleton_class(VALUE);
154
+ VALUE rb_singleton_class_clone_and_attach(VALUE obj, VALUE attach);
155
+ VALUE rb_singleton_class_get(VALUE obj);
156
+ void rb_undef_methods_from(VALUE klass, VALUE super);
157
+
158
+ static inline void RCLASS_SET_ORIGIN(VALUE klass, VALUE origin);
159
+ static inline void RICLASS_SET_ORIGIN_SHARED_MTBL(VALUE iclass);
160
+ static inline VALUE RCLASS_SUPER(VALUE klass);
161
+ static inline VALUE RCLASS_SET_SUPER(VALUE klass, VALUE super);
162
+ static inline void RCLASS_SET_INCLUDER(VALUE iclass, VALUE klass);
163
+
164
+ MJIT_SYMBOL_EXPORT_BEGIN
165
+ VALUE rb_class_inherited(VALUE, VALUE);
166
+ VALUE rb_keyword_error_new(const char *, VALUE);
167
+ MJIT_SYMBOL_EXPORT_END
168
+
169
+ static inline void
170
+ RCLASS_SET_ORIGIN(VALUE klass, VALUE origin)
171
+ {
172
+ RB_OBJ_WRITE(klass, &RCLASS_ORIGIN(klass), origin);
173
+ if (klass != origin) FL_SET(origin, RICLASS_IS_ORIGIN);
174
+ }
175
+
176
+ static inline void
177
+ RICLASS_SET_ORIGIN_SHARED_MTBL(VALUE iclass)
178
+ {
179
+ FL_SET(iclass, RICLASS_ORIGIN_SHARED_MTBL);
180
+ }
181
+
182
+ static inline bool
183
+ RICLASS_OWNS_M_TBL_P(VALUE iclass)
184
+ {
185
+ return FL_TEST_RAW(iclass, RICLASS_IS_ORIGIN | RICLASS_ORIGIN_SHARED_MTBL) == RICLASS_IS_ORIGIN;
186
+ }
187
+
188
+ static inline void
189
+ RCLASS_SET_INCLUDER(VALUE iclass, VALUE klass)
190
+ {
191
+ RB_OBJ_WRITE(iclass, &RCLASS_INCLUDER(iclass), klass);
192
+ }
193
+
194
+ static inline VALUE
195
+ RCLASS_SUPER(VALUE klass)
196
+ {
197
+ return RCLASS(klass)->super;
198
+ }
199
+
200
+ static inline VALUE
201
+ RCLASS_SET_SUPER(VALUE klass, VALUE super)
202
+ {
203
+ if (super) {
204
+ rb_class_remove_from_super_subclasses(klass);
205
+ rb_class_subclass_add(super, klass);
206
+ }
207
+ RB_OBJ_WRITE(klass, &RCLASS(klass)->super, super);
208
+ rb_class_update_superclasses(klass);
209
+ return super;
210
+ }
211
+
212
+ #endif /* INTERNAL_CLASS_H */
@@ -0,0 +1,107 @@
1
+ #ifndef INTERNAL_COMPILERS_H /*-*-C-*-vi:se ft=c:*/
2
+ #define INTERNAL_COMPILERS_H
3
+ /**
4
+ * @author Ruby developers <ruby-core@ruby-lang.org>
5
+ * @copyright This file is a part of the programming language Ruby.
6
+ * Permission is hereby granted, to either redistribute and/or
7
+ * modify this file, provided that the conditions mentioned in the
8
+ * file COPYING are met. Consult the file for details.
9
+ * @brief Internal header absorbing C compiler differences.
10
+ */
11
+ #include "ruby/internal/compiler_since.h"
12
+ #include "ruby/internal/has/attribute.h"
13
+ #include "ruby/internal/has/builtin.h"
14
+ #include "ruby/internal/has/c_attribute.h"
15
+ #include "ruby/internal/has/declspec_attribute.h"
16
+ #include "ruby/internal/has/extension.h"
17
+ #include "ruby/internal/has/feature.h"
18
+ #include "ruby/internal/has/warning.h"
19
+ #include "ruby/backward/2/gcc_version_since.h"
20
+
21
+ #define MSC_VERSION_SINCE(_) RBIMPL_COMPILER_SINCE(MSVC, (_) / 100, (_) % 100, 0)
22
+ #define MSC_VERSION_BEFORE(_) RBIMPL_COMPILER_BEFORE(MSVC, (_) / 100, (_) % 100, 0)
23
+
24
+ #ifndef __has_attribute
25
+ # define __has_attribute(...) RBIMPL_HAS_ATTRIBUTE(__VA_ARGS__)
26
+ #endif
27
+
28
+ #ifndef __has_c_attribute
29
+ # /* As of writing everything that lacks __has_c_attribute also completely
30
+ # * lacks C2x attributes as well. Might change in future? */
31
+ # define __has_c_attribute(...) 0
32
+ #endif
33
+
34
+ #ifndef __has_declspec_attribute
35
+ # define __has_declspec_attribute(...) RBIMPL_HAS_DECLSPEC_ATTRIBUTE(__VA_ARGS__)
36
+ #endif
37
+
38
+ #ifndef __has_builtin
39
+ # define __has_builtin(...) RBIMPL_HAS_BUILTIN(__VA_ARGS__)
40
+ #endif
41
+
42
+ #ifndef __has_feature
43
+ # define __has_feature(...) RBIMPL_HAS_FEATURE(__VA_ARGS__)
44
+ #endif
45
+
46
+ #ifndef __has_extension
47
+ # define __has_extension(...) RBIMPL_HAS_EXTENSION(__VA_ARGS__)
48
+ #endif
49
+
50
+ #ifndef __has_warning
51
+ # define __has_warning(...) RBIMPL_HAS_WARNING(__VA_ARGS__)
52
+ #endif
53
+
54
+ #ifndef __GNUC__
55
+ # define __extension__ /* void */
56
+ #endif
57
+
58
+ #ifndef MAYBE_UNUSED
59
+ # define MAYBE_UNUSED(x) x
60
+ #endif
61
+
62
+ #ifndef WARN_UNUSED_RESULT
63
+ # define WARN_UNUSED_RESULT(x) x
64
+ #endif
65
+
66
+ #define RB_OBJ_BUILTIN_TYPE(obj) rb_obj_builtin_type(obj)
67
+ #define OBJ_BUILTIN_TYPE(obj) RB_OBJ_BUILTIN_TYPE(obj)
68
+ #ifdef __GNUC__
69
+ #define rb_obj_builtin_type(obj) \
70
+ __extension__({ \
71
+ VALUE arg_obj = (obj); \
72
+ RB_SPECIAL_CONST_P(arg_obj) ? -1 : \
73
+ (int)RB_BUILTIN_TYPE(arg_obj); \
74
+ })
75
+ #else
76
+ # include "ruby/ruby.h"
77
+ static inline int
78
+ rb_obj_builtin_type(VALUE obj)
79
+ {
80
+ return RB_SPECIAL_CONST_P(obj) ? -1 :
81
+ (int)RB_BUILTIN_TYPE(obj);
82
+ }
83
+ #endif
84
+
85
+ /* A macro for defining a flexible array, like: VALUE ary[FLEX_ARY_LEN]; */
86
+ #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
87
+ # define FLEX_ARY_LEN /* VALUE ary[]; */
88
+ #elif defined(__GNUC__) && !defined(__STRICT_ANSI__)
89
+ # define FLEX_ARY_LEN 0 /* VALUE ary[0]; */
90
+ #else
91
+ # define FLEX_ARY_LEN 1 /* VALUE ary[1]; */
92
+ #endif
93
+
94
+ /*
95
+ * For declaring bitfields out of non-unsigned int types:
96
+ * struct date {
97
+ * BITFIELD(enum months, month, 4);
98
+ * ...
99
+ * };
100
+ */
101
+ #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
102
+ # define BITFIELD(type, name, size) type name : size
103
+ #else
104
+ # define BITFIELD(type, name, size) unsigned int name : size
105
+ #endif
106
+
107
+ #endif /* INTERNAL_COMPILERS_H */
@@ -0,0 +1,188 @@
1
+ #ifndef INTERNAL_GC_H /*-*-C-*-vi:se ft=c:*/
2
+ #define INTERNAL_GC_H
3
+ /**
4
+ * @author Ruby developers <ruby-core@ruby-lang.org>
5
+ * @copyright This file is a part of the programming language Ruby.
6
+ * Permission is hereby granted, to either redistribute and/or
7
+ * modify this file, provided that the conditions mentioned in the
8
+ * file COPYING are met. Consult the file for details.
9
+ * @brief Internal header for GC.
10
+ */
11
+ #include "ruby/internal/config.h"
12
+
13
+ #include <stddef.h> /* for size_t */
14
+
15
+ #include "internal/compilers.h" /* for __has_attribute */
16
+ #include "ruby/ruby.h" /* for rb_event_flag_t */
17
+
18
+ struct rb_execution_context_struct; /* in vm_core.h */
19
+ struct rb_objspace; /* in vm_core.h */
20
+
21
+ #ifdef NEWOBJ_OF
22
+ # undef NEWOBJ_OF
23
+ # undef RB_NEWOBJ_OF
24
+ # undef RB_OBJ_WRITE
25
+ #endif
26
+
27
+ #define RVALUE_SIZE (sizeof(struct RBasic) + sizeof(VALUE[RBIMPL_RVALUE_EMBED_LEN_MAX]))
28
+
29
+ #define RB_RVARGC_NEWOBJ_OF(var, T, c, f, s) \
30
+ T *(var) = (T *)(((f) & FL_WB_PROTECTED) ? \
31
+ rb_wb_protected_newobj_of((c), (f) & ~FL_WB_PROTECTED, s) : \
32
+ rb_wb_unprotected_newobj_of((c), (f), s))
33
+
34
+ #define RB_RVARGC_EC_NEWOBJ_OF(ec, var, T, c, f, s) \
35
+ T *(var) = (T *)(((f) & FL_WB_PROTECTED) ? \
36
+ rb_ec_wb_protected_newobj_of((ec), (c), (f) & ~FL_WB_PROTECTED, s) : \
37
+ rb_wb_unprotected_newobj_of((c), (f), s))
38
+
39
+ /* optimized version of NEWOBJ() */
40
+ #define RB_NEWOBJ_OF(var, T, c, f) RB_RVARGC_NEWOBJ_OF(var, T, c, f, RVALUE_SIZE)
41
+
42
+ #define RB_EC_NEWOBJ_OF(ec, var, T, c, f) RB_RVARGC_EC_NEWOBJ_OF(ec, var, T, c, f, RVALUE_SIZE)
43
+
44
+ #define NEWOBJ_OF(var, T, c, f) RB_NEWOBJ_OF((var), T, (c), (f))
45
+ #define RVARGC_NEWOBJ_OF(var, T, c, f, s) RB_RVARGC_NEWOBJ_OF((var), T, (c), (f), (s))
46
+ #define RB_OBJ_GC_FLAGS_MAX 6 /* used in ext/objspace */
47
+
48
+ #ifndef USE_UNALIGNED_MEMBER_ACCESS
49
+ # define UNALIGNED_MEMBER_ACCESS(expr) (expr)
50
+ #elif ! USE_UNALIGNED_MEMBER_ACCESS
51
+ # define UNALIGNED_MEMBER_ACCESS(expr) (expr)
52
+ #elif ! (__has_warning("-Waddress-of-packed-member") || GCC_VERSION_SINCE(9, 0, 0))
53
+ # define UNALIGNED_MEMBER_ACCESS(expr) (expr)
54
+ #else
55
+ # include "internal/warnings.h"
56
+ # define UNALIGNED_MEMBER_ACCESS(expr) __extension__({ \
57
+ COMPILER_WARNING_PUSH; \
58
+ COMPILER_WARNING_IGNORED(-Waddress-of-packed-member); \
59
+ __typeof__(expr) unaligned_member_access_result = (expr); \
60
+ COMPILER_WARNING_POP; \
61
+ unaligned_member_access_result; \
62
+ })
63
+ #endif
64
+
65
+ #define UNALIGNED_MEMBER_PTR(ptr, mem) UNALIGNED_MEMBER_ACCESS(&(ptr)->mem)
66
+ #define RB_OBJ_WRITE(a, slot, b) \
67
+ rb_obj_write((VALUE)(a), UNALIGNED_MEMBER_ACCESS((VALUE *)(slot)), \
68
+ (VALUE)(b), __FILE__, __LINE__)
69
+
70
+ #if USE_RVARGC
71
+ # define SIZE_POOL_COUNT 5
72
+ #else
73
+ # define SIZE_POOL_COUNT 1
74
+ #endif
75
+
76
+ typedef struct ractor_newobj_size_pool_cache {
77
+ struct RVALUE *freelist;
78
+ struct heap_page *using_page;
79
+ } rb_ractor_newobj_size_pool_cache_t;
80
+
81
+ typedef struct ractor_newobj_cache {
82
+ size_t incremental_mark_step_allocated_slots;
83
+ rb_ractor_newobj_size_pool_cache_t size_pool_caches[SIZE_POOL_COUNT];
84
+ } rb_ractor_newobj_cache_t;
85
+
86
+ /* gc.c */
87
+ extern VALUE *ruby_initial_gc_stress_ptr;
88
+ extern int ruby_disable_gc;
89
+ RUBY_ATTR_MALLOC void *ruby_mimmalloc(size_t size);
90
+ void ruby_mimfree(void *ptr);
91
+ void rb_objspace_set_event_hook(const rb_event_flag_t event);
92
+ VALUE rb_objspace_gc_enable(struct rb_objspace *);
93
+ VALUE rb_objspace_gc_disable(struct rb_objspace *);
94
+ void ruby_gc_set_params(void);
95
+ void rb_copy_wb_protected_attribute(VALUE dest, VALUE obj);
96
+ #if __has_attribute(alloc_align)
97
+ __attribute__((__alloc_align__(1)))
98
+ #endif
99
+ RUBY_ATTR_MALLOC void *rb_aligned_malloc(size_t, size_t) RUBY_ATTR_ALLOC_SIZE((2));
100
+ size_t rb_size_mul_or_raise(size_t, size_t, VALUE); /* used in compile.c */
101
+ size_t rb_size_mul_add_or_raise(size_t, size_t, size_t, VALUE); /* used in iseq.h */
102
+ RUBY_ATTR_MALLOC void *rb_xmalloc_mul_add(size_t, size_t, size_t);
103
+ RUBY_ATTR_MALLOC void *rb_xcalloc_mul_add(size_t, size_t, size_t);
104
+ void *rb_xrealloc_mul_add(const void *, size_t, size_t, size_t);
105
+ RUBY_ATTR_MALLOC void *rb_xmalloc_mul_add_mul(size_t, size_t, size_t, size_t);
106
+ RUBY_ATTR_MALLOC void *rb_xcalloc_mul_add_mul(size_t, size_t, size_t, size_t);
107
+ static inline void *ruby_sized_xrealloc_inlined(void *ptr, size_t new_size, size_t old_size) RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((2));
108
+ static inline void *ruby_sized_xrealloc2_inlined(void *ptr, size_t new_count, size_t elemsiz, size_t old_count) RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((2, 3));
109
+ static inline void ruby_sized_xfree_inlined(void *ptr, size_t size);
110
+ VALUE rb_class_allocate_instance(VALUE klass);
111
+ void rb_gc_ractor_newobj_cache_clear(rb_ractor_newobj_cache_t *newobj_cache);
112
+ size_t rb_gc_obj_slot_size(VALUE obj);
113
+ bool rb_gc_size_allocatable_p(size_t size);
114
+ int rb_objspace_garbage_object_p(VALUE obj);
115
+
116
+ RUBY_SYMBOL_EXPORT_BEGIN
117
+ /* gc.c (export) */
118
+ const char *rb_objspace_data_type_name(VALUE obj);
119
+ VALUE rb_wb_protected_newobj_of(VALUE, VALUE, size_t);
120
+ VALUE rb_wb_unprotected_newobj_of(VALUE, VALUE, size_t);
121
+ VALUE rb_ec_wb_protected_newobj_of(struct rb_execution_context_struct *ec, VALUE klass, VALUE flags, size_t);
122
+ size_t rb_obj_memsize_of(VALUE);
123
+ void rb_gc_verify_internal_consistency(void);
124
+ size_t rb_obj_gc_flags(VALUE, ID[], size_t);
125
+ void rb_gc_mark_values(long n, const VALUE *values);
126
+ void rb_gc_mark_vm_stack_values(long n, const VALUE *values);
127
+ void *ruby_sized_xrealloc(void *ptr, size_t new_size, size_t old_size) RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((2));
128
+ void *ruby_sized_xrealloc2(void *ptr, size_t new_count, size_t element_size, size_t old_count) RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((2, 3));
129
+ void ruby_sized_xfree(void *x, size_t size);
130
+ RUBY_SYMBOL_EXPORT_END
131
+
132
+ MJIT_SYMBOL_EXPORT_BEGIN
133
+ int rb_ec_stack_check(struct rb_execution_context_struct *ec);
134
+ void rb_gc_writebarrier_remember(VALUE obj);
135
+ const char *rb_obj_info(VALUE obj);
136
+ MJIT_SYMBOL_EXPORT_END
137
+
138
+ #if defined(HAVE_MALLOC_USABLE_SIZE) || defined(HAVE_MALLOC_SIZE) || defined(_WIN32)
139
+
140
+ static inline void *
141
+ ruby_sized_xrealloc_inlined(void *ptr, size_t new_size, size_t old_size)
142
+ {
143
+ return ruby_xrealloc(ptr, new_size);
144
+ }
145
+
146
+ static inline void *
147
+ ruby_sized_xrealloc2_inlined(void *ptr, size_t new_count, size_t elemsiz, size_t old_count)
148
+ {
149
+ return ruby_xrealloc2(ptr, new_count, elemsiz);
150
+ }
151
+
152
+ static inline void
153
+ ruby_sized_xfree_inlined(void *ptr, size_t size)
154
+ {
155
+ ruby_xfree(ptr);
156
+ }
157
+
158
+ # define SIZED_REALLOC_N(x, y, z, w) REALLOC_N(x, y, z)
159
+
160
+ #else
161
+
162
+ static inline void *
163
+ ruby_sized_xrealloc_inlined(void *ptr, size_t new_size, size_t old_size)
164
+ {
165
+ return ruby_sized_xrealloc(ptr, new_size, old_size);
166
+ }
167
+
168
+ static inline void *
169
+ ruby_sized_xrealloc2_inlined(void *ptr, size_t new_count, size_t elemsiz, size_t old_count)
170
+ {
171
+ return ruby_sized_xrealloc2(ptr, new_count, elemsiz, old_count);
172
+ }
173
+
174
+ static inline void
175
+ ruby_sized_xfree_inlined(void *ptr, size_t size)
176
+ {
177
+ ruby_sized_xfree(ptr, size);
178
+ }
179
+
180
+ # define SIZED_REALLOC_N(v, T, m, n) \
181
+ ((v) = (T *)ruby_sized_xrealloc2((void *)(v), (m), sizeof(T), (n)))
182
+
183
+ #endif /* HAVE_MALLOC_USABLE_SIZE */
184
+
185
+ #define ruby_sized_xrealloc ruby_sized_xrealloc_inlined
186
+ #define ruby_sized_xrealloc2 ruby_sized_xrealloc2_inlined
187
+ #define ruby_sized_xfree ruby_sized_xfree_inlined
188
+ #endif /* INTERNAL_GC_H */