debase-ruby_core_source 3.4.1 → 4.0.0.preview2

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