datadog-ruby_core_source 3.5.5 → 3.5.6

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.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +0 -2
  3. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/ccan/build_assert/build_assert.h +40 -0
  4. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/ccan/check_type/check_type.h +63 -0
  5. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/ccan/container_of/container_of.h +142 -0
  6. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/ccan/list/list.h +791 -0
  7. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/ccan/str/str.h +17 -0
  8. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/constant.h +53 -0
  9. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/debug_counter.h +428 -0
  10. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/hrtime.h +237 -0
  11. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/id.h +365 -0
  12. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/id_table.h +74 -0
  13. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/internal/array.h +158 -0
  14. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/internal/basic_operators.h +67 -0
  15. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/internal/bits.h +647 -0
  16. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/internal/box.h +103 -0
  17. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/internal/class.h +797 -0
  18. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/internal/compilers.h +104 -0
  19. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/internal/coverage.h +51 -0
  20. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/internal/gc.h +411 -0
  21. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/internal/imemo.h +302 -0
  22. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/internal/sanitizers.h +346 -0
  23. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/internal/serial.h +23 -0
  24. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/internal/set_table.h +77 -0
  25. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/internal/static_assert.h +16 -0
  26. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/internal/time.h +34 -0
  27. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/internal/variable.h +81 -0
  28. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/internal/vm.h +144 -0
  29. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/internal/warnings.h +16 -0
  30. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/internal.h +106 -0
  31. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/iseq.h +439 -0
  32. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/method.h +279 -0
  33. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/node.h +122 -0
  34. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/parser_st.h +161 -0
  35. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/parser_value.h +116 -0
  36. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/arena.h +37 -0
  37. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/ast.h +10371 -0
  38. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/buffer.h +52 -0
  39. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/comments.h +43 -0
  40. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/compiler/align.h +36 -0
  41. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/compiler/exported.h +24 -0
  42. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/compiler/filesystem.h +32 -0
  43. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/compiler/nodiscard.h +22 -0
  44. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/compiler/nonnull.h +18 -0
  45. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/constant_pool.h +81 -0
  46. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/diagnostic.h +93 -0
  47. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/errors_format.h +53 -0
  48. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/excludes.h +29 -0
  49. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/integer.h +41 -0
  50. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/json.h +32 -0
  51. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/line_offset_list.h +61 -0
  52. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/magic_comments.h +35 -0
  53. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/node.h +94 -0
  54. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/options.h +335 -0
  55. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/parser.h +348 -0
  56. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/prettyprint.h +31 -0
  57. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/prism.h +131 -0
  58. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/serialize.h +115 -0
  59. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/source.h +155 -0
  60. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/stream.h +28 -0
  61. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/string_query.h +63 -0
  62. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/stringy.h +72 -0
  63. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism/version.h +38 -0
  64. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/prism_compile.h +204 -0
  65. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/ractor_core.h +421 -0
  66. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/ruby_assert.h +14 -0
  67. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/ruby_atomic.h +115 -0
  68. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/rubyparser.h +1389 -0
  69. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/shape.h +733 -0
  70. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/thread_none.h +25 -0
  71. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/thread_pthread.h +63 -0
  72. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/thread_sched.h +271 -0
  73. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/vm_core.h +2509 -0
  74. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/vm_debug.h +124 -0
  75. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/vm_opts.h +65 -0
  76. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/vm_sync.h +160 -0
  77. data/lib/datadog/ruby_core_source/ruby-4.1.0-preview1/zjit.h +221 -0
  78. data/lib/datadog/ruby_core_source/version.rb +1 -1
  79. metadata +77 -2
@@ -0,0 +1,797 @@
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.h"
12
+ #include "id_table.h" /* for struct rb_id_table */
13
+ #include "internal/box.h"
14
+ #include "internal/serial.h" /* for rb_serial_t */
15
+ #include "ractor_core.h" /* for rb_ractor_main_p */
16
+ #include "internal/static_assert.h"
17
+ #include "internal/variable.h" /* for rb_class_ivar_set */
18
+ #include "ruby/internal/stdbool.h" /* for bool */
19
+ #include "ruby/intern.h" /* for rb_alloc_func_t */
20
+ #include "ruby/ruby.h" /* for struct RBasic */
21
+ #include "shape.h"
22
+ #include "ruby_assert.h"
23
+ #include "vm_core.h"
24
+ #include "vm_sync.h"
25
+ #include "method.h" /* for rb_cref_t */
26
+
27
+ #ifdef RCLASS_SUPER
28
+ # undef RCLASS_SUPER
29
+ #endif
30
+
31
+ struct rb_cvar_class_tbl_entry {
32
+ VALUE imemo_flags;
33
+ uint32_t index;
34
+ rb_serial_t global_cvar_state;
35
+ const rb_cref_t *cref;
36
+ VALUE class_value;
37
+ };
38
+
39
+ struct rb_classext_struct {
40
+ const rb_box_t *box;
41
+ VALUE super;
42
+ VALUE fields_obj; // Fields are either ivar or other internal properties stored inline
43
+ /**
44
+ * For class/module: name of class/module
45
+ * For refinement iclass: hidden hash with refinement module keys and module refinement
46
+ * iclass values
47
+ * TODO: move into as union below
48
+ */
49
+ VALUE classpath;
50
+ struct rb_id_table *m_tbl;
51
+ struct rb_id_table *const_tbl;
52
+ struct rb_id_table *callable_m_tbl;
53
+ VALUE cc_tbl; /* { ID => { cme, [cc1, cc2, ...] }, ... } */
54
+ VALUE cvc_tbl;
55
+ VALUE *superclasses;
56
+ /**
57
+ * imemo_subclasses VALUE tracking this class's subclasses.
58
+ * Only used in prime classext. Lazily allocated on first subclass addition.
59
+ */
60
+ VALUE subclasses;
61
+
62
+ const VALUE origin_;
63
+ const VALUE refined_class;
64
+ union {
65
+ struct {
66
+ rb_alloc_func_t allocator;
67
+ } class;
68
+ struct {
69
+ VALUE attached_object;
70
+ } singleton_class;
71
+ struct {
72
+ const VALUE includer;
73
+ } iclass;
74
+ } as;
75
+ /* Id of the Ractor that created this class/module; only that Ractor may modify
76
+ * it. 0 is the main Ractor, so a program that never leaves it stores nothing.
77
+ * Ids are never reused, so a terminated owner leaves the class read-only for
78
+ * everybody. Prime classext only; always 0 for T_ICLASS. */
79
+ rb_serial_t owner_ractor_id;
80
+ uint16_t superclass_depth;
81
+ attr_index_t max_iv_count;
82
+ uint8_t variation_count;
83
+ bool permanent_classpath : 1;
84
+ bool shared_const_tbl : 1;
85
+ bool iclass_is_origin : 1;
86
+ bool iclass_origin_shared_mtbl : 1;
87
+ bool superclasses_with_self : 1;
88
+ bool expect_no_ivar : 1;
89
+ };
90
+ typedef struct rb_classext_struct rb_classext_t;
91
+
92
+ STATIC_ASSERT(shape_max_variations, SHAPE_MAX_VARIATIONS < (1 << (sizeof(((rb_classext_t *)0)->variation_count) * CHAR_BIT)));
93
+
94
+ struct RClass {
95
+ struct RBasic basic;
96
+ VALUE object_id;
97
+ /*
98
+ * If box_classext_tbl is NULL, then the prime classext is readable (because no other classext exists).
99
+ * For the check whether writable or not, check flag RCLASS_PRIME_CLASSEXT_WRITABLE
100
+ */
101
+ };
102
+
103
+ struct RClass_and_rb_classext_t {
104
+ struct RClass rclass;
105
+ rb_classext_t classext;
106
+ };
107
+
108
+ #if SIZEOF_VALUE >= SIZEOF_LONG_LONG
109
+ // Assert that classes can be embedded in heaps[3] (256B slot size on 64-bit).
110
+ // On 32bit platforms there is no variable width allocation so it doesn't matter.
111
+ STATIC_ASSERT(sizeof_rb_classext_t, sizeof(struct RClass_and_rb_classext_t) <= 256);
112
+ #endif
113
+
114
+ struct RClass_boxable {
115
+ struct RClass_and_rb_classext_t base;
116
+ st_table *box_classext_tbl; // box_object -> (rb_classext_t *)
117
+ };
118
+
119
+ static const uint16_t RCLASS_MAX_SUPERCLASS_DEPTH = ((uint16_t)-1);
120
+
121
+ static inline bool RCLASS_SINGLETON_P(VALUE klass);
122
+
123
+ static inline bool RCLASS_PRIME_CLASSEXT_READABLE_P(VALUE obj);
124
+ static inline bool RCLASS_PRIME_CLASSEXT_WRITABLE_P(VALUE obj);
125
+ static inline void RCLASS_SET_PRIME_CLASSEXT_WRITABLE(VALUE obj, bool writable);
126
+
127
+ #define RCLASS_EXT_PRIME(c) (&((struct RClass_and_rb_classext_t*)(c))->classext)
128
+ #define RCLASS_EXT_PRIME_P(ext, c) (&((struct RClass_and_rb_classext_t*)(c))->classext == ext)
129
+
130
+ // Class ownership. See rb_classext_struct::owner_ractor_id.
131
+ #define RCLASSEXT_OWNER_RACTOR_ID(ext) (ext->owner_ractor_id)
132
+
133
+ static inline rb_serial_t
134
+ RCLASS_OWNER_RACTOR_ID(VALUE klass)
135
+ {
136
+ return RCLASS_EXT_PRIME(klass)->owner_ractor_id;
137
+ }
138
+
139
+ static inline void
140
+ RCLASS_SET_OWNER_RACTOR_ID(VALUE klass, rb_serial_t ractor_id)
141
+ {
142
+ // not a VALUE: no write barrier, nothing for the GC to mark or move
143
+ RCLASS_EXT_PRIME(klass)->owner_ractor_id = ractor_id;
144
+ }
145
+
146
+ bool rb_class_owned_by_ractor_p(rb_serial_t owner_id); // rb_class_owned_p's slow half
147
+ void rb_class_owner_check(VALUE klass); // raise Ractor::IsolationError unless rb_class_owned_p(klass)
148
+ void rb_class_take_ownership(VALUE klass); // for a moved object's singleton class only
149
+ void rb_class_check_singleton_movable(VALUE klass); // raise if it holds unshareable values
150
+
151
+ // true if the current Ractor created klass. Inline because the class ivar and
152
+ // constant read paths take it on every access.
153
+ static inline bool
154
+ rb_class_owned_p(VALUE klass)
155
+ {
156
+ rb_serial_t owner_id = RCLASS_OWNER_RACTOR_ID(klass);
157
+ if (LIKELY(!owner_id)) return rb_ractor_main_p(); // the only case single-Ractor programs take
158
+ return rb_class_owned_by_ractor_p(owner_id);
159
+ }
160
+
161
+ static inline rb_classext_t * RCLASS_EXT_READABLE_IN_BOX(VALUE obj, const rb_box_t *box);
162
+ static inline rb_classext_t * RCLASS_EXT_READABLE(VALUE obj);
163
+ static inline rb_classext_t * RCLASS_EXT_WRITABLE_IN_BOX(VALUE obj, const rb_box_t *box);
164
+ static inline rb_classext_t * RCLASS_EXT_WRITABLE(VALUE obj);
165
+
166
+ // Raw accessor
167
+ #define RCLASSEXT_BOX(ext) (ext->box)
168
+ #define RCLASSEXT_SUPER(ext) (ext->super)
169
+ #define RCLASSEXT_FIELDS(ext) (ext->fields_obj ? ROBJECT_FIELDS(ext->fields_obj) : NULL)
170
+ #define RCLASSEXT_FIELDS_OBJ(ext) (ext->fields_obj)
171
+ #define RCLASSEXT_M_TBL(ext) (ext->m_tbl)
172
+ #define RCLASSEXT_CONST_TBL(ext) (ext->const_tbl)
173
+ #define RCLASSEXT_CALLABLE_M_TBL(ext) (ext->callable_m_tbl)
174
+ #define RCLASSEXT_CC_TBL(ext) (ext->cc_tbl)
175
+ #define RCLASSEXT_CVC_TBL(ext) (ext->cvc_tbl)
176
+ #define RCLASSEXT_SUPERCLASS_DEPTH(ext) (ext->superclass_depth)
177
+ #define RCLASSEXT_SUPERCLASSES(ext) (ext->superclasses)
178
+ #define RCLASSEXT_SUBCLASSES(ext) (ext->subclasses)
179
+ #define RCLASSEXT_ORIGIN(ext) (ext->origin_)
180
+ #define RCLASSEXT_REFINED_CLASS(ext) (ext->refined_class)
181
+ // class.allocator/singleton_class.attached_object are not accessed directly via RCLASSEXT_*
182
+ #define RCLASSEXT_INCLUDER(ext) (ext->as.iclass.includer)
183
+ #define RCLASSEXT_PERMANENT_CLASSPATH(ext) (ext->permanent_classpath)
184
+ #define RCLASSEXT_SHARED_CONST_TBL(ext) (ext->shared_const_tbl)
185
+ #define RCLASSEXT_ICLASS_IS_ORIGIN(ext) (ext->iclass_is_origin)
186
+ #define RCLASSEXT_ICLASS_ORIGIN_SHARED_MTBL(ext) (ext->iclass_origin_shared_mtbl)
187
+ #define RCLASSEXT_SUPERCLASSES_WITH_SELF(ext) (ext->superclasses_with_self)
188
+ #define RCLASSEXT_CLASSPATH(ext) (ext->classpath)
189
+ #define RCLASSEXT_MODULE_REFINEMENT_ICLASSES(ext) (ext->classpath)
190
+
191
+ static inline void RCLASSEXT_SET_ORIGIN(rb_classext_t *ext, VALUE klass, VALUE origin);
192
+ static inline void RCLASSEXT_SET_INCLUDER(rb_classext_t *ext, VALUE klass, VALUE includer);
193
+
194
+ /* Prime classext entry accessor for very specific reason */
195
+ #define RCLASS_PRIME_BOX(c) (RCLASS_EXT_PRIME(c)->box)
196
+ // To invalidate CC by inserting&invalidating method entry into tables containing the target cme
197
+ // See clear_method_cache_by_id_in_class()
198
+ #define RCLASS_PRIME_FIELDS_OBJ(c) (RCLASS_EXT_PRIME(c)->fields_obj)
199
+ #define RCLASS_PRIME_M_TBL(c) (RCLASS_EXT_PRIME(c)->m_tbl)
200
+ #define RCLASS_PRIME_CONST_TBL(c) (RCLASS_EXT_PRIME(c)->const_tbl)
201
+ #define RCLASS_PRIME_CALLABLE_M_TBL(c) (RCLASS_EXT_PRIME(c)->callable_m_tbl)
202
+ #define RCLASS_PRIME_CC_TBL(c) (RCLASS_EXT_PRIME(c)->cc_tbl)
203
+ #define RCLASS_M_TBL_NOT_PRIME_P(c, tbl) (RCLASS_EXT_PRIME(c)->m_tbl != tbl)
204
+ #define RCLASS_CALLABLE_M_TBL_NOT_PRIME_P(c, tbl) (RCLASS_EXT_PRIME(c)->callable_m_tbl != tbl)
205
+ #define RCLASS_CC_TBL_NOT_PRIME_P(c, tbl) (RCLASS_EXT_PRIME(c)->cc_tbl != tbl)
206
+
207
+ // Read accessor, regarding box
208
+ #define RCLASS_SUPER(c) (RCLASS_EXT_READABLE(c)->super)
209
+ #define RCLASS_M_TBL(c) (RCLASS_EXT_READABLE(c)->m_tbl)
210
+ #define RCLASS_CONST_TBL(c) (RCLASS_EXT_READABLE(c)->const_tbl)
211
+ /*
212
+ * Both cc_tbl/callable_m_tbl are cache-like and always be changed when referreed,
213
+ * so always those should be writable.
214
+ */
215
+ #define RCLASS_CVC_TBL(c) (RCLASS_EXT_READABLE(c)->cvc_tbl)
216
+ #define RCLASS_SUBCLASSES(c) (RCLASS_EXT_PRIME(c)->subclasses)
217
+ #define RCLASS_ORIGIN(c) (RCLASS_EXT_READABLE(c)->origin_)
218
+ #define RICLASS_IS_ORIGIN_P(c) (RCLASS_EXT_READABLE(c)->iclass_is_origin)
219
+ #define RCLASS_PERMANENT_CLASSPATH_P(c) (RCLASS_EXT_READABLE(c)->permanent_classpath)
220
+ #define RCLASS_CLASSPATH(c) (RCLASS_EXT_READABLE(c)->classpath)
221
+
222
+ // Superclasses can't be changed after initialization
223
+ #define RCLASS_SUPERCLASS_DEPTH(c) (RCLASS_EXT_PRIME(c)->superclass_depth)
224
+ #define RCLASS_SUPERCLASSES(c) (RCLASS_EXT_PRIME(c)->superclasses)
225
+ #define RCLASS_SUPERCLASSES_WITH_SELF_P(c) (RCLASS_EXT_PRIME(c)->superclasses_with_self)
226
+
227
+ // Ruby Box doesn't make changes on these refined_class/attached_object/includer
228
+ #define RCLASS_REFINED_CLASS(c) (RCLASS_EXT_PRIME(c)->refined_class)
229
+ #define RCLASS_ATTACHED_OBJECT(c) (RCLASS_EXT_PRIME(c)->as.singleton_class.attached_object)
230
+ #define RCLASS_INCLUDER(c) (RCLASS_EXT_PRIME(c)->as.iclass.includer)
231
+ #define RCLASS_MODULE_REFINEMENT_ICLASSES(c) (RCLASS_EXT_PRIME(c)->classpath)
232
+
233
+ // max IV count and variation count are just hints, so they don't need to be per-box
234
+ #define RCLASS_MAX_IV_COUNT(ext) (RCLASS_EXT_PRIME(ext)->max_iv_count)
235
+ #define RCLASS_VARIATION_COUNT(ext) (RCLASS_EXT_PRIME(ext)->variation_count)
236
+
237
+ // Writable classext entries (instead of RCLASS_SET_*) because member data will be operated directly
238
+ #define RCLASS_WRITABLE_M_TBL(c) (RCLASS_EXT_WRITABLE(c)->m_tbl)
239
+ #define RCLASS_WRITABLE_CONST_TBL(c) (RCLASS_EXT_WRITABLE(c)->const_tbl)
240
+ #define RCLASS_WRITABLE_CALLABLE_M_TBL(c) (RCLASS_EXT_WRITABLE(c)->callable_m_tbl)
241
+ #define RCLASS_WRITABLE_CC_TBL(c) (RCLASS_EXT_WRITABLE(c)->cc_tbl)
242
+ #define RCLASS_WRITABLE_CVC_TBL(c) (RCLASS_EXT_WRITABLE(c)->cvc_tbl)
243
+ // Subclasses are only in the prime classext (box-invariant)
244
+ #define RCLASS_WRITABLE_SUBCLASSES(c) (RCLASS_EXT_PRIME(c)->subclasses)
245
+
246
+ static inline void RCLASS_SET_SUPER(VALUE klass, VALUE super);
247
+ static inline void RCLASS_WRITE_SUPER(VALUE klass, VALUE super);
248
+ static inline void RCLASS_SET_CONST_TBL(VALUE klass, struct rb_id_table *table, bool shared);
249
+ static inline void RCLASS_WRITE_CONST_TBL(VALUE klass, struct rb_id_table *table, bool shared);
250
+ static inline void RCLASS_WRITE_CALLABLE_M_TBL(VALUE klass, struct rb_id_table *table);
251
+ static inline void RCLASS_WRITE_CC_TBL(VALUE klass, VALUE table);
252
+ static inline void RCLASS_SET_CVC_TBL(VALUE klass, VALUE table);
253
+ static inline void RCLASS_WRITE_CVC_TBL(VALUE klass, VALUE table);
254
+
255
+ static inline void RCLASS_WRITE_SUPERCLASSES(VALUE klass, size_t depth, VALUE *superclasses, bool with_self);
256
+ static inline void RCLASS_SET_SUBCLASSES(VALUE klass, VALUE subclasses);
257
+
258
+ static inline void RCLASS_SET_ORIGIN(VALUE klass, VALUE origin);
259
+ static inline void RCLASS_WRITE_ORIGIN(VALUE klass, VALUE origin);
260
+ static inline void RICLASS_SET_ORIGIN_SHARED_MTBL(VALUE iclass);
261
+ static inline void RICLASS_WRITE_ORIGIN_SHARED_MTBL(VALUE iclass);
262
+ static inline bool RICLASS_OWNS_M_TBL_P(VALUE iclass);
263
+
264
+ static inline void RCLASS_SET_REFINED_CLASS(VALUE klass, VALUE refined);
265
+ static inline rb_alloc_func_t RCLASS_ALLOCATOR(VALUE klass);
266
+ static inline void RCLASS_SET_ALLOCATOR(VALUE klass, rb_alloc_func_t allocator);
267
+ static inline VALUE RCLASS_SET_ATTACHED_OBJECT(VALUE klass, VALUE attached_object);
268
+
269
+ static inline void RCLASS_SET_INCLUDER(VALUE iclass, VALUE klass);
270
+ static inline void RCLASS_SET_MODULE_REFINEMENT_ICLASSES(VALUE iclass, VALUE table);
271
+ static inline void RCLASS_SET_MAX_IV_COUNT(VALUE klass, attr_index_t count);
272
+ static inline void RCLASS_SET_CLASSPATH(VALUE klass, VALUE classpath, bool permanent);
273
+ static inline void RCLASS_WRITE_CLASSPATH(VALUE klass, VALUE classpath, bool permanent);
274
+
275
+ #define RCLASS_IS_ROOT FL_USER0
276
+ // 1 is for RUBY_FL_SINGLETON or RMODULE_IS_REFINEMENT
277
+ #define RCLASS_PRIME_CLASSEXT_WRITABLE FL_USER2
278
+ #define RCLASS_IS_INITIALIZED FL_USER3
279
+ // 3 is RMODULE_IS_REFINEMENT for RMODULE
280
+ #define RCLASS_BOXABLE FL_USER4
281
+ #define RCLASS_ALLOCATOR_DEFINED FL_USER5
282
+ #define RCLASS_HAS_SUBCLASSES FL_USER6
283
+
284
+ static inline st_table *
285
+ RCLASS_CLASSEXT_TBL(VALUE klass)
286
+ {
287
+ if (FL_TEST_RAW(klass, RCLASS_BOXABLE)) {
288
+ struct RClass_boxable *box_klass = (struct RClass_boxable *)klass;
289
+ return box_klass->box_classext_tbl;
290
+ }
291
+ return NULL;
292
+ }
293
+
294
+ static inline void
295
+ RCLASS_SET_CLASSEXT_TBL(VALUE klass, st_table *tbl)
296
+ {
297
+ RUBY_ASSERT(FL_TEST_RAW(klass, RCLASS_BOXABLE));
298
+ struct RClass_boxable *box_klass = (struct RClass_boxable *)klass;
299
+ box_klass->box_classext_tbl = tbl;
300
+ }
301
+
302
+ /* class.c */
303
+ rb_classext_t * rb_class_duplicate_classext(rb_classext_t *orig, VALUE obj, const rb_box_t *box, int *first_set);
304
+ void rb_class_ensure_writable(VALUE obj);
305
+
306
+ void rb_class_set_box_classext(VALUE obj, const rb_box_t *box, rb_classext_t *ext);
307
+
308
+ static inline int
309
+ RCLASS_SET_BOX_CLASSEXT(VALUE obj, const rb_box_t *box, rb_classext_t *ext)
310
+ {
311
+ int first_set = 0;
312
+ st_table *tbl = RCLASS_CLASSEXT_TBL(obj);
313
+ VM_ASSERT(BOX_MUTABLE_P(box)); // Setting non-prime classext never happens on the master box
314
+ VM_ASSERT(box->box_object);
315
+ VM_ASSERT(RCLASSEXT_BOX(ext) == box);
316
+ if (!tbl) {
317
+ tbl = st_init_numtable_with_size(1);
318
+ RCLASS_SET_CLASSEXT_TBL(obj, tbl);
319
+ }
320
+ if (rb_st_table_size(tbl) == 0) {
321
+ first_set = 1;
322
+ }
323
+
324
+ rb_class_set_box_classext(obj, box, ext);
325
+
326
+ return first_set;
327
+ }
328
+
329
+ #define VM_ASSERT_BOXABLE_TYPE(klass) \
330
+ VM_ASSERT(RB_TYPE_P(klass, T_CLASS) || RB_TYPE_P(klass, T_MODULE) || RB_TYPE_P(klass, T_ICLASS), "%s is not boxable type", rb_type_str(BUILTIN_TYPE(klass)))
331
+
332
+ static inline bool
333
+ RCLASS_PRIME_CLASSEXT_READABLE_P(VALUE klass)
334
+ {
335
+ VM_ASSERT(klass != 0, "klass should be a valid object");
336
+ VM_ASSERT_BOXABLE_TYPE(klass);
337
+ // if the lookup table exists, then it means the prime classext is NOT directly readable.
338
+ return !FL_TEST_RAW(klass, RCLASS_BOXABLE) || RCLASS_CLASSEXT_TBL(klass) == NULL;
339
+ }
340
+
341
+ static inline bool
342
+ RCLASS_PRIME_CLASSEXT_WRITABLE_P(VALUE klass)
343
+ {
344
+ VM_ASSERT(klass != 0, "klass should be a valid object");
345
+ VM_ASSERT_BOXABLE_TYPE(klass);
346
+ RBIMPL_ASSUME(klass != 0);
347
+ return FL_TEST_RAW(klass, RCLASS_PRIME_CLASSEXT_WRITABLE);
348
+ }
349
+
350
+ static inline void
351
+ RCLASS_SET_PRIME_CLASSEXT_WRITABLE(VALUE klass, bool writable)
352
+ {
353
+ VM_ASSERT(klass != 0, "klass should be a valid object");
354
+ VM_ASSERT_BOXABLE_TYPE(klass);
355
+ if (writable) {
356
+ FL_SET_RAW(klass, RCLASS_PRIME_CLASSEXT_WRITABLE);
357
+ }
358
+ else {
359
+ FL_UNSET_RAW(klass, RCLASS_PRIME_CLASSEXT_WRITABLE);
360
+ }
361
+ }
362
+
363
+ static inline rb_classext_t *
364
+ RCLASS_EXT_TABLE_LOOKUP_INTERNAL(VALUE obj, const rb_box_t *box)
365
+ {
366
+ st_data_t classext_ptr;
367
+ st_table *classext_tbl = RCLASS_CLASSEXT_TBL(obj);
368
+ if (classext_tbl) {
369
+ if (rb_st_lookup(classext_tbl, (st_data_t)box->box_object, &classext_ptr)) {
370
+ return (rb_classext_t *)classext_ptr;
371
+ }
372
+ }
373
+ return NULL;
374
+ }
375
+
376
+ static inline rb_classext_t *
377
+ RCLASS_EXT_READABLE_LOOKUP(VALUE obj, const rb_box_t *box)
378
+ {
379
+ rb_classext_t *ext = RCLASS_EXT_TABLE_LOOKUP_INTERNAL(obj, box);
380
+ if (ext)
381
+ return ext;
382
+ // Classext for the ns not found. Refer the prime one instead.
383
+ return RCLASS_EXT_PRIME(obj);
384
+ }
385
+
386
+ static inline rb_classext_t *
387
+ RCLASS_EXT_READABLE_IN_BOX(VALUE obj, const rb_box_t *box)
388
+ {
389
+ if (BOX_MASTER_P(box)
390
+ || RCLASS_PRIME_CLASSEXT_READABLE_P(obj)) {
391
+ return RCLASS_EXT_PRIME(obj);
392
+ }
393
+ return RCLASS_EXT_READABLE_LOOKUP(obj, box);
394
+ }
395
+
396
+ static inline rb_classext_t *
397
+ RCLASS_EXT_READABLE(VALUE obj)
398
+ {
399
+ const rb_box_t *box;
400
+ if (RCLASS_PRIME_CLASSEXT_READABLE_P(obj)) {
401
+ return RCLASS_EXT_PRIME(obj);
402
+ }
403
+ // delay determining the current box to optimize for unmodified classes
404
+ box = rb_current_box();
405
+ if (BOX_MASTER_P(box)) {
406
+ return RCLASS_EXT_PRIME(obj);
407
+ }
408
+ return RCLASS_EXT_READABLE_LOOKUP(obj, box);
409
+ }
410
+
411
+ static inline rb_classext_t *
412
+ RCLASS_EXT_WRITABLE_LOOKUP(VALUE obj, const rb_box_t *box)
413
+ {
414
+ rb_classext_t *ext;
415
+ int first_set = 0;
416
+
417
+ ext = RCLASS_EXT_TABLE_LOOKUP_INTERNAL(obj, box);
418
+ if (ext)
419
+ return ext;
420
+
421
+ RB_VM_LOCKING() {
422
+ // re-check the classext is not created to avoid the multi-thread race
423
+ ext = RCLASS_EXT_TABLE_LOOKUP_INTERNAL(obj, box);
424
+ if (!ext) {
425
+ ext = rb_class_duplicate_classext(RCLASS_EXT_PRIME(obj), obj, box, &first_set);
426
+ if (first_set) {
427
+ // TODO: are there any case that a class/module become non-writable after its birthtime?
428
+ RCLASS_SET_PRIME_CLASSEXT_WRITABLE(obj, false);
429
+ }
430
+ }
431
+ }
432
+ return ext;
433
+ }
434
+
435
+ static inline rb_classext_t *
436
+ RCLASS_EXT_WRITABLE_IN_BOX(VALUE obj, const rb_box_t *box)
437
+ {
438
+ if (BOX_MASTER_P(box)
439
+ || RCLASS_PRIME_CLASSEXT_WRITABLE_P(obj)) {
440
+ return RCLASS_EXT_PRIME(obj);
441
+ }
442
+ return RCLASS_EXT_WRITABLE_LOOKUP(obj, box);
443
+ }
444
+
445
+ static inline rb_classext_t *
446
+ RCLASS_EXT_WRITABLE(VALUE obj)
447
+ {
448
+ const rb_box_t *box;
449
+ if (LIKELY(RCLASS_PRIME_CLASSEXT_WRITABLE_P(obj))) {
450
+ return RCLASS_EXT_PRIME(obj);
451
+ }
452
+ // delay determining the current box to optimize for unmodified classes
453
+ box = rb_current_box();
454
+ if (BOX_MASTER_P(box)) {
455
+ return RCLASS_EXT_PRIME(obj);
456
+ }
457
+ return RCLASS_EXT_WRITABLE_LOOKUP(obj, box);
458
+ }
459
+
460
+ static inline void
461
+ RCLASSEXT_SET_ORIGIN(rb_classext_t *ext, VALUE klass, VALUE origin)
462
+ {
463
+ RB_OBJ_WRITE(klass, &(RCLASSEXT_ORIGIN(ext)), origin);
464
+ }
465
+
466
+ static inline void
467
+ RCLASSEXT_SET_INCLUDER(rb_classext_t *ext, VALUE klass, VALUE includer)
468
+ {
469
+ RUBY_ASSERT(RB_TYPE_P(klass, T_ICLASS));
470
+ RB_OBJ_WRITE(klass, &(RCLASSEXT_INCLUDER(ext)), includer);
471
+ }
472
+
473
+ /* class.c */
474
+ typedef void rb_class_classext_foreach_callback_func(rb_classext_t *classext, bool is_prime, VALUE box_value, void *arg);
475
+ void rb_class_classext_foreach(VALUE klass, rb_class_classext_foreach_callback_func *func, void *arg);
476
+ void rb_class_subclass_add(VALUE super, VALUE klass);
477
+ void rb_class_foreach_subclass(VALUE klass, void (*f)(VALUE, VALUE), VALUE);
478
+ void rb_class_update_superclasses(VALUE);
479
+ int rb_singleton_class_internal_p(VALUE sklass);
480
+ VALUE rb_class_set_super(VALUE klass, VALUE super);
481
+ VALUE rb_class_boot(VALUE);
482
+ VALUE rb_class_s_alloc(VALUE klass);
483
+ VALUE rb_module_s_alloc(VALUE klass);
484
+ void rb_class_set_initialized(VALUE klass);
485
+ void rb_module_check_initializable(VALUE module);
486
+ VALUE rb_make_metaclass(VALUE, VALUE);
487
+ VALUE rb_include_class_new(VALUE, VALUE);
488
+ VALUE rb_define_class_id_under_no_pin(VALUE outer, ID id, VALUE super);
489
+ VALUE rb_obj_methods(int argc, const VALUE *argv, VALUE obj);
490
+ VALUE rb_obj_protected_methods(int argc, const VALUE *argv, VALUE obj);
491
+ VALUE rb_obj_private_methods(int argc, const VALUE *argv, VALUE obj);
492
+ VALUE rb_obj_public_methods(int argc, const VALUE *argv, VALUE obj);
493
+ VALUE rb_class_undefined_instance_methods(VALUE mod);
494
+ VALUE rb_special_singleton_class(VALUE);
495
+ VALUE rb_singleton_class_clone_and_attach(VALUE obj, VALUE attach);
496
+ VALUE rb_singleton_class_get(VALUE obj);
497
+ void rb_undef_methods_from(VALUE klass, VALUE super);
498
+ VALUE rb_class_inherited(VALUE, VALUE);
499
+ VALUE rb_keyword_error_new(const char *, VALUE);
500
+
501
+ rb_classext_t *rb_class_unlink_classext(VALUE klass, const rb_box_t *box);
502
+ void rb_class_classext_free(VALUE klass, rb_classext_t *ext, bool is_prime);
503
+ void rb_iclass_classext_free(VALUE klass, rb_classext_t *ext, bool is_prime);
504
+ void rb_freeze_singleton_class(VALUE attached_object);
505
+
506
+ RUBY_SYMBOL_EXPORT_BEGIN
507
+
508
+ /* for objspace */
509
+ VALUE rb_class_super_of(VALUE klass);
510
+ VALUE rb_class_singleton_p(VALUE klass);
511
+ unsigned char rb_class_variation_count(VALUE klass);
512
+
513
+ RUBY_SYMBOL_EXPORT_END
514
+
515
+ static inline bool
516
+ RCLASS_SINGLETON_P(VALUE klass)
517
+ {
518
+ RUBY_ASSERT(RB_TYPE_P(klass, T_CLASS) || RB_TYPE_P(klass, T_MODULE) || RB_TYPE_P(klass, T_ICLASS));
519
+ return RB_BUILTIN_TYPE(klass) == T_CLASS && FL_TEST_RAW(klass, FL_SINGLETON);
520
+ }
521
+
522
+ static inline void
523
+ RCLASS_SET_SUPER(VALUE klass, VALUE super)
524
+ {
525
+ RB_OBJ_WRITE(klass, &RCLASSEXT_SUPER(RCLASS_EXT_PRIME(klass)), super);
526
+ }
527
+
528
+ static inline void
529
+ RCLASS_WRITE_SUPER(VALUE klass, VALUE super)
530
+ {
531
+ RB_OBJ_WRITE(klass, &RCLASSEXT_SUPER(RCLASS_EXT_WRITABLE(klass)), super);
532
+ }
533
+
534
+ static inline VALUE
535
+ RCLASS_WRITABLE_ENSURE_FIELDS_OBJ(VALUE obj)
536
+ {
537
+ RUBY_ASSERT(RB_TYPE_P(obj, RUBY_T_CLASS) || RB_TYPE_P(obj, RUBY_T_MODULE));
538
+ rb_classext_t *ext = RCLASS_EXT_WRITABLE(obj);
539
+ if (!ext->fields_obj) {
540
+ RB_OBJ_WRITE(obj, &ext->fields_obj, rb_imemo_fields_new(obj, ROOT_SHAPE_ID, true));
541
+ }
542
+ return ext->fields_obj;
543
+ }
544
+
545
+ static inline VALUE
546
+ RCLASS_WRITABLE_FIELDS_OBJ(VALUE obj)
547
+ {
548
+ RUBY_ASSERT(RB_TYPE_P(obj, RUBY_T_CLASS) || RB_TYPE_P(obj, RUBY_T_MODULE));
549
+ return RCLASSEXT_FIELDS_OBJ(RCLASS_EXT_WRITABLE(obj));
550
+ }
551
+
552
+ static inline void
553
+ RCLASSEXT_SET_FIELDS_OBJ(VALUE obj, rb_classext_t *ext, VALUE fields_obj)
554
+ {
555
+ RUBY_ASSERT(RB_TYPE_P(obj, RUBY_T_CLASS) || RB_TYPE_P(obj, RUBY_T_MODULE));
556
+
557
+ RB_OBJ_ATOMIC_WRITE(obj, &ext->fields_obj, fields_obj);
558
+ }
559
+
560
+ static inline void
561
+ RCLASS_WRITABLE_SET_FIELDS_OBJ(VALUE obj, VALUE fields_obj)
562
+ {
563
+ RUBY_ASSERT(RB_TYPE_P(obj, RUBY_T_CLASS) || RB_TYPE_P(obj, RUBY_T_MODULE));
564
+
565
+ RCLASSEXT_SET_FIELDS_OBJ(obj, RCLASS_EXT_WRITABLE(obj), fields_obj);
566
+ }
567
+
568
+ static inline uint32_t
569
+ RCLASS_FIELDS_COUNT(VALUE obj)
570
+ {
571
+ RUBY_ASSERT(RB_TYPE_P(obj, RUBY_T_CLASS) || RB_TYPE_P(obj, RUBY_T_MODULE));
572
+
573
+ VALUE fields_obj = RCLASS_WRITABLE_FIELDS_OBJ(obj);
574
+ if (fields_obj) {
575
+ if (rb_obj_shape_complex_p(fields_obj)) {
576
+ return (uint32_t)rb_st_table_size(rb_imemo_fields_complex_tbl(fields_obj));
577
+ }
578
+ else {
579
+ return RSHAPE_LEN(RBASIC_SHAPE_ID(fields_obj));
580
+ }
581
+ }
582
+ return 0;
583
+ }
584
+
585
+ static inline void
586
+ RCLASS_SET_M_TBL(VALUE klass, struct rb_id_table *table)
587
+ {
588
+ RCLASSEXT_M_TBL(RCLASS_EXT_PRIME(klass)) = table;
589
+ }
590
+
591
+ static inline void
592
+ RCLASS_WRITE_M_TBL(VALUE klass, struct rb_id_table *table)
593
+ {
594
+ RCLASSEXT_M_TBL(RCLASS_EXT_WRITABLE(klass)) = table;
595
+ }
596
+
597
+ static inline void
598
+ RCLASS_SET_CONST_TBL(VALUE klass, struct rb_id_table *table, bool shared)
599
+ {
600
+ rb_classext_t *ext = RCLASS_EXT_PRIME(klass);
601
+ RCLASSEXT_CONST_TBL(ext) = table;
602
+ if (shared)
603
+ RCLASSEXT_SHARED_CONST_TBL(ext) = true;
604
+ }
605
+
606
+ static inline void
607
+ RCLASS_WRITE_CONST_TBL(VALUE klass, struct rb_id_table *table, bool shared)
608
+ {
609
+ rb_classext_t *ext = RCLASS_EXT_WRITABLE(klass);
610
+ RCLASSEXT_CONST_TBL(ext) = table;
611
+ if (shared)
612
+ RCLASSEXT_SHARED_CONST_TBL(ext) = true;
613
+ }
614
+
615
+ static inline void
616
+ RCLASS_WRITE_CALLABLE_M_TBL(VALUE klass, struct rb_id_table *table)
617
+ {
618
+ RCLASSEXT_CALLABLE_M_TBL(RCLASS_EXT_WRITABLE(klass)) = table;
619
+ }
620
+
621
+ static inline void
622
+ RCLASS_WRITE_CC_TBL(VALUE klass, VALUE table)
623
+ {
624
+ RB_OBJ_ATOMIC_WRITE(klass, &RCLASSEXT_CC_TBL(RCLASS_EXT_WRITABLE(klass)), table);
625
+ }
626
+
627
+ static inline void
628
+ RCLASS_SET_CVC_TBL(VALUE klass, VALUE table)
629
+ {
630
+ RB_OBJ_ATOMIC_WRITE(klass, &RCLASSEXT_CVC_TBL(RCLASS_EXT_PRIME(klass)), table);
631
+ }
632
+
633
+ static inline void
634
+ RCLASS_WRITE_CVC_TBL(VALUE klass, VALUE table)
635
+ {
636
+ RB_OBJ_ATOMIC_WRITE(klass, &RCLASSEXT_CVC_TBL(RCLASS_EXT_WRITABLE(klass)), table);
637
+ }
638
+
639
+ static inline void
640
+ RCLASS_SET_REFINED_CLASS(VALUE klass, VALUE refined)
641
+ {
642
+ RB_OBJ_WRITE(klass, &RCLASSEXT_REFINED_CLASS(RCLASS_EXT_PRIME(klass)), refined);
643
+ }
644
+
645
+ static inline rb_alloc_func_t
646
+ RCLASS_ALLOCATOR(VALUE klass)
647
+ {
648
+ RBIMPL_ASSERT_TYPE(klass, T_CLASS);
649
+ RUBY_ASSERT(!RCLASS_SINGLETON_P(klass));
650
+ return RCLASS_EXT_PRIME(klass)->as.class.allocator;
651
+ }
652
+
653
+ static inline void
654
+ RCLASS_SET_ALLOCATOR(VALUE klass, rb_alloc_func_t allocator)
655
+ {
656
+ RUBY_ASSERT(RB_TYPE_P(klass, T_CLASS));
657
+ RUBY_ASSERT(!RCLASS_SINGLETON_P(klass));
658
+ RCLASS_EXT_PRIME(klass)->as.class.allocator = allocator; // Allocator is set only on the initial definition
659
+ }
660
+
661
+ static inline void
662
+ RCLASS_SET_ORIGIN(VALUE klass, VALUE origin)
663
+ {
664
+ rb_classext_t *ext = RCLASS_EXT_PRIME(klass);
665
+ RB_OBJ_WRITE(klass, &RCLASSEXT_ORIGIN(ext), origin);
666
+ if (klass != origin) RCLASSEXT_ICLASS_IS_ORIGIN(RCLASS_EXT_WRITABLE(origin)) = true;
667
+ }
668
+
669
+ static inline void
670
+ RCLASS_WRITE_ORIGIN(VALUE klass, VALUE origin)
671
+ {
672
+ rb_classext_t *ext = RCLASS_EXT_WRITABLE(klass);
673
+ RB_OBJ_WRITE(klass, &RCLASSEXT_ORIGIN(ext), origin);
674
+ if (klass != origin) RCLASSEXT_ICLASS_IS_ORIGIN(RCLASS_EXT_WRITABLE(origin)) = true;
675
+ }
676
+
677
+ static inline void
678
+ RICLASS_SET_ORIGIN_SHARED_MTBL(VALUE iclass)
679
+ {
680
+ RCLASSEXT_ICLASS_ORIGIN_SHARED_MTBL(RCLASS_EXT_PRIME(iclass)) = true;
681
+ }
682
+
683
+ static inline void
684
+ RICLASS_WRITE_ORIGIN_SHARED_MTBL(VALUE iclass)
685
+ {
686
+ RCLASSEXT_ICLASS_ORIGIN_SHARED_MTBL(RCLASS_EXT_WRITABLE(iclass)) = true;
687
+ }
688
+
689
+ static inline bool
690
+ RICLASS_OWNS_M_TBL_P(VALUE iclass)
691
+ {
692
+ rb_classext_t *ext = RCLASS_EXT_READABLE(iclass);
693
+ return RCLASSEXT_ICLASS_IS_ORIGIN(ext) && !RCLASSEXT_ICLASS_ORIGIN_SHARED_MTBL(ext);
694
+ }
695
+
696
+ static inline bool
697
+ RICLASS_FOR_REFINEMENT_P(VALUE iclass)
698
+ {
699
+ return BUILTIN_TYPE(iclass) == T_ICLASS &&
700
+ RB_TYPE_P(RBASIC(iclass)->klass, T_MODULE) &&
701
+ FL_TEST_RAW(RBASIC(iclass)->klass, RMODULE_IS_REFINEMENT);
702
+ }
703
+
704
+ static inline void
705
+ RCLASS_SET_INCLUDER(VALUE iclass, VALUE klass)
706
+ {
707
+ RUBY_ASSERT(RB_TYPE_P(iclass, T_ICLASS));
708
+ RB_OBJ_WRITE(iclass, &RCLASS_INCLUDER(iclass), klass);
709
+ }
710
+
711
+ static inline void
712
+ RCLASS_SET_MODULE_REFINEMENT_ICLASSES(VALUE iclass, VALUE table)
713
+ {
714
+ RUBY_ASSERT(RB_TYPE_P(iclass, T_ICLASS));
715
+ RB_OBJ_WRITE(iclass, &RCLASS_MODULE_REFINEMENT_ICLASSES(iclass), table);
716
+ }
717
+
718
+ static inline void
719
+ RCLASS_WRITE_SUPERCLASSES(VALUE klass, size_t depth, VALUE *superclasses, bool with_self)
720
+ {
721
+ RUBY_ASSERT(depth <= RCLASS_MAX_SUPERCLASS_DEPTH);
722
+
723
+ rb_classext_t *ext = RCLASS_EXT_PRIME(klass);
724
+ RCLASSEXT_SUPERCLASS_DEPTH(ext) = depth;
725
+ RCLASSEXT_SUPERCLASSES(ext) = superclasses;
726
+ RCLASSEXT_SUPERCLASSES_WITH_SELF(ext) = with_self;
727
+ }
728
+
729
+ static inline void
730
+ RCLASS_SET_SUBCLASSES(VALUE klass, VALUE subclasses)
731
+ {
732
+ rb_classext_t *ext = RCLASS_EXT_PRIME(klass);
733
+ RB_OBJ_WRITE(klass, &RCLASSEXT_SUBCLASSES(ext), subclasses);
734
+ }
735
+
736
+ static inline void
737
+ RCLASS_SET_CLASSPATH(VALUE klass, VALUE classpath, bool permanent)
738
+ {
739
+ rb_classext_t *ext = RCLASS_EXT_READABLE(klass);
740
+ assert(BUILTIN_TYPE(klass) == T_CLASS || BUILTIN_TYPE(klass) == T_MODULE);
741
+ assert(classpath == 0 || BUILTIN_TYPE(classpath) == T_STRING);
742
+ assert(FL_TEST_RAW(classpath, RUBY_FL_SHAREABLE));
743
+
744
+ RB_OBJ_WRITE(klass, &(RCLASSEXT_CLASSPATH(ext)), classpath);
745
+ RCLASSEXT_PERMANENT_CLASSPATH(ext) = permanent;
746
+ }
747
+
748
+ static inline void
749
+ RCLASS_WRITE_CLASSPATH(VALUE klass, VALUE classpath, bool permanent)
750
+ {
751
+ rb_classext_t *ext = RCLASS_EXT_WRITABLE(klass);
752
+ assert(BUILTIN_TYPE(klass) == T_CLASS || BUILTIN_TYPE(klass) == T_MODULE);
753
+ assert(classpath == 0 || BUILTIN_TYPE(classpath) == T_STRING);
754
+ assert(!RB_FL_ABLE(classpath) || FL_TEST_RAW(classpath, RUBY_FL_SHAREABLE));
755
+
756
+ RB_OBJ_WRITE(klass, &(RCLASSEXT_CLASSPATH(ext)), classpath);
757
+ RCLASSEXT_PERMANENT_CLASSPATH(ext) = permanent;
758
+ }
759
+
760
+ static inline VALUE
761
+ RCLASS_SET_ATTACHED_OBJECT(VALUE klass, VALUE attached_object)
762
+ {
763
+ assert(RCLASS_SINGLETON_P(klass));
764
+
765
+ RB_OBJ_WRITE(klass, &RCLASS_EXT_PRIME(klass)->as.singleton_class.attached_object, attached_object);
766
+ return attached_object;
767
+ }
768
+
769
+ static inline void
770
+ RCLASS_SET_MAX_IV_COUNT(VALUE klass, attr_index_t count)
771
+ {
772
+ RUBY_ASSERT(klass != rb_cObject);
773
+ RUBY_ASSERT(klass != rb_cBasicObject);
774
+
775
+ RCLASS_MAX_IV_COUNT(klass) = count;
776
+ }
777
+
778
+ static inline void
779
+ RCLASS_SET_EXPECT_NO_IVAR(VALUE klass)
780
+ {
781
+ RCLASS_EXT_PRIME(klass)->expect_no_ivar = true;
782
+ }
783
+
784
+ static inline bool
785
+ RCLASS_EXPECT_NO_IVAR(VALUE klass)
786
+ {
787
+ return RCLASS_EXT_PRIME(klass)->expect_no_ivar;
788
+ }
789
+
790
+ static inline bool
791
+ RCLASS_INITIALIZED_P(VALUE klass)
792
+ {
793
+ VM_ASSERT(RB_TYPE_P(klass, T_CLASS) || RB_TYPE_P(klass, T_MODULE));
794
+ return FL_TEST_RAW(klass, RCLASS_IS_INITIALIZED);
795
+ }
796
+
797
+ #endif /* INTERNAL_CLASS_H */