llrb 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +21 -0
  3. data/.gitmodules +4 -0
  4. data/.rspec +2 -0
  5. data/.travis.yml +5 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +56 -0
  8. data/README.md +311 -0
  9. data/Rakefile +30 -0
  10. data/bin/bm_app_fib +41 -0
  11. data/bin/bm_empty_method +33 -0
  12. data/bin/bm_loop_while +27 -0
  13. data/bin/bm_plus +33 -0
  14. data/bin/console +14 -0
  15. data/bin/loop_while.rb +5 -0
  16. data/bin/setup +8 -0
  17. data/ext/llrb/cfg.h +124 -0
  18. data/ext/llrb/compiler.c +987 -0
  19. data/ext/llrb/compiler/funcs.h +164 -0
  20. data/ext/llrb/compiler/stack.h +43 -0
  21. data/ext/llrb/cruby.h +42 -0
  22. data/ext/llrb/cruby/ccan/build_assert/build_assert.h +40 -0
  23. data/ext/llrb/cruby/ccan/check_type/check_type.h +63 -0
  24. data/ext/llrb/cruby/ccan/container_of/container_of.h +142 -0
  25. data/ext/llrb/cruby/ccan/list/list.h +773 -0
  26. data/ext/llrb/cruby/ccan/str/str.h +16 -0
  27. data/ext/llrb/cruby/internal.h +1774 -0
  28. data/ext/llrb/cruby/iseq.h +252 -0
  29. data/ext/llrb/cruby/method.h +213 -0
  30. data/ext/llrb/cruby/node.h +520 -0
  31. data/ext/llrb/cruby/probes_helper.h +43 -0
  32. data/ext/llrb/cruby/ruby_assert.h +54 -0
  33. data/ext/llrb/cruby/ruby_atomic.h +233 -0
  34. data/ext/llrb/cruby/thread_pthread.h +54 -0
  35. data/ext/llrb/cruby/vm_core.h +1646 -0
  36. data/ext/llrb/cruby/vm_debug.h +37 -0
  37. data/ext/llrb/cruby/vm_exec.h +182 -0
  38. data/ext/llrb/cruby/vm_opts.h +57 -0
  39. data/ext/llrb/cruby_extra/id.h +220 -0
  40. data/ext/llrb/cruby_extra/insns.inc +113 -0
  41. data/ext/llrb/cruby_extra/insns_info.inc +796 -0
  42. data/ext/llrb/cruby_extra/probes.h +80 -0
  43. data/ext/llrb/extconf.rb +102 -0
  44. data/ext/llrb/llrb.c +148 -0
  45. data/ext/llrb/optimizer.cc +118 -0
  46. data/ext/llrb/parser.c +191 -0
  47. data/ext/llrb/profiler.c +336 -0
  48. data/ext/llrb_insn_checkkeyword.c +20 -0
  49. data/ext/llrb_insn_checkmatch.c +28 -0
  50. data/ext/llrb_insn_concatarray.c +23 -0
  51. data/ext/llrb_insn_concatstrings.c +21 -0
  52. data/ext/llrb_insn_defined.c +9 -0
  53. data/ext/llrb_insn_getclassvariable.c +10 -0
  54. data/ext/llrb_insn_getinstancevariable.c +44 -0
  55. data/ext/llrb_insn_getlocal.c +14 -0
  56. data/ext/llrb_insn_getlocal_level0.c +8 -0
  57. data/ext/llrb_insn_getlocal_level1.c +8 -0
  58. data/ext/llrb_insn_getspecial.c +14 -0
  59. data/ext/llrb_insn_invokeblock.c +39 -0
  60. data/ext/llrb_insn_invokesuper.c +47 -0
  61. data/ext/llrb_insn_opt_aref.c +25 -0
  62. data/ext/llrb_insn_opt_aset.c +28 -0
  63. data/ext/llrb_insn_opt_div.c +32 -0
  64. data/ext/llrb_insn_opt_eq.c +57 -0
  65. data/ext/llrb_insn_opt_ge.c +28 -0
  66. data/ext/llrb_insn_opt_gt.c +38 -0
  67. data/ext/llrb_insn_opt_le.c +29 -0
  68. data/ext/llrb_insn_opt_lt.c +38 -0
  69. data/ext/llrb_insn_opt_ltlt.c +27 -0
  70. data/ext/llrb_insn_opt_minus.c +36 -0
  71. data/ext/llrb_insn_opt_mod.c +32 -0
  72. data/ext/llrb_insn_opt_mult.c +30 -0
  73. data/ext/llrb_insn_opt_neq.c +103 -0
  74. data/ext/llrb_insn_opt_plus.c +48 -0
  75. data/ext/llrb_insn_opt_send_without_block.c +45 -0
  76. data/ext/llrb_insn_opt_str_freeze.c +12 -0
  77. data/ext/llrb_insn_putspecialobject.c +23 -0
  78. data/ext/llrb_insn_send.c +49 -0
  79. data/ext/llrb_insn_setclassvariable.c +19 -0
  80. data/ext/llrb_insn_setconstant.c +23 -0
  81. data/ext/llrb_insn_setinstancevariable.c +48 -0
  82. data/ext/llrb_insn_setlocal.c +16 -0
  83. data/ext/llrb_insn_setlocal_level0.c +9 -0
  84. data/ext/llrb_insn_setlocal_level1.c +10 -0
  85. data/ext/llrb_insn_setspecial.c +15 -0
  86. data/ext/llrb_insn_splatarray.c +13 -0
  87. data/ext/llrb_insn_throw.c +11 -0
  88. data/ext/llrb_insn_trace.c +37 -0
  89. data/ext/llrb_push_result.c +14 -0
  90. data/ext/llrb_self_from_cfp.c +12 -0
  91. data/ext/llrb_set_pc.c +8 -0
  92. data/lib/llrb.rb +2 -0
  93. data/lib/llrb/jit.rb +76 -0
  94. data/lib/llrb/start.rb +2 -0
  95. data/lib/llrb/version.rb +3 -0
  96. data/llrb.gemspec +48 -0
  97. data/wercker.yml +31 -0
  98. metadata +227 -0
@@ -0,0 +1,16 @@
1
+ /* CC0 (Public domain) - see ccan/licenses/CC0 file for details */
2
+ #ifndef CCAN_STR_H
3
+ #define CCAN_STR_H
4
+ /**
5
+ * stringify - Turn expression into a string literal
6
+ * @expr: any C expression
7
+ *
8
+ * Example:
9
+ * #define PRINT_COND_IF_FALSE(cond) \
10
+ * ((cond) || printf("%s is false!", stringify(cond)))
11
+ */
12
+ #define stringify(expr) stringify_1(expr)
13
+ /* Double-indirection required to stringify expansions */
14
+ #define stringify_1(expr) #expr
15
+
16
+ #endif /* CCAN_STR_H */
@@ -0,0 +1,1774 @@
1
+ /**********************************************************************
2
+
3
+ internal.h -
4
+
5
+ $Author$
6
+ created at: Tue May 17 11:42:20 JST 2011
7
+
8
+ Copyright (C) 2011 Yukihiro Matsumoto
9
+
10
+ **********************************************************************/
11
+
12
+ #ifndef RUBY_INTERNAL_H
13
+ #define RUBY_INTERNAL_H 1
14
+
15
+ #include "ruby.h"
16
+ #include "ruby/encoding.h"
17
+ #include "ruby/io.h"
18
+
19
+ #if defined(__cplusplus)
20
+ extern "C" {
21
+ #if 0
22
+ } /* satisfy cc-mode */
23
+ #endif
24
+ #endif
25
+
26
+ #define LIKELY(x) RB_LIKELY(x)
27
+ #define UNLIKELY(x) RB_UNLIKELY(x)
28
+
29
+ #ifndef MAYBE_UNUSED
30
+ # define MAYBE_UNUSED(x) x
31
+ #endif
32
+
33
+ #ifndef WARN_UNUSED_RESULT
34
+ # define WARN_UNUSED_RESULT(x) x
35
+ #endif
36
+
37
+ #ifdef HAVE_VALGRIND_MEMCHECK_H
38
+ # include <valgrind/memcheck.h>
39
+ # ifndef VALGRIND_MAKE_MEM_DEFINED
40
+ # define VALGRIND_MAKE_MEM_DEFINED(p, n) VALGRIND_MAKE_READABLE((p), (n))
41
+ # endif
42
+ # ifndef VALGRIND_MAKE_MEM_UNDEFINED
43
+ # define VALGRIND_MAKE_MEM_UNDEFINED(p, n) VALGRIND_MAKE_WRITABLE((p), (n))
44
+ # endif
45
+ #else
46
+ # define VALGRIND_MAKE_MEM_DEFINED(p, n) 0
47
+ # define VALGRIND_MAKE_MEM_UNDEFINED(p, n) 0
48
+ #endif
49
+
50
+ #define numberof(array) ((int)(sizeof(array) / sizeof((array)[0])))
51
+
52
+ #ifndef __has_feature
53
+ # define __has_feature(x) 0
54
+ #endif
55
+
56
+ #ifndef __has_extension
57
+ # define __has_extension __has_feature
58
+ #endif
59
+
60
+ #if GCC_VERSION_SINCE(4, 6, 0) || __has_extension(c_static_assert)
61
+ # define STATIC_ASSERT(name, expr) _Static_assert(expr, #name ": " #expr)
62
+ #else
63
+ # define STATIC_ASSERT(name, expr) typedef int static_assert_##name##_check[1 - 2*!(expr)]
64
+ #endif
65
+
66
+ #define SIGNED_INTEGER_TYPE_P(int_type) (0 > ((int_type)0)-1)
67
+ #define SIGNED_INTEGER_MAX(sint_type) \
68
+ (sint_type) \
69
+ ((((sint_type)1) << (sizeof(sint_type) * CHAR_BIT - 2)) | \
70
+ ((((sint_type)1) << (sizeof(sint_type) * CHAR_BIT - 2)) - 1))
71
+ #define SIGNED_INTEGER_MIN(sint_type) (-SIGNED_INTEGER_MAX(sint_type)-1)
72
+ #define UNSIGNED_INTEGER_MAX(uint_type) (~(uint_type)0)
73
+
74
+ #if SIGNEDNESS_OF_TIME_T < 0 /* signed */
75
+ # define TIMET_MAX SIGNED_INTEGER_MAX(time_t)
76
+ # define TIMET_MIN SIGNED_INTEGER_MIN(time_t)
77
+ #elif SIGNEDNESS_OF_TIME_T > 0 /* unsigned */
78
+ # define TIMET_MAX UNSIGNED_INTEGER_MAX(time_t)
79
+ # define TIMET_MIN ((time_t)0)
80
+ #endif
81
+ #define TIMET_MAX_PLUS_ONE (2*(double)(TIMET_MAX/2+1))
82
+
83
+ #define MUL_OVERFLOW_SIGNED_INTEGER_P(a, b, min, max) ( \
84
+ (a) == 0 ? 0 : \
85
+ (a) == -1 ? (b) < -(max) : \
86
+ (a) > 0 ? \
87
+ ((b) > 0 ? (max) / (a) < (b) : (min) / (a) > (b)) : \
88
+ ((b) > 0 ? (min) / (a) < (b) : (max) / (a) > (b)))
89
+ #define MUL_OVERFLOW_FIXNUM_P(a, b) MUL_OVERFLOW_SIGNED_INTEGER_P(a, b, FIXNUM_MIN, FIXNUM_MAX)
90
+ #define MUL_OVERFLOW_LONG_P(a, b) MUL_OVERFLOW_SIGNED_INTEGER_P(a, b, LONG_MIN, LONG_MAX)
91
+ #define MUL_OVERFLOW_INT_P(a, b) MUL_OVERFLOW_SIGNED_INTEGER_P(a, b, INT_MIN, INT_MAX)
92
+
93
+ #ifndef swap16
94
+ # ifdef HAVE_BUILTIN___BUILTIN_BSWAP16
95
+ # define swap16(x) __builtin_bswap16(x)
96
+ # endif
97
+ #endif
98
+
99
+ #ifndef swap16
100
+ # define swap16(x) ((uint16_t)((((x)&0xFF)<<8) | (((x)>>8)&0xFF)))
101
+ #endif
102
+
103
+ #ifndef swap32
104
+ # ifdef HAVE_BUILTIN___BUILTIN_BSWAP32
105
+ # define swap32(x) __builtin_bswap32(x)
106
+ # endif
107
+ #endif
108
+
109
+ #ifndef swap32
110
+ # define swap32(x) ((uint32_t)((((x)&0xFF)<<24) \
111
+ |(((x)>>24)&0xFF) \
112
+ |(((x)&0x0000FF00)<<8) \
113
+ |(((x)&0x00FF0000)>>8) ))
114
+ #endif
115
+
116
+ #ifndef swap64
117
+ # ifdef HAVE_BUILTIN___BUILTIN_BSWAP64
118
+ # define swap64(x) __builtin_bswap64(x)
119
+ # endif
120
+ #endif
121
+
122
+ #ifndef swap64
123
+ # ifdef HAVE_INT64_T
124
+ # define byte_in_64bit(n) ((uint64_t)0xff << (n))
125
+ # define swap64(x) ((uint64_t)((((x)&byte_in_64bit(0))<<56) \
126
+ |(((x)>>56)&0xFF) \
127
+ |(((x)&byte_in_64bit(8))<<40) \
128
+ |(((x)&byte_in_64bit(48))>>40) \
129
+ |(((x)&byte_in_64bit(16))<<24) \
130
+ |(((x)&byte_in_64bit(40))>>24) \
131
+ |(((x)&byte_in_64bit(24))<<8) \
132
+ |(((x)&byte_in_64bit(32))>>8)))
133
+ # endif
134
+ #endif
135
+
136
+ static inline unsigned int
137
+ nlz_int(unsigned int x)
138
+ {
139
+ #if defined(HAVE_BUILTIN___BUILTIN_CLZ)
140
+ if (x == 0) return SIZEOF_INT * CHAR_BIT;
141
+ return (unsigned int)__builtin_clz(x);
142
+ #else
143
+ unsigned int y;
144
+ # if 64 < SIZEOF_INT * CHAR_BIT
145
+ unsigned int n = 128;
146
+ # elif 32 < SIZEOF_INT * CHAR_BIT
147
+ unsigned int n = 64;
148
+ # else
149
+ unsigned int n = 32;
150
+ # endif
151
+ # if 64 < SIZEOF_INT * CHAR_BIT
152
+ y = x >> 64; if (y) {n -= 64; x = y;}
153
+ # endif
154
+ # if 32 < SIZEOF_INT * CHAR_BIT
155
+ y = x >> 32; if (y) {n -= 32; x = y;}
156
+ # endif
157
+ y = x >> 16; if (y) {n -= 16; x = y;}
158
+ y = x >> 8; if (y) {n -= 8; x = y;}
159
+ y = x >> 4; if (y) {n -= 4; x = y;}
160
+ y = x >> 2; if (y) {n -= 2; x = y;}
161
+ y = x >> 1; if (y) {return n - 2;}
162
+ return (unsigned int)(n - x);
163
+ #endif
164
+ }
165
+
166
+ static inline unsigned int
167
+ nlz_long(unsigned long x)
168
+ {
169
+ #if defined(HAVE_BUILTIN___BUILTIN_CLZL)
170
+ if (x == 0) return SIZEOF_LONG * CHAR_BIT;
171
+ return (unsigned int)__builtin_clzl(x);
172
+ #else
173
+ unsigned long y;
174
+ # if 64 < SIZEOF_LONG * CHAR_BIT
175
+ unsigned int n = 128;
176
+ # elif 32 < SIZEOF_LONG * CHAR_BIT
177
+ unsigned int n = 64;
178
+ # else
179
+ unsigned int n = 32;
180
+ # endif
181
+ # if 64 < SIZEOF_LONG * CHAR_BIT
182
+ y = x >> 64; if (y) {n -= 64; x = y;}
183
+ # endif
184
+ # if 32 < SIZEOF_LONG * CHAR_BIT
185
+ y = x >> 32; if (y) {n -= 32; x = y;}
186
+ # endif
187
+ y = x >> 16; if (y) {n -= 16; x = y;}
188
+ y = x >> 8; if (y) {n -= 8; x = y;}
189
+ y = x >> 4; if (y) {n -= 4; x = y;}
190
+ y = x >> 2; if (y) {n -= 2; x = y;}
191
+ y = x >> 1; if (y) {return n - 2;}
192
+ return (unsigned int)(n - x);
193
+ #endif
194
+ }
195
+
196
+ #ifdef HAVE_LONG_LONG
197
+ static inline unsigned int
198
+ nlz_long_long(unsigned LONG_LONG x)
199
+ {
200
+ #if defined(HAVE_BUILTIN___BUILTIN_CLZLL)
201
+ if (x == 0) return SIZEOF_LONG_LONG * CHAR_BIT;
202
+ return (unsigned int)__builtin_clzll(x);
203
+ #else
204
+ unsigned LONG_LONG y;
205
+ # if 64 < SIZEOF_LONG_LONG * CHAR_BIT
206
+ unsigned int n = 128;
207
+ # elif 32 < SIZEOF_LONG_LONG * CHAR_BIT
208
+ unsigned int n = 64;
209
+ # else
210
+ unsigned int n = 32;
211
+ # endif
212
+ # if 64 < SIZEOF_LONG_LONG * CHAR_BIT
213
+ y = x >> 64; if (y) {n -= 64; x = y;}
214
+ # endif
215
+ # if 32 < SIZEOF_LONG_LONG * CHAR_BIT
216
+ y = x >> 32; if (y) {n -= 32; x = y;}
217
+ # endif
218
+ y = x >> 16; if (y) {n -= 16; x = y;}
219
+ y = x >> 8; if (y) {n -= 8; x = y;}
220
+ y = x >> 4; if (y) {n -= 4; x = y;}
221
+ y = x >> 2; if (y) {n -= 2; x = y;}
222
+ y = x >> 1; if (y) {return n - 2;}
223
+ return (unsigned int)(n - x);
224
+ #endif
225
+ }
226
+ #endif
227
+
228
+ #ifdef HAVE_UINT128_T
229
+ static inline unsigned int
230
+ nlz_int128(uint128_t x)
231
+ {
232
+ uint128_t y;
233
+ unsigned int n = 128;
234
+ y = x >> 64; if (y) {n -= 64; x = y;}
235
+ y = x >> 32; if (y) {n -= 32; x = y;}
236
+ y = x >> 16; if (y) {n -= 16; x = y;}
237
+ y = x >> 8; if (y) {n -= 8; x = y;}
238
+ y = x >> 4; if (y) {n -= 4; x = y;}
239
+ y = x >> 2; if (y) {n -= 2; x = y;}
240
+ y = x >> 1; if (y) {return n - 2;}
241
+ return (unsigned int)(n - x);
242
+ }
243
+ #endif
244
+
245
+ static inline unsigned int
246
+ nlz_intptr(uintptr_t x)
247
+ {
248
+ #if SIZEOF_VOIDP == 8
249
+ return nlz_long_long(x);
250
+ #elif SIZEOF_VOIDP == 4
251
+ return nlz_int(x);
252
+ #endif
253
+ }
254
+
255
+ static inline unsigned int
256
+ rb_popcount32(uint32_t x)
257
+ {
258
+ #ifdef HAVE_BUILTIN___BUILTIN_POPCOUNT
259
+ return (unsigned int)__builtin_popcount(x);
260
+ #else
261
+ x = (x & 0x55555555) + (x >> 1 & 0x55555555);
262
+ x = (x & 0x33333333) + (x >> 2 & 0x33333333);
263
+ x = (x & 0x0f0f0f0f) + (x >> 4 & 0x0f0f0f0f);
264
+ x = (x & 0x001f001f) + (x >> 8 & 0x001f001f);
265
+ return (x & 0x0000003f) + (x >>16 & 0x0000003f);
266
+ #endif
267
+ }
268
+
269
+ static inline int
270
+ rb_popcount64(uint64_t x)
271
+ {
272
+ #ifdef HAVE_BUILTIN___BUILTIN_POPCOUNT
273
+ return __builtin_popcountll(x);
274
+ #else
275
+ x = (x & 0x5555555555555555) + (x >> 1 & 0x5555555555555555);
276
+ x = (x & 0x3333333333333333) + (x >> 2 & 0x3333333333333333);
277
+ x = (x & 0x0707070707070707) + (x >> 4 & 0x0707070707070707);
278
+ x = (x & 0x001f001f001f001f) + (x >> 8 & 0x001f001f001f001f);
279
+ x = (x & 0x0000003f0000003f) + (x >>16 & 0x0000003f0000003f);
280
+ return (x & 0x7f) + (x >>32 & 0x7f);
281
+ #endif
282
+ }
283
+
284
+ static inline int
285
+ rb_popcount_intptr(uintptr_t x)
286
+ {
287
+ #if SIZEOF_VOIDP == 8
288
+ return rb_popcount64(x);
289
+ #elif SIZEOF_VOIDP == 4
290
+ return rb_popcount32(x);
291
+ #endif
292
+ }
293
+
294
+ static inline int
295
+ ntz_int32(uint32_t x)
296
+ {
297
+ #ifdef HAVE_BUILTIN___BUILTIN_CTZ
298
+ return __builtin_ctz(x);
299
+ #else
300
+ return rb_popcount32((~x) & (x-1));
301
+ #endif
302
+ }
303
+
304
+ static inline int
305
+ ntz_int64(uint64_t x)
306
+ {
307
+ #ifdef HAVE_BUILTIN___BUILTIN_CTZLL
308
+ return __builtin_ctzll(x);
309
+ #else
310
+ return rb_popcount64((~x) & (x-1));
311
+ #endif
312
+ }
313
+
314
+ static inline int
315
+ ntz_intptr(uintptr_t x)
316
+ {
317
+ #if SIZEOF_VOIDP == 8
318
+ return ntz_int64(x);
319
+ #elif SIZEOF_VOIDP == 4
320
+ return ntz_int32(x);
321
+ #endif
322
+ }
323
+
324
+ #if HAVE_LONG_LONG && SIZEOF_LONG * 2 <= SIZEOF_LONG_LONG
325
+ # define DLONG LONG_LONG
326
+ # define DL2NUM(x) LL2NUM(x)
327
+ #elif defined(HAVE_INT128_T)
328
+ # define DLONG int128_t
329
+ # define DL2NUM(x) (RB_FIXABLE(x) ? LONG2FIX(x) : rb_int128t2big(x))
330
+ VALUE rb_int128t2big(int128_t n);
331
+ #endif
332
+
333
+ #define ST2FIX(h) LONG2FIX((long)(h))
334
+
335
+
336
+ /* arguments must be Fixnum */
337
+ static inline VALUE
338
+ rb_fix_mul_fix(VALUE x, VALUE y)
339
+ {
340
+ long lx = FIX2LONG(x);
341
+ long ly = FIX2LONG(y);
342
+ #ifdef DLONG
343
+ return DL2NUM((DLONG)lx * (DLONG)ly);
344
+ #else
345
+ if (MUL_OVERFLOW_FIXNUM_P(lx, ly)) {
346
+ return rb_big_mul(rb_int2big(lx), rb_int2big(ly));
347
+ }
348
+ else {
349
+ return LONG2FIX(lx * ly);
350
+ }
351
+ #endif
352
+ }
353
+
354
+ /*
355
+ * This behaves different from C99 for negative arguments.
356
+ * Note that div may overflow fixnum.
357
+ */
358
+ static inline void
359
+ rb_fix_divmod_fix(VALUE a, VALUE b, VALUE *divp, VALUE *modp)
360
+ {
361
+ /* assume / and % comply C99.
362
+ * ldiv(3) won't be inlined by GCC and clang.
363
+ * I expect / and % are compiled as single idiv.
364
+ */
365
+ long x = FIX2LONG(a);
366
+ long y = FIX2LONG(b);
367
+ long div, mod;
368
+ if (x == FIXNUM_MIN && y == -1) {
369
+ if (divp) *divp = LONG2NUM(-FIXNUM_MIN);
370
+ if (modp) *modp = LONG2FIX(0);
371
+ return;
372
+ }
373
+ div = x / y;
374
+ mod = x % y;
375
+ if (y > 0 ? mod < 0 : mod > 0) {
376
+ mod += y;
377
+ div -= 1;
378
+ }
379
+ if (divp) *divp = LONG2FIX(div);
380
+ if (modp) *modp = LONG2FIX(mod);
381
+ }
382
+
383
+ /* div() for Ruby
384
+ * This behaves different from C99 for negative arguments.
385
+ */
386
+ static inline VALUE
387
+ rb_fix_div_fix(VALUE x, VALUE y)
388
+ {
389
+ VALUE div;
390
+ rb_fix_divmod_fix(x, y, &div, NULL);
391
+ return div;
392
+ }
393
+
394
+ /* mod() for Ruby
395
+ * This behaves different from C99 for negative arguments.
396
+ */
397
+ static inline VALUE
398
+ rb_fix_mod_fix(VALUE x, VALUE y)
399
+ {
400
+ VALUE mod;
401
+ rb_fix_divmod_fix(x, y, NULL, &mod);
402
+ return mod;
403
+ }
404
+
405
+ #if defined(HAVE_UINT128_T)
406
+ # define bit_length(x) \
407
+ (unsigned int) \
408
+ (sizeof(x) <= SIZEOF_INT ? SIZEOF_INT * CHAR_BIT - nlz_int((unsigned int)(x)) : \
409
+ sizeof(x) <= SIZEOF_LONG ? SIZEOF_LONG * CHAR_BIT - nlz_long((unsigned long)(x)) : \
410
+ sizeof(x) <= SIZEOF_LONG_LONG ? SIZEOF_LONG_LONG * CHAR_BIT - nlz_long_long((unsigned LONG_LONG)(x)) : \
411
+ SIZEOF_INT128_T * CHAR_BIT - nlz_int128((uint128_t)(x)))
412
+ #elif defined(HAVE_LONG_LONG)
413
+ # define bit_length(x) \
414
+ (unsigned int) \
415
+ (sizeof(x) <= SIZEOF_INT ? SIZEOF_INT * CHAR_BIT - nlz_int((unsigned int)(x)) : \
416
+ sizeof(x) <= SIZEOF_LONG ? SIZEOF_LONG * CHAR_BIT - nlz_long((unsigned long)(x)) : \
417
+ SIZEOF_LONG_LONG * CHAR_BIT - nlz_long_long((unsigned LONG_LONG)(x)))
418
+ #else
419
+ # define bit_length(x) \
420
+ (unsigned int) \
421
+ (sizeof(x) <= SIZEOF_INT ? SIZEOF_INT * CHAR_BIT - nlz_int((unsigned int)(x)) : \
422
+ SIZEOF_LONG * CHAR_BIT - nlz_long((unsigned long)(x)))
423
+ #endif
424
+
425
+ #ifndef BDIGIT
426
+ # if SIZEOF_INT*2 <= SIZEOF_LONG_LONG
427
+ # define BDIGIT unsigned int
428
+ # define SIZEOF_BDIGIT SIZEOF_INT
429
+ # define BDIGIT_DBL unsigned LONG_LONG
430
+ # define BDIGIT_DBL_SIGNED LONG_LONG
431
+ # define PRI_BDIGIT_PREFIX ""
432
+ # define PRI_BDIGIT_DBL_PREFIX PRI_LL_PREFIX
433
+ # elif SIZEOF_INT*2 <= SIZEOF_LONG
434
+ # define BDIGIT unsigned int
435
+ # define SIZEOF_BDIGIT SIZEOF_INT
436
+ # define BDIGIT_DBL unsigned long
437
+ # define BDIGIT_DBL_SIGNED long
438
+ # define PRI_BDIGIT_PREFIX ""
439
+ # define PRI_BDIGIT_DBL_PREFIX "l"
440
+ # elif SIZEOF_SHORT*2 <= SIZEOF_LONG
441
+ # define BDIGIT unsigned short
442
+ # define SIZEOF_BDIGIT SIZEOF_SHORT
443
+ # define BDIGIT_DBL unsigned long
444
+ # define BDIGIT_DBL_SIGNED long
445
+ # define PRI_BDIGIT_PREFIX "h"
446
+ # define PRI_BDIGIT_DBL_PREFIX "l"
447
+ # else
448
+ # define BDIGIT unsigned short
449
+ # define SIZEOF_BDIGIT (SIZEOF_LONG/2)
450
+ # define SIZEOF_ACTUAL_BDIGIT SIZEOF_LONG
451
+ # define BDIGIT_DBL unsigned long
452
+ # define BDIGIT_DBL_SIGNED long
453
+ # define PRI_BDIGIT_PREFIX "h"
454
+ # define PRI_BDIGIT_DBL_PREFIX "l"
455
+ # endif
456
+ #endif
457
+ #ifndef SIZEOF_ACTUAL_BDIGIT
458
+ # define SIZEOF_ACTUAL_BDIGIT SIZEOF_BDIGIT
459
+ #endif
460
+
461
+ #ifdef PRI_BDIGIT_PREFIX
462
+ # define PRIdBDIGIT PRI_BDIGIT_PREFIX"d"
463
+ # define PRIiBDIGIT PRI_BDIGIT_PREFIX"i"
464
+ # define PRIoBDIGIT PRI_BDIGIT_PREFIX"o"
465
+ # define PRIuBDIGIT PRI_BDIGIT_PREFIX"u"
466
+ # define PRIxBDIGIT PRI_BDIGIT_PREFIX"x"
467
+ # define PRIXBDIGIT PRI_BDIGIT_PREFIX"X"
468
+ #endif
469
+
470
+ #ifdef PRI_BDIGIT_DBL_PREFIX
471
+ # define PRIdBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"d"
472
+ # define PRIiBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"i"
473
+ # define PRIoBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"o"
474
+ # define PRIuBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"u"
475
+ # define PRIxBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"x"
476
+ # define PRIXBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"X"
477
+ #endif
478
+
479
+ #define BIGNUM_EMBED_LEN_NUMBITS 3
480
+ #ifndef BIGNUM_EMBED_LEN_MAX
481
+ # if (SIZEOF_VALUE*3/SIZEOF_ACTUAL_BDIGIT) < (1 << BIGNUM_EMBED_LEN_NUMBITS)-1
482
+ # define BIGNUM_EMBED_LEN_MAX (SIZEOF_VALUE*3/SIZEOF_ACTUAL_BDIGIT)
483
+ # else
484
+ # define BIGNUM_EMBED_LEN_MAX ((1 << BIGNUM_EMBED_LEN_NUMBITS)-1)
485
+ # endif
486
+ #endif
487
+
488
+ struct RBignum {
489
+ struct RBasic basic;
490
+ union {
491
+ struct {
492
+ size_t len;
493
+ BDIGIT *digits;
494
+ } heap;
495
+ BDIGIT ary[BIGNUM_EMBED_LEN_MAX];
496
+ } as;
497
+ };
498
+ #define BIGNUM_SIGN_BIT ((VALUE)FL_USER1)
499
+ /* sign: positive:1, negative:0 */
500
+ #define BIGNUM_SIGN(b) ((RBASIC(b)->flags & BIGNUM_SIGN_BIT) != 0)
501
+ #define BIGNUM_SET_SIGN(b,sign) \
502
+ ((sign) ? (RBASIC(b)->flags |= BIGNUM_SIGN_BIT) \
503
+ : (RBASIC(b)->flags &= ~BIGNUM_SIGN_BIT))
504
+ #define BIGNUM_POSITIVE_P(b) BIGNUM_SIGN(b)
505
+ #define BIGNUM_NEGATIVE_P(b) (!BIGNUM_SIGN(b))
506
+ #define BIGNUM_NEGATE(b) (RBASIC(b)->flags ^= BIGNUM_SIGN_BIT)
507
+
508
+ #define BIGNUM_EMBED_FLAG ((VALUE)FL_USER2)
509
+ #define BIGNUM_EMBED_LEN_MASK ((VALUE)(FL_USER5|FL_USER4|FL_USER3))
510
+ #define BIGNUM_EMBED_LEN_SHIFT (FL_USHIFT+BIGNUM_EMBED_LEN_NUMBITS)
511
+ #define BIGNUM_LEN(b) \
512
+ ((RBASIC(b)->flags & BIGNUM_EMBED_FLAG) ? \
513
+ (size_t)((RBASIC(b)->flags >> BIGNUM_EMBED_LEN_SHIFT) & \
514
+ (BIGNUM_EMBED_LEN_MASK >> BIGNUM_EMBED_LEN_SHIFT)) : \
515
+ RBIGNUM(b)->as.heap.len)
516
+ /* LSB:BIGNUM_DIGITS(b)[0], MSB:BIGNUM_DIGITS(b)[BIGNUM_LEN(b)-1] */
517
+ #define BIGNUM_DIGITS(b) \
518
+ ((RBASIC(b)->flags & BIGNUM_EMBED_FLAG) ? \
519
+ RBIGNUM(b)->as.ary : \
520
+ RBIGNUM(b)->as.heap.digits)
521
+ #define BIGNUM_LENINT(b) rb_long2int(BIGNUM_LEN(b))
522
+
523
+ #define RBIGNUM(obj) (R_CAST(RBignum)(obj))
524
+
525
+ struct RRational {
526
+ struct RBasic basic;
527
+ const VALUE num;
528
+ const VALUE den;
529
+ };
530
+
531
+ #define RRATIONAL(obj) (R_CAST(RRational)(obj))
532
+ #define RRATIONAL_SET_NUM(rat, n) RB_OBJ_WRITE((rat), &((struct RRational *)(rat))->num,(n))
533
+ #define RRATIONAL_SET_DEN(rat, d) RB_OBJ_WRITE((rat), &((struct RRational *)(rat))->den,(d))
534
+
535
+ struct RFloat {
536
+ struct RBasic basic;
537
+ double float_value;
538
+ };
539
+
540
+ #define RFLOAT(obj) (R_CAST(RFloat)(obj))
541
+
542
+ struct RComplex {
543
+ struct RBasic basic;
544
+ const VALUE real;
545
+ const VALUE imag;
546
+ };
547
+
548
+ #define RCOMPLEX(obj) (R_CAST(RComplex)(obj))
549
+
550
+ #ifdef RCOMPLEX_SET_REAL /* shortcut macro for internal only */
551
+ #undef RCOMPLEX_SET_REAL
552
+ #undef RCOMPLEX_SET_IMAG
553
+ #define RCOMPLEX_SET_REAL(cmp, r) RB_OBJ_WRITE((cmp), &((struct RComplex *)(cmp))->real,(r))
554
+ #define RCOMPLEX_SET_IMAG(cmp, i) RB_OBJ_WRITE((cmp), &((struct RComplex *)(cmp))->imag,(i))
555
+ #endif
556
+
557
+ struct RHash {
558
+ struct RBasic basic;
559
+ struct st_table *ntbl; /* possibly 0 */
560
+ int iter_lev;
561
+ const VALUE ifnone;
562
+ };
563
+
564
+ #define RHASH(obj) (R_CAST(RHash)(obj))
565
+
566
+ #ifdef RHASH_ITER_LEV
567
+ #undef RHASH_ITER_LEV
568
+ #undef RHASH_IFNONE
569
+ #undef RHASH_SIZE
570
+ #define RHASH_ITER_LEV(h) (RHASH(h)->iter_lev)
571
+ #define RHASH_IFNONE(h) (RHASH(h)->ifnone)
572
+ #define RHASH_SIZE(h) (RHASH(h)->ntbl ? RHASH(h)->ntbl->num_entries : (st_index_t)0)
573
+ #endif
574
+
575
+ /* missing/setproctitle.c */
576
+ #ifndef HAVE_SETPROCTITLE
577
+ extern void ruby_init_setproctitle(int argc, char *argv[]);
578
+ #endif
579
+
580
+ #define RSTRUCT_EMBED_LEN_MAX RSTRUCT_EMBED_LEN_MAX
581
+ #define RSTRUCT_EMBED_LEN_MASK RSTRUCT_EMBED_LEN_MASK
582
+ #define RSTRUCT_EMBED_LEN_SHIFT RSTRUCT_EMBED_LEN_SHIFT
583
+ enum {
584
+ RSTRUCT_EMBED_LEN_MAX = 3,
585
+ RSTRUCT_EMBED_LEN_MASK = (RUBY_FL_USER2|RUBY_FL_USER1),
586
+ RSTRUCT_EMBED_LEN_SHIFT = (RUBY_FL_USHIFT+1),
587
+
588
+ RSTRUCT_ENUM_END
589
+ };
590
+
591
+ struct RStruct {
592
+ struct RBasic basic;
593
+ union {
594
+ struct {
595
+ long len;
596
+ const VALUE *ptr;
597
+ } heap;
598
+ const VALUE ary[RSTRUCT_EMBED_LEN_MAX];
599
+ } as;
600
+ };
601
+
602
+ #undef RSTRUCT_LEN
603
+ #undef RSTRUCT_PTR
604
+ #undef RSTRUCT_SET
605
+ #undef RSTRUCT_GET
606
+ #define RSTRUCT_EMBED_LEN(st) \
607
+ (long)((RBASIC(st)->flags >> RSTRUCT_EMBED_LEN_SHIFT) & \
608
+ (RSTRUCT_EMBED_LEN_MASK >> RSTRUCT_EMBED_LEN_SHIFT))
609
+ #define RSTRUCT_LEN(st) rb_struct_len(st)
610
+ #define RSTRUCT_LENINT(st) rb_long2int(RSTRUCT_LEN(st))
611
+ #define RSTRUCT_CONST_PTR(st) rb_struct_const_ptr(st)
612
+ #define RSTRUCT_PTR(st) ((VALUE *)RSTRUCT_CONST_PTR(RB_OBJ_WB_UNPROTECT_FOR(STRUCT, st)))
613
+ #define RSTRUCT_SET(st, idx, v) RB_OBJ_WRITE(st, &RSTRUCT_CONST_PTR(st)[idx], (v))
614
+ #define RSTRUCT_GET(st, idx) (RSTRUCT_CONST_PTR(st)[idx])
615
+ #define RSTRUCT(obj) (R_CAST(RStruct)(obj))
616
+
617
+ static inline long
618
+ rb_struct_len(VALUE st)
619
+ {
620
+ return (RBASIC(st)->flags & RSTRUCT_EMBED_LEN_MASK) ?
621
+ RSTRUCT_EMBED_LEN(st) : RSTRUCT(st)->as.heap.len;
622
+ }
623
+
624
+ static inline const VALUE *
625
+ rb_struct_const_ptr(VALUE st)
626
+ {
627
+ return FIX_CONST_VALUE_PTR((RBASIC(st)->flags & RSTRUCT_EMBED_LEN_MASK) ?
628
+ RSTRUCT(st)->as.ary : RSTRUCT(st)->as.heap.ptr);
629
+ }
630
+
631
+ /* class.c */
632
+
633
+ struct rb_deprecated_classext_struct {
634
+ char conflict[sizeof(VALUE) * 3];
635
+ };
636
+
637
+ struct rb_subclass_entry;
638
+ typedef struct rb_subclass_entry rb_subclass_entry_t;
639
+
640
+ struct rb_subclass_entry {
641
+ VALUE klass;
642
+ rb_subclass_entry_t *next;
643
+ };
644
+
645
+ #if defined(HAVE_LONG_LONG)
646
+ typedef unsigned LONG_LONG rb_serial_t;
647
+ #define SERIALT2NUM ULL2NUM
648
+ #elif defined(HAVE_UINT64_T)
649
+ typedef uint64_t rb_serial_t;
650
+ #define SERIALT2NUM SIZET2NUM
651
+ #else
652
+ typedef unsigned long rb_serial_t;
653
+ #define SERIALT2NUM ULONG2NUM
654
+ #endif
655
+
656
+ struct rb_classext_struct {
657
+ struct st_table *iv_index_tbl;
658
+ struct st_table *iv_tbl;
659
+ struct rb_id_table *const_tbl;
660
+ struct rb_id_table *callable_m_tbl;
661
+ rb_subclass_entry_t *subclasses;
662
+ rb_subclass_entry_t **parent_subclasses;
663
+ /**
664
+ * In the case that this is an `ICLASS`, `module_subclasses` points to the link
665
+ * in the module's `subclasses` list that indicates that the klass has been
666
+ * included. Hopefully that makes sense.
667
+ */
668
+ rb_subclass_entry_t **module_subclasses;
669
+ rb_serial_t class_serial;
670
+ const VALUE origin_;
671
+ VALUE refined_class;
672
+ rb_alloc_func_t allocator;
673
+ };
674
+
675
+ typedef struct rb_classext_struct rb_classext_t;
676
+
677
+ #undef RClass
678
+ struct RClass {
679
+ struct RBasic basic;
680
+ VALUE super;
681
+ rb_classext_t *ptr;
682
+ struct rb_id_table *m_tbl;
683
+ };
684
+
685
+ void rb_class_subclass_add(VALUE super, VALUE klass);
686
+ void rb_class_remove_from_super_subclasses(VALUE);
687
+ int rb_singleton_class_internal_p(VALUE sklass);
688
+
689
+ #define RCLASS_EXT(c) (RCLASS(c)->ptr)
690
+ #define RCLASS_IV_TBL(c) (RCLASS_EXT(c)->iv_tbl)
691
+ #define RCLASS_CONST_TBL(c) (RCLASS_EXT(c)->const_tbl)
692
+ #define RCLASS_M_TBL(c) (RCLASS(c)->m_tbl)
693
+ #define RCLASS_CALLABLE_M_TBL(c) (RCLASS_EXT(c)->callable_m_tbl)
694
+ #define RCLASS_IV_INDEX_TBL(c) (RCLASS_EXT(c)->iv_index_tbl)
695
+ #define RCLASS_ORIGIN(c) (RCLASS_EXT(c)->origin_)
696
+ #define RCLASS_REFINED_CLASS(c) (RCLASS_EXT(c)->refined_class)
697
+ #define RCLASS_SERIAL(c) (RCLASS_EXT(c)->class_serial)
698
+
699
+ #define RICLASS_IS_ORIGIN FL_USER5
700
+
701
+ static inline void
702
+ RCLASS_SET_ORIGIN(VALUE klass, VALUE origin)
703
+ {
704
+ RB_OBJ_WRITE(klass, &RCLASS_ORIGIN(klass), origin);
705
+ if (klass != origin) FL_SET(origin, RICLASS_IS_ORIGIN);
706
+ }
707
+
708
+ #undef RCLASS_SUPER
709
+ static inline VALUE
710
+ RCLASS_SUPER(VALUE klass)
711
+ {
712
+ return RCLASS(klass)->super;
713
+ }
714
+
715
+ static inline VALUE
716
+ RCLASS_SET_SUPER(VALUE klass, VALUE super)
717
+ {
718
+ if (super) {
719
+ rb_class_remove_from_super_subclasses(klass);
720
+ rb_class_subclass_add(super, klass);
721
+ }
722
+ RB_OBJ_WRITE(klass, &RCLASS(klass)->super, super);
723
+ return super;
724
+ }
725
+ /* IMEMO: Internal memo object */
726
+
727
+ #ifndef IMEMO_DEBUG
728
+ #define IMEMO_DEBUG 0
729
+ #endif
730
+
731
+ struct RIMemo {
732
+ VALUE flags;
733
+ VALUE v0;
734
+ VALUE v1;
735
+ VALUE v2;
736
+ VALUE v3;
737
+ };
738
+
739
+ enum imemo_type {
740
+ imemo_env = 0,
741
+ imemo_cref = 1,
742
+ imemo_svar = 2,
743
+ imemo_throw_data = 3,
744
+ imemo_ifunc = 4,
745
+ imemo_memo = 5,
746
+ imemo_ment = 6,
747
+ imemo_iseq = 7,
748
+ imemo_mask = 0x07
749
+ };
750
+
751
+ static inline enum imemo_type
752
+ imemo_type(VALUE imemo)
753
+ {
754
+ return (RBASIC(imemo)->flags >> FL_USHIFT) & imemo_mask;
755
+ }
756
+
757
+ /* FL_USER0 to FL_USER2 is for type */
758
+ #define IMEMO_FL_USHIFT (FL_USHIFT + 3)
759
+ #define IMEMO_FL_USER0 FL_USER3
760
+ #define IMEMO_FL_USER1 FL_USER4
761
+ #define IMEMO_FL_USER2 FL_USER5
762
+ #define IMEMO_FL_USER3 FL_USER6
763
+ #define IMEMO_FL_USER4 FL_USER7
764
+
765
+ /* CREF in method.h */
766
+
767
+ /* SVAR */
768
+
769
+ struct vm_svar {
770
+ VALUE flags;
771
+ const VALUE cref_or_me;
772
+ const VALUE lastline;
773
+ const VALUE backref;
774
+ const VALUE others;
775
+ };
776
+
777
+ /* THROW_DATA */
778
+
779
+ struct vm_throw_data {
780
+ VALUE flags;
781
+ VALUE reserved;
782
+ const VALUE throw_obj;
783
+ const struct rb_control_frame_struct *catch_frame;
784
+ VALUE throw_state;
785
+ };
786
+
787
+ #define THROW_DATA_P(err) RB_TYPE_P((err), T_IMEMO)
788
+
789
+ /* IFUNC */
790
+
791
+ struct vm_ifunc {
792
+ VALUE flags;
793
+ VALUE reserved;
794
+ VALUE (*func)(ANYARGS);
795
+ const void *data;
796
+ ID id;
797
+ };
798
+
799
+ #define IFUNC_NEW(a, b, c) ((struct vm_ifunc *)rb_imemo_new(imemo_ifunc, (VALUE)(a), (VALUE)(b), (VALUE)(c), 0))
800
+
801
+ /* MEMO */
802
+
803
+ struct MEMO {
804
+ VALUE flags;
805
+ VALUE reserved;
806
+ const VALUE v1;
807
+ const VALUE v2;
808
+ union {
809
+ long cnt;
810
+ long state;
811
+ const VALUE value;
812
+ VALUE (*func)(ANYARGS);
813
+ } u3;
814
+ };
815
+
816
+ #define MEMO_V1_SET(m, v) RB_OBJ_WRITE((m), &(m)->v1, (v))
817
+ #define MEMO_V2_SET(m, v) RB_OBJ_WRITE((m), &(m)->v2, (v))
818
+
819
+ #define MEMO_CAST(m) ((struct MEMO *)m)
820
+
821
+ #define MEMO_NEW(a, b, c) ((struct MEMO *)rb_imemo_new(imemo_memo, (VALUE)(a), (VALUE)(b), (VALUE)(c), 0))
822
+
823
+ #define roomof(x, y) (((x) + (y) - 1) / (y))
824
+ #define type_roomof(x, y) roomof(sizeof(x), sizeof(y))
825
+ #define MEMO_FOR(type, value) ((type *)RARRAY_PTR(value))
826
+ #define NEW_MEMO_FOR(type, value) \
827
+ ((value) = rb_ary_tmp_new_fill(type_roomof(type, VALUE)), MEMO_FOR(type, value))
828
+ #define NEW_PARTIAL_MEMO_FOR(type, value, member) \
829
+ ((value) = rb_ary_tmp_new_fill(type_roomof(type, VALUE)), \
830
+ rb_ary_set_len((value), offsetof(type, member) / sizeof(VALUE)), \
831
+ MEMO_FOR(type, value))
832
+
833
+ #define STRING_P(s) (RB_TYPE_P((s), T_STRING) && CLASS_OF(s) == rb_cString)
834
+
835
+ #ifdef RUBY_INTEGER_UNIFICATION
836
+ # define rb_cFixnum rb_cInteger
837
+ # define rb_cBignum rb_cInteger
838
+ #endif
839
+
840
+ enum {
841
+ cmp_opt_Fixnum,
842
+ cmp_opt_String,
843
+ cmp_optimizable_count
844
+ };
845
+
846
+ struct cmp_opt_data {
847
+ unsigned int opt_methods;
848
+ unsigned int opt_inited;
849
+ };
850
+
851
+ #define NEW_CMP_OPT_MEMO(type, value) \
852
+ NEW_PARTIAL_MEMO_FOR(type, value, cmp_opt)
853
+ #define CMP_OPTIMIZABLE_BIT(type) (1U << TOKEN_PASTE(cmp_opt_,type))
854
+ #define CMP_OPTIMIZABLE(data, type) \
855
+ (((data).opt_inited & CMP_OPTIMIZABLE_BIT(type)) ? \
856
+ ((data).opt_methods & CMP_OPTIMIZABLE_BIT(type)) : \
857
+ (((data).opt_inited |= CMP_OPTIMIZABLE_BIT(type)), \
858
+ rb_method_basic_definition_p(TOKEN_PASTE(rb_c,type), id_cmp) && \
859
+ ((data).opt_methods |= CMP_OPTIMIZABLE_BIT(type))))
860
+
861
+ #define OPTIMIZED_CMP(a, b, data) \
862
+ ((FIXNUM_P(a) && FIXNUM_P(b) && CMP_OPTIMIZABLE(data, Fixnum)) ? \
863
+ (((long)a > (long)b) ? 1 : ((long)a < (long)b) ? -1 : 0) : \
864
+ (STRING_P(a) && STRING_P(b) && CMP_OPTIMIZABLE(data, String)) ? \
865
+ rb_str_cmp(a, b) : \
866
+ rb_cmpint(rb_funcallv(a, id_cmp, 1, &b), a, b))
867
+
868
+ /* ment is in method.h */
869
+
870
+ /* global variable */
871
+
872
+ struct rb_global_entry {
873
+ struct rb_global_variable *var;
874
+ ID id;
875
+ };
876
+
877
+ struct rb_global_entry *rb_global_entry(ID);
878
+ VALUE rb_gvar_get(struct rb_global_entry *);
879
+ VALUE rb_gvar_set(struct rb_global_entry *, VALUE);
880
+ VALUE rb_gvar_defined(struct rb_global_entry *);
881
+
882
+ struct vtm; /* defined by timev.h */
883
+
884
+ /* array.c */
885
+ VALUE rb_ary_last(int, const VALUE *, VALUE);
886
+ void rb_ary_set_len(VALUE, long);
887
+ void rb_ary_delete_same(VALUE, VALUE);
888
+ VALUE rb_ary_tmp_new_fill(long capa);
889
+ VALUE rb_ary_at(VALUE, VALUE);
890
+ size_t rb_ary_memsize(VALUE);
891
+ #ifdef __GNUC__
892
+ #define rb_ary_new_from_args(n, ...) \
893
+ __extension__ ({ \
894
+ const VALUE args_to_new_ary[] = {__VA_ARGS__}; \
895
+ if (__builtin_constant_p(n)) { \
896
+ STATIC_ASSERT(rb_ary_new_from_args, numberof(args_to_new_ary) == (n)); \
897
+ } \
898
+ rb_ary_new_from_values(numberof(args_to_new_ary), args_to_new_ary); \
899
+ })
900
+ #endif
901
+
902
+ /* bignum.c */
903
+ extern const char ruby_digitmap[];
904
+ double rb_big_fdiv_double(VALUE x, VALUE y);
905
+ VALUE rb_big_uminus(VALUE x);
906
+ VALUE rb_big_hash(VALUE);
907
+ VALUE rb_big_odd_p(VALUE);
908
+ VALUE rb_big_even_p(VALUE);
909
+ size_t rb_big_size(VALUE);
910
+ VALUE rb_integer_float_cmp(VALUE x, VALUE y);
911
+ VALUE rb_integer_float_eq(VALUE x, VALUE y);
912
+ VALUE rb_cstr_parse_inum(const char *str, ssize_t len, char **endp, int base);
913
+ VALUE rb_big_comp(VALUE x);
914
+ VALUE rb_big_aref(VALUE x, VALUE y);
915
+ VALUE rb_big_abs(VALUE x);
916
+ VALUE rb_big_size_m(VALUE big);
917
+ VALUE rb_big_bit_length(VALUE big);
918
+ VALUE rb_big_remainder(VALUE x, VALUE y);
919
+ VALUE rb_big_gt(VALUE x, VALUE y);
920
+ VALUE rb_big_ge(VALUE x, VALUE y);
921
+ VALUE rb_big_lt(VALUE x, VALUE y);
922
+ VALUE rb_big_le(VALUE x, VALUE y);
923
+
924
+ /* class.c */
925
+ VALUE rb_class_boot(VALUE);
926
+ VALUE rb_class_inherited(VALUE, VALUE);
927
+ VALUE rb_make_metaclass(VALUE, VALUE);
928
+ VALUE rb_include_class_new(VALUE, VALUE);
929
+ void rb_class_foreach_subclass(VALUE klass, void (*f)(VALUE, VALUE), VALUE);
930
+ void rb_class_detach_subclasses(VALUE);
931
+ void rb_class_detach_module_subclasses(VALUE);
932
+ void rb_class_remove_from_module_subclasses(VALUE);
933
+ VALUE rb_obj_methods(int argc, const VALUE *argv, VALUE obj);
934
+ VALUE rb_obj_protected_methods(int argc, const VALUE *argv, VALUE obj);
935
+ VALUE rb_obj_private_methods(int argc, const VALUE *argv, VALUE obj);
936
+ VALUE rb_obj_public_methods(int argc, const VALUE *argv, VALUE obj);
937
+ int rb_obj_basic_to_s_p(VALUE);
938
+ VALUE rb_special_singleton_class(VALUE);
939
+ VALUE rb_singleton_class_clone_and_attach(VALUE obj, VALUE attach);
940
+ VALUE rb_singleton_class_get(VALUE obj);
941
+ void Init_class_hierarchy(void);
942
+
943
+ int rb_class_has_methods(VALUE c);
944
+ void rb_undef_methods_from(VALUE klass, VALUE super);
945
+
946
+ /* compar.c */
947
+ VALUE rb_invcmp(VALUE, VALUE);
948
+
949
+ /* compile.c */
950
+ struct rb_block;
951
+ int rb_dvar_defined(ID, const struct rb_block *);
952
+ int rb_local_defined(ID, const struct rb_block *);
953
+ CONSTFUNC(const char * rb_insns_name(int i));
954
+ VALUE rb_insns_name_array(void);
955
+
956
+ /* complex.c */
957
+ VALUE rb_complex_plus(VALUE, VALUE);
958
+ VALUE rb_complex_mul(VALUE, VALUE);
959
+ VALUE rb_complex_abs(VALUE x);
960
+ VALUE rb_complex_sqrt(VALUE x);
961
+
962
+ /* cont.c */
963
+ VALUE rb_obj_is_fiber(VALUE);
964
+ void rb_fiber_reset_root_local_storage(VALUE);
965
+ void ruby_register_rollback_func_for_ensure(VALUE (*ensure_func)(ANYARGS), VALUE (*rollback_func)(ANYARGS));
966
+
967
+ /* debug.c */
968
+ PRINTF_ARGS(void ruby_debug_printf(const char*, ...), 1, 2);
969
+
970
+ /* dmyext.c */
971
+ void Init_enc(void);
972
+ void Init_ext(void);
973
+
974
+ /* encoding.c */
975
+ ID rb_id_encoding(void);
976
+ CONSTFUNC(void rb_gc_mark_encodings(void));
977
+ rb_encoding *rb_enc_get_from_index(int index);
978
+ rb_encoding *rb_enc_check_str(VALUE str1, VALUE str2);
979
+ int rb_encdb_replicate(const char *alias, const char *orig);
980
+ int rb_encdb_alias(const char *alias, const char *orig);
981
+ int rb_encdb_dummy(const char *name);
982
+ void rb_encdb_declare(const char *name);
983
+ void rb_enc_set_base(const char *name, const char *orig);
984
+ int rb_enc_set_dummy(int index);
985
+ void rb_encdb_set_unicode(int index);
986
+ PUREFUNC(int rb_data_is_encoding(VALUE obj));
987
+
988
+ /* enum.c */
989
+ VALUE rb_f_send(int argc, VALUE *argv, VALUE recv);
990
+ VALUE rb_nmin_run(VALUE obj, VALUE num, int by, int rev, int ary);
991
+
992
+ /* error.c */
993
+ extern VALUE rb_eEAGAIN;
994
+ extern VALUE rb_eEWOULDBLOCK;
995
+ extern VALUE rb_eEINPROGRESS;
996
+ void rb_report_bug_valist(VALUE file, int line, const char *fmt, va_list args);
997
+ PRINTF_ARGS(void rb_compile_error_str(VALUE file, int line, void *enc, const char *fmt, ...), 4, 5);
998
+ VALUE rb_syntax_error_append(VALUE, VALUE, int, int, rb_encoding*, const char*, va_list);
999
+ VALUE rb_check_backtrace(VALUE);
1000
+ NORETURN(void rb_async_bug_errno(const char *,int));
1001
+ const char *rb_builtin_type_name(int t);
1002
+ const char *rb_builtin_class_name(VALUE x);
1003
+ PRINTF_ARGS(void rb_enc_warn(rb_encoding *enc, const char *fmt, ...), 2, 3);
1004
+ PRINTF_ARGS(void rb_enc_warning(rb_encoding *enc, const char *fmt, ...), 2, 3);
1005
+ PRINTF_ARGS(void rb_sys_enc_warning(rb_encoding *enc, const char *fmt, ...), 2, 3);
1006
+ VALUE rb_name_err_new(VALUE mesg, VALUE recv, VALUE method);
1007
+ #define rb_name_err_raise_str(mesg, recv, name) \
1008
+ rb_exc_raise(rb_name_err_new(mesg, recv, name))
1009
+ #define rb_name_err_raise(mesg, recv, name) \
1010
+ rb_name_err_raise_str(rb_fstring_cstr(mesg), (recv), (name))
1011
+ NORETURN(void ruby_only_for_internal_use(const char *));
1012
+ #define ONLY_FOR_INTERNAL_USE(func) ruby_only_for_internal_use(func)
1013
+
1014
+ /* eval.c */
1015
+ VALUE rb_refinement_module_get_refined_class(VALUE module);
1016
+
1017
+ /* eval_error.c */
1018
+ void ruby_error_print(void);
1019
+ VALUE rb_get_backtrace(VALUE info);
1020
+
1021
+ /* eval_jump.c */
1022
+ void rb_call_end_proc(VALUE data);
1023
+ void rb_mark_end_proc(void);
1024
+
1025
+ /* file.c */
1026
+ VALUE rb_home_dir_of(VALUE user, VALUE result);
1027
+ VALUE rb_default_home_dir(VALUE result);
1028
+ VALUE rb_realpath_internal(VALUE basedir, VALUE path, int strict);
1029
+ void rb_file_const(const char*, VALUE);
1030
+ int rb_file_load_ok(const char *);
1031
+ VALUE rb_file_expand_path_fast(VALUE, VALUE);
1032
+ VALUE rb_file_expand_path_internal(VALUE, VALUE, int, int, VALUE);
1033
+ VALUE rb_get_path_check_to_string(VALUE, int);
1034
+ VALUE rb_get_path_check_convert(VALUE, VALUE, int);
1035
+ void Init_File(void);
1036
+ int ruby_is_fd_loadable(int fd);
1037
+
1038
+ #ifdef RUBY_FUNCTION_NAME_STRING
1039
+ # if defined __GNUC__ && __GNUC__ >= 4
1040
+ # pragma GCC visibility push(default)
1041
+ # endif
1042
+ NORETURN(void rb_sys_fail_path_in(const char *func_name, VALUE path));
1043
+ NORETURN(void rb_syserr_fail_path_in(const char *func_name, int err, VALUE path));
1044
+ # if defined __GNUC__ && __GNUC__ >= 4
1045
+ # pragma GCC visibility pop
1046
+ # endif
1047
+ # define rb_sys_fail_path(path) rb_sys_fail_path_in(RUBY_FUNCTION_NAME_STRING, path)
1048
+ # define rb_syserr_fail_path(err, path) rb_syserr_fail_path_in(RUBY_FUNCTION_NAME_STRING, (err), (path))
1049
+ #else
1050
+ # define rb_sys_fail_path(path) rb_sys_fail_str(path)
1051
+ # define rb_syserr_fail_path(err, path) rb_syserr_fail_str((err), (path))
1052
+ #endif
1053
+
1054
+ /* gc.c */
1055
+ extern VALUE *ruby_initial_gc_stress_ptr;
1056
+ extern int ruby_disable_gc;
1057
+ void Init_heap(void);
1058
+ void *ruby_mimmalloc(size_t size);
1059
+ void ruby_mimfree(void *ptr);
1060
+ void rb_objspace_set_event_hook(const rb_event_flag_t event);
1061
+ #if USE_RGENGC
1062
+ void rb_gc_writebarrier_remember(VALUE obj);
1063
+ #else
1064
+ #define rb_gc_writebarrier_remember(obj) 0
1065
+ #endif
1066
+ void ruby_gc_set_params(int safe_level);
1067
+ void rb_copy_wb_protected_attribute(VALUE dest, VALUE obj);
1068
+
1069
+ #if defined(HAVE_MALLOC_USABLE_SIZE) || defined(HAVE_MALLOC_SIZE) || defined(_WIN32)
1070
+ #define ruby_sized_xrealloc(ptr, new_size, old_size) ruby_xrealloc(ptr, new_size)
1071
+ #define ruby_sized_xrealloc2(ptr, new_count, element_size, old_count) ruby_xrealloc(ptr, new_count, element_size)
1072
+ #define ruby_sized_xfree(ptr, size) ruby_xfree(ptr)
1073
+ #define SIZED_REALLOC_N(var,type,n,old_n) REALLOC_N(var, type, n)
1074
+ #else
1075
+ void *ruby_sized_xrealloc(void *ptr, size_t new_size, size_t old_size) RUBY_ATTR_ALLOC_SIZE((2));
1076
+ void *ruby_sized_xrealloc2(void *ptr, size_t new_count, size_t element_size, size_t old_count) RUBY_ATTR_ALLOC_SIZE((2, 3));
1077
+ void ruby_sized_xfree(void *x, size_t size);
1078
+ #define SIZED_REALLOC_N(var,type,n,old_n) ((var)=(type*)ruby_sized_xrealloc((char*)(var), (n) * sizeof(type), (old_n) * sizeof(type)))
1079
+ #endif
1080
+
1081
+ void rb_gc_resurrect(VALUE ptr);
1082
+
1083
+ /* optimized version of NEWOBJ() */
1084
+ #undef NEWOBJF_OF
1085
+ #undef RB_NEWOBJ_OF
1086
+ #define RB_NEWOBJ_OF(obj,type,klass,flags) \
1087
+ type *(obj) = (type*)(((flags) & FL_WB_PROTECTED) ? \
1088
+ rb_wb_protected_newobj_of(klass, (flags) & ~FL_WB_PROTECTED) : \
1089
+ rb_wb_unprotected_newobj_of(klass, flags))
1090
+ #define NEWOBJ_OF(obj,type,klass,flags) RB_NEWOBJ_OF(obj,type,klass,flags)
1091
+
1092
+ /* hash.c */
1093
+ struct st_table *rb_hash_tbl_raw(VALUE hash);
1094
+ VALUE rb_hash_has_key(VALUE hash, VALUE key);
1095
+ VALUE rb_hash_default_value(VALUE hash, VALUE key);
1096
+ VALUE rb_hash_set_default_proc(VALUE hash, VALUE proc);
1097
+ long rb_objid_hash(st_index_t index);
1098
+ long rb_dbl_long_hash(double d);
1099
+ st_table *rb_init_identtable(void);
1100
+ st_table *rb_init_identtable_with_size(st_index_t size);
1101
+ VALUE rb_hash_compare_by_id_p(VALUE hash);
1102
+
1103
+ #define RHASH_TBL_RAW(h) rb_hash_tbl_raw(h)
1104
+ VALUE rb_hash_keys(VALUE hash);
1105
+ VALUE rb_hash_values(VALUE hash);
1106
+ VALUE rb_hash_rehash(VALUE hash);
1107
+ int rb_hash_add_new_element(VALUE hash, VALUE key, VALUE val);
1108
+ #define HASH_DELETED FL_USER1
1109
+ #define HASH_PROC_DEFAULT FL_USER2
1110
+
1111
+ /* inits.c */
1112
+ void rb_call_inits(void);
1113
+
1114
+ /* io.c */
1115
+ const char *ruby_get_inplace_mode(void);
1116
+ void ruby_set_inplace_mode(const char *);
1117
+ ssize_t rb_io_bufread(VALUE io, void *buf, size_t size);
1118
+ void rb_stdio_set_default_encoding(void);
1119
+ VALUE rb_io_flush_raw(VALUE, int);
1120
+ size_t rb_io_memsize(const rb_io_t *);
1121
+
1122
+ /* load.c */
1123
+ VALUE rb_get_load_path(void);
1124
+ VALUE rb_get_expanded_load_path(void);
1125
+ int rb_require_internal(VALUE fname, int safe);
1126
+ NORETURN(void rb_load_fail(VALUE, const char*));
1127
+
1128
+ /* loadpath.c */
1129
+ extern const char ruby_exec_prefix[];
1130
+ extern const char ruby_initial_load_paths[];
1131
+
1132
+ /* localeinit.c */
1133
+ int Init_enc_set_filesystem_encoding(void);
1134
+
1135
+ /* math.c */
1136
+ VALUE rb_math_atan2(VALUE, VALUE);
1137
+ VALUE rb_math_cos(VALUE);
1138
+ VALUE rb_math_cosh(VALUE);
1139
+ VALUE rb_math_exp(VALUE);
1140
+ VALUE rb_math_hypot(VALUE, VALUE);
1141
+ VALUE rb_math_log(int argc, const VALUE *argv);
1142
+ VALUE rb_math_sin(VALUE);
1143
+ VALUE rb_math_sinh(VALUE);
1144
+ VALUE rb_math_sqrt(VALUE);
1145
+
1146
+ /* newline.c */
1147
+ void Init_newline(void);
1148
+
1149
+ /* numeric.c */
1150
+
1151
+ #define FIXNUM_POSITIVE_P(num) ((SIGNED_VALUE)(num) > (SIGNED_VALUE)INT2FIX(0))
1152
+ #define FIXNUM_NEGATIVE_P(num) ((SIGNED_VALUE)(num) < 0)
1153
+ #define FIXNUM_ZERO_P(num) ((num) == INT2FIX(0))
1154
+
1155
+ #define INT_NEGATIVE_P(x) (FIXNUM_P(x) ? FIXNUM_NEGATIVE_P(x) : BIGNUM_NEGATIVE_P(x))
1156
+
1157
+ #ifndef ROUND_DEFAULT
1158
+ # define ROUND_DEFAULT RUBY_NUM_ROUND_HALF_UP
1159
+ #endif
1160
+ enum ruby_num_rounding_mode {
1161
+ RUBY_NUM_ROUND_HALF_UP,
1162
+ RUBY_NUM_ROUND_HALF_EVEN,
1163
+ RUBY_NUM_ROUND_HALF_DOWN,
1164
+ RUBY_NUM_ROUND_DEFAULT = ROUND_DEFAULT
1165
+ };
1166
+ #define ROUND_TO(mode, even, up, down) \
1167
+ ((mode) == RUBY_NUM_ROUND_HALF_EVEN ? even : \
1168
+ (mode) == RUBY_NUM_ROUND_HALF_UP ? up : down)
1169
+ #define ROUND_FUNC(mode, name) \
1170
+ ROUND_TO(mode, name##_half_even, name##_half_up, name##_half_down)
1171
+ #define ROUND_CALL(mode, name, args) \
1172
+ ROUND_TO(mode, name##_half_even args, \
1173
+ name##_half_up args, name##_half_down args)
1174
+
1175
+ int rb_num_to_uint(VALUE val, unsigned int *ret);
1176
+ VALUE ruby_num_interval_step_size(VALUE from, VALUE to, VALUE step, int excl);
1177
+ int ruby_float_step(VALUE from, VALUE to, VALUE step, int excl);
1178
+ double ruby_float_mod(double x, double y);
1179
+ int rb_num_negative_p(VALUE);
1180
+ VALUE rb_int_succ(VALUE num);
1181
+ VALUE rb_int_pred(VALUE num);
1182
+ VALUE rb_int_uminus(VALUE num);
1183
+ VALUE rb_float_uminus(VALUE num);
1184
+ VALUE rb_int_plus(VALUE x, VALUE y);
1185
+ VALUE rb_int_minus(VALUE x, VALUE y);
1186
+ VALUE rb_int_mul(VALUE x, VALUE y);
1187
+ VALUE rb_int_idiv(VALUE x, VALUE y);
1188
+ VALUE rb_int_modulo(VALUE x, VALUE y);
1189
+ VALUE rb_int_round(VALUE num, int ndigits, enum ruby_num_rounding_mode mode);
1190
+ VALUE rb_int2str(VALUE num, int base);
1191
+ VALUE rb_dbl_hash(double d);
1192
+ VALUE rb_fix_plus(VALUE x, VALUE y);
1193
+ VALUE rb_int_gt(VALUE x, VALUE y);
1194
+ VALUE rb_float_gt(VALUE x, VALUE y);
1195
+ VALUE rb_int_ge(VALUE x, VALUE y);
1196
+ enum ruby_num_rounding_mode rb_num_get_rounding_option(VALUE opts);
1197
+ double rb_int_fdiv_double(VALUE x, VALUE y);
1198
+ VALUE rb_int_pow(VALUE x, VALUE y);
1199
+ VALUE rb_float_pow(VALUE x, VALUE y);
1200
+ VALUE rb_int_cmp(VALUE x, VALUE y);
1201
+ VALUE rb_int_equal(VALUE x, VALUE y);
1202
+ VALUE rb_int_divmod(VALUE x, VALUE y);
1203
+ VALUE rb_int_and(VALUE x, VALUE y);
1204
+ VALUE rb_int_lshift(VALUE x, VALUE y);
1205
+ VALUE rb_int_div(VALUE x, VALUE y);
1206
+ VALUE rb_int_abs(VALUE num);
1207
+ VALUE rb_float_abs(VALUE flt);
1208
+
1209
+ #if USE_FLONUM
1210
+ #define RUBY_BIT_ROTL(v, n) (((v) << (n)) | ((v) >> ((sizeof(v) * 8) - n)))
1211
+ #define RUBY_BIT_ROTR(v, n) (((v) >> (n)) | ((v) << ((sizeof(v) * 8) - n)))
1212
+ #endif
1213
+
1214
+ static inline double
1215
+ rb_float_flonum_value(VALUE v)
1216
+ {
1217
+ #if USE_FLONUM
1218
+ if (v != (VALUE)0x8000000000000002) { /* LIKELY */
1219
+ union {
1220
+ double d;
1221
+ VALUE v;
1222
+ } t;
1223
+
1224
+ VALUE b63 = (v >> 63);
1225
+ /* e: xx1... -> 011... */
1226
+ /* xx0... -> 100... */
1227
+ /* ^b63 */
1228
+ t.v = RUBY_BIT_ROTR((2 - b63) | (v & ~(VALUE)0x03), 3);
1229
+ return t.d;
1230
+ }
1231
+ #endif
1232
+ return 0.0;
1233
+ }
1234
+
1235
+ static inline double
1236
+ rb_float_noflonum_value(VALUE v)
1237
+ {
1238
+ return ((struct RFloat *)v)->float_value;
1239
+ }
1240
+
1241
+ static inline double
1242
+ rb_float_value_inline(VALUE v)
1243
+ {
1244
+ if (FLONUM_P(v)) {
1245
+ return rb_float_flonum_value(v);
1246
+ }
1247
+ return rb_float_noflonum_value(v);
1248
+ }
1249
+
1250
+ static inline VALUE
1251
+ rb_float_new_inline(double d)
1252
+ {
1253
+ #if USE_FLONUM
1254
+ union {
1255
+ double d;
1256
+ VALUE v;
1257
+ } t;
1258
+ int bits;
1259
+
1260
+ t.d = d;
1261
+ bits = (int)((VALUE)(t.v >> 60) & 0x7);
1262
+ /* bits contains 3 bits of b62..b60. */
1263
+ /* bits - 3 = */
1264
+ /* b011 -> b000 */
1265
+ /* b100 -> b001 */
1266
+
1267
+ if (t.v != 0x3000000000000000 /* 1.72723e-77 */ &&
1268
+ !((bits-3) & ~0x01)) {
1269
+ return (RUBY_BIT_ROTL(t.v, 3) & ~(VALUE)0x01) | 0x02;
1270
+ }
1271
+ else if (t.v == (VALUE)0) {
1272
+ /* +0.0 */
1273
+ return 0x8000000000000002;
1274
+ }
1275
+ /* out of range */
1276
+ #endif
1277
+ return rb_float_new_in_heap(d);
1278
+ }
1279
+
1280
+ #define rb_float_value(v) rb_float_value_inline(v)
1281
+ #define rb_float_new(d) rb_float_new_inline(d)
1282
+
1283
+ /* object.c */
1284
+ void rb_obj_copy_ivar(VALUE dest, VALUE obj);
1285
+ CONSTFUNC(VALUE rb_obj_equal(VALUE obj1, VALUE obj2));
1286
+ CONSTFUNC(VALUE rb_obj_not(VALUE obj));
1287
+ VALUE rb_class_search_ancestor(VALUE klass, VALUE super);
1288
+ NORETURN(void rb_undefined_alloc(VALUE klass));
1289
+ double rb_num_to_dbl(VALUE val);
1290
+ VALUE rb_obj_dig(int argc, VALUE *argv, VALUE self, VALUE notfound);
1291
+
1292
+ struct RBasicRaw {
1293
+ VALUE flags;
1294
+ VALUE klass;
1295
+ };
1296
+
1297
+ #define RBASIC_CLEAR_CLASS(obj) memset(&(((struct RBasicRaw *)((VALUE)(obj)))->klass), 0, sizeof(VALUE))
1298
+ #define RBASIC_SET_CLASS_RAW(obj, cls) memcpy(&((struct RBasicRaw *)((VALUE)(obj)))->klass, &(cls), sizeof(VALUE))
1299
+ #define RBASIC_SET_CLASS(obj, cls) do { \
1300
+ VALUE _obj_ = (obj); \
1301
+ RB_OBJ_WRITE(_obj_, &((struct RBasicRaw *)(_obj_))->klass, cls); \
1302
+ } while (0)
1303
+
1304
+ /* parse.y */
1305
+ #ifndef USE_SYMBOL_GC
1306
+ #define USE_SYMBOL_GC 1
1307
+ #endif
1308
+ VALUE rb_parser_get_yydebug(VALUE);
1309
+ VALUE rb_parser_set_yydebug(VALUE, VALUE);
1310
+ VALUE rb_parser_set_context(VALUE, const struct rb_block *, int);
1311
+ void *rb_parser_load_file(VALUE parser, VALUE name);
1312
+ int rb_is_const_name(VALUE name);
1313
+ int rb_is_class_name(VALUE name);
1314
+ int rb_is_global_name(VALUE name);
1315
+ int rb_is_instance_name(VALUE name);
1316
+ int rb_is_attrset_name(VALUE name);
1317
+ int rb_is_local_name(VALUE name);
1318
+ int rb_is_method_name(VALUE name);
1319
+ int rb_is_junk_name(VALUE name);
1320
+ PUREFUNC(int rb_is_const_sym(VALUE sym));
1321
+ PUREFUNC(int rb_is_class_sym(VALUE sym));
1322
+ PUREFUNC(int rb_is_global_sym(VALUE sym));
1323
+ PUREFUNC(int rb_is_instance_sym(VALUE sym));
1324
+ PUREFUNC(int rb_is_attrset_sym(VALUE sym));
1325
+ PUREFUNC(int rb_is_local_sym(VALUE sym));
1326
+ PUREFUNC(int rb_is_method_sym(VALUE sym));
1327
+ PUREFUNC(int rb_is_junk_sym(VALUE sym));
1328
+ ID rb_make_internal_id(void);
1329
+ void rb_gc_free_dsymbol(VALUE);
1330
+ ID rb_id_attrget(ID id);
1331
+
1332
+ /* proc.c */
1333
+ VALUE rb_proc_location(VALUE self);
1334
+ st_index_t rb_hash_proc(st_index_t hash, VALUE proc);
1335
+ int rb_block_arity(void);
1336
+ VALUE rb_func_proc_new(rb_block_call_func_t func, VALUE val);
1337
+ VALUE rb_func_lambda_new(rb_block_call_func_t func, VALUE val);
1338
+
1339
+ /* process.c */
1340
+ #define RB_MAX_GROUPS (65536)
1341
+
1342
+ struct rb_execarg {
1343
+ union {
1344
+ struct {
1345
+ VALUE shell_script;
1346
+ } sh;
1347
+ struct {
1348
+ VALUE command_name;
1349
+ VALUE command_abspath; /* full path string or nil */
1350
+ VALUE argv_str;
1351
+ VALUE argv_buf;
1352
+ } cmd;
1353
+ } invoke;
1354
+ VALUE redirect_fds;
1355
+ VALUE envp_str;
1356
+ VALUE envp_buf;
1357
+ VALUE dup2_tmpbuf;
1358
+ unsigned use_shell : 1;
1359
+ unsigned pgroup_given : 1;
1360
+ unsigned umask_given : 1;
1361
+ unsigned unsetenv_others_given : 1;
1362
+ unsigned unsetenv_others_do : 1;
1363
+ unsigned close_others_given : 1;
1364
+ unsigned close_others_do : 1;
1365
+ unsigned chdir_given : 1;
1366
+ unsigned new_pgroup_given : 1;
1367
+ unsigned new_pgroup_flag : 1;
1368
+ unsigned uid_given : 1;
1369
+ unsigned gid_given : 1;
1370
+ rb_pid_t pgroup_pgid; /* asis(-1), new pgroup(0), specified pgroup (0<V). */
1371
+ VALUE rlimit_limits; /* Qfalse or [[rtype, softlim, hardlim], ...] */
1372
+ mode_t umask_mask;
1373
+ rb_uid_t uid;
1374
+ rb_gid_t gid;
1375
+ int close_others_maxhint;
1376
+ VALUE fd_dup2;
1377
+ VALUE fd_close;
1378
+ VALUE fd_open;
1379
+ VALUE fd_dup2_child;
1380
+ VALUE env_modification; /* Qfalse or [[k1,v1], ...] */
1381
+ VALUE path_env;
1382
+ VALUE chdir_dir;
1383
+ };
1384
+
1385
+ /* argv_str contains extra two elements.
1386
+ * The beginning one is for /bin/sh used by exec_with_sh.
1387
+ * The last one for terminating NULL used by execve.
1388
+ * See rb_exec_fillarg() in process.c. */
1389
+ #define ARGVSTR2ARGC(argv_str) (RSTRING_LEN(argv_str) / sizeof(char *) - 2)
1390
+ #define ARGVSTR2ARGV(argv_str) ((char **)RSTRING_PTR(argv_str) + 1)
1391
+
1392
+ rb_pid_t rb_fork_ruby(int *status);
1393
+ void rb_last_status_clear(void);
1394
+
1395
+ /* rational.c */
1396
+ VALUE rb_rational_uminus(VALUE self);
1397
+ VALUE rb_rational_plus(VALUE self, VALUE other);
1398
+ VALUE rb_lcm(VALUE x, VALUE y);
1399
+ VALUE rb_rational_reciprocal(VALUE x);
1400
+ VALUE rb_cstr_to_rat(const char *, int);
1401
+ VALUE rb_rational_abs(VALUE self);
1402
+ VALUE rb_rational_cmp(VALUE self, VALUE other);
1403
+
1404
+ /* re.c */
1405
+ VALUE rb_reg_compile(VALUE str, int options, const char *sourcefile, int sourceline);
1406
+ VALUE rb_reg_check_preprocess(VALUE);
1407
+ long rb_reg_search0(VALUE, VALUE, long, int, int);
1408
+ VALUE rb_reg_match_p(VALUE re, VALUE str, long pos);
1409
+ void rb_backref_set_string(VALUE string, long pos, long len);
1410
+ int rb_match_count(VALUE match);
1411
+ int rb_match_nth_defined(int nth, VALUE match);
1412
+
1413
+ /* signal.c */
1414
+ extern int ruby_enable_coredump;
1415
+ int rb_get_next_signal(void);
1416
+ int rb_sigaltstack_size(void);
1417
+
1418
+ /* strftime.c */
1419
+ #ifdef RUBY_ENCODING_H
1420
+ VALUE rb_strftime_timespec(const char *format, size_t format_len, rb_encoding *enc,
1421
+ const struct vtm *vtm, struct timespec *ts, int gmt);
1422
+ VALUE rb_strftime(const char *format, size_t format_len, rb_encoding *enc,
1423
+ const struct vtm *vtm, VALUE timev, int gmt);
1424
+ #endif
1425
+
1426
+ /* string.c */
1427
+ void Init_frozen_strings(void);
1428
+ VALUE rb_fstring(VALUE);
1429
+ VALUE rb_fstring_new(const char *ptr, long len);
1430
+ #define rb_fstring_lit(str) rb_fstring_new((str), rb_strlen_lit(str))
1431
+ #define rb_fstring_literal(str) rb_fstring_lit(str)
1432
+ VALUE rb_fstring_cstr(const char *str);
1433
+ #ifdef HAVE_BUILTIN___BUILTIN_CONSTANT_P
1434
+ # define rb_fstring_cstr(str) RB_GNUC_EXTENSION_BLOCK( \
1435
+ (__builtin_constant_p(str)) ? \
1436
+ rb_fstring_new((str), (long)strlen(str)) : \
1437
+ rb_fstring_cstr(str) \
1438
+ )
1439
+ #endif
1440
+ #ifdef RUBY_ENCODING_H
1441
+ VALUE rb_fstring_enc_new(const char *ptr, long len, rb_encoding *enc);
1442
+ #define rb_fstring_enc_lit(str, enc) rb_fstring_enc_new((str), rb_strlen_lit(str), (enc))
1443
+ #define rb_fstring_enc_literal(str, enc) rb_fstring_enc_lit(str, enc)
1444
+ VALUE rb_fstring_enc_cstr(const char *ptr, rb_encoding *enc);
1445
+ # ifdef HAVE_BUILTIN___BUILTIN_CONSTANT_P
1446
+ # define rb_fstring_enc_cstr(str, enc) RB_GNUC_EXTENSION_BLOCK( \
1447
+ (__builtin_constant_p(str)) ? \
1448
+ rb_fstring_enc_new((str), (long)strlen(str), (enc)) : \
1449
+ rb_fstring_enc_cstr(str, enc) \
1450
+ )
1451
+ # endif
1452
+ #endif
1453
+ int rb_str_buf_cat_escaped_char(VALUE result, unsigned int c, int unicode_p);
1454
+ int rb_str_symname_p(VALUE);
1455
+ VALUE rb_str_quote_unprintable(VALUE);
1456
+ VALUE rb_id_quote_unprintable(ID);
1457
+ #define QUOTE(str) rb_str_quote_unprintable(str)
1458
+ #define QUOTE_ID(id) rb_id_quote_unprintable(id)
1459
+ char *rb_str_fill_terminator(VALUE str, const int termlen);
1460
+ void rb_str_change_terminator_length(VALUE str, const int oldtermlen, const int termlen);
1461
+ VALUE rb_str_locktmp_ensure(VALUE str, VALUE (*func)(VALUE), VALUE arg);
1462
+ VALUE rb_str_tmp_frozen_acquire(VALUE str);
1463
+ void rb_str_tmp_frozen_release(VALUE str, VALUE tmp);
1464
+ VALUE rb_str_chomp_string(VALUE str, VALUE chomp);
1465
+ #ifdef RUBY_ENCODING_H
1466
+ VALUE rb_external_str_with_enc(VALUE str, rb_encoding *eenc);
1467
+ VALUE rb_str_cat_conv_enc_opts(VALUE newstr, long ofs, const char *ptr, long len,
1468
+ rb_encoding *from, int ecflags, VALUE ecopts);
1469
+ VALUE rb_enc_str_scrub(rb_encoding *enc, VALUE str, VALUE repl);
1470
+ #endif
1471
+ #define STR_NOEMBED FL_USER1
1472
+ #define STR_SHARED FL_USER2 /* = ELTS_SHARED */
1473
+ #define STR_EMBED_P(str) (!FL_TEST_RAW((str), STR_NOEMBED))
1474
+ #define STR_SHARED_P(s) FL_ALL_RAW((s), STR_NOEMBED|ELTS_SHARED)
1475
+ #define is_ascii_string(str) (rb_enc_str_coderange(str) == ENC_CODERANGE_7BIT)
1476
+ #define is_broken_string(str) (rb_enc_str_coderange(str) == ENC_CODERANGE_BROKEN)
1477
+ size_t rb_str_memsize(VALUE);
1478
+ VALUE rb_sym_proc_call(ID mid, int argc, const VALUE *argv, VALUE passed_proc);
1479
+ VALUE rb_sym_to_proc(VALUE sym);
1480
+
1481
+ /* symbol.c */
1482
+ #ifdef RUBY_ENCODING_H
1483
+ VALUE rb_sym_intern(const char *ptr, long len, rb_encoding *enc);
1484
+ VALUE rb_sym_intern_cstr(const char *ptr, rb_encoding *enc);
1485
+ #ifdef __GNUC__
1486
+ #define rb_sym_intern_cstr(ptr, enc) __extension__ ( \
1487
+ { \
1488
+ (__builtin_constant_p(ptr)) ? \
1489
+ rb_sym_intern((ptr), (long)strlen(ptr), (enc)) : \
1490
+ rb_sym_intern_cstr((ptr), (enc)); \
1491
+ })
1492
+ #endif
1493
+ #endif
1494
+ VALUE rb_sym_intern_ascii(const char *ptr, long len);
1495
+ VALUE rb_sym_intern_ascii_cstr(const char *ptr);
1496
+ #ifdef __GNUC__
1497
+ #define rb_sym_intern_ascii_cstr(ptr) __extension__ ( \
1498
+ { \
1499
+ (__builtin_constant_p(ptr)) ? \
1500
+ rb_sym_intern_ascii((ptr), (long)strlen(ptr)) : \
1501
+ rb_sym_intern_ascii_cstr(ptr); \
1502
+ })
1503
+ #endif
1504
+
1505
+ /* struct.c */
1506
+ VALUE rb_struct_init_copy(VALUE copy, VALUE s);
1507
+ VALUE rb_struct_lookup(VALUE s, VALUE idx);
1508
+
1509
+ /* time.c */
1510
+ struct timeval rb_time_timeval(VALUE);
1511
+
1512
+ /* thread.c */
1513
+ VALUE rb_obj_is_mutex(VALUE obj);
1514
+ VALUE rb_suppress_tracing(VALUE (*func)(VALUE), VALUE arg);
1515
+ void rb_thread_execute_interrupts(VALUE th);
1516
+ void rb_clear_trace_func(void);
1517
+ VALUE rb_get_coverages(void);
1518
+ VALUE rb_thread_shield_new(void);
1519
+ VALUE rb_thread_shield_wait(VALUE self);
1520
+ VALUE rb_thread_shield_release(VALUE self);
1521
+ VALUE rb_thread_shield_destroy(VALUE self);
1522
+ int rb_thread_to_be_killed(VALUE thread);
1523
+ void rb_mutex_allow_trap(VALUE self, int val);
1524
+ VALUE rb_uninterruptible(VALUE (*b_proc)(ANYARGS), VALUE data);
1525
+ VALUE rb_mutex_owned_p(VALUE self);
1526
+ void ruby_kill(rb_pid_t pid, int sig);
1527
+
1528
+ /* thread_pthread.c, thread_win32.c */
1529
+ void Init_native_thread(void);
1530
+ int rb_divert_reserved_fd(int fd);
1531
+
1532
+ /* transcode.c */
1533
+ extern VALUE rb_cEncodingConverter;
1534
+ size_t rb_econv_memsize(rb_econv_t *);
1535
+
1536
+ /* us_ascii.c */
1537
+ extern rb_encoding OnigEncodingUS_ASCII;
1538
+
1539
+ /* util.c */
1540
+ char *ruby_dtoa(double d_, int mode, int ndigits, int *decpt, int *sign, char **rve);
1541
+ char *ruby_hdtoa(double d, const char *xdigs, int ndigits, int *decpt, int *sign, char **rve);
1542
+
1543
+ /* utf_8.c */
1544
+ extern rb_encoding OnigEncodingUTF_8;
1545
+
1546
+ /* variable.c */
1547
+ void rb_gc_mark_global_tbl(void);
1548
+ size_t rb_generic_ivar_memsize(VALUE);
1549
+ VALUE rb_search_class_path(VALUE);
1550
+ VALUE rb_attr_delete(VALUE, ID);
1551
+ VALUE rb_ivar_lookup(VALUE obj, ID id, VALUE undef);
1552
+ void rb_autoload_str(VALUE mod, ID id, VALUE file);
1553
+ void rb_deprecate_constant(VALUE mod, const char *name);
1554
+
1555
+ /* version.c */
1556
+ extern const char ruby_engine[];
1557
+
1558
+ /* vm_insnhelper.h */
1559
+ rb_serial_t rb_next_class_serial(void);
1560
+
1561
+ /* vm.c */
1562
+ VALUE rb_obj_is_thread(VALUE obj);
1563
+ void rb_vm_mark(void *ptr);
1564
+ void Init_BareVM(void);
1565
+ void Init_vm_objects(void);
1566
+ PUREFUNC(VALUE rb_vm_top_self(void));
1567
+ void rb_thread_recycle_stack_release(VALUE *);
1568
+ void rb_vm_change_state(void);
1569
+ void rb_vm_inc_const_missing_count(void);
1570
+ void rb_thread_mark(void *th);
1571
+ RUBY_SYMBOL_EXPORT_BEGIN
1572
+ const void **rb_vm_get_insns_address_table(void);
1573
+ RUBY_SYMBOL_EXPORT_END
1574
+ VALUE rb_sourcefilename(void);
1575
+ VALUE rb_source_location(int *pline);
1576
+ const char *rb_source_loc(int *pline);
1577
+ void rb_vm_pop_cfunc_frame(void);
1578
+ int rb_vm_add_root_module(ID id, VALUE module);
1579
+ void rb_vm_check_redefinition_by_prepend(VALUE klass);
1580
+ VALUE rb_yield_refine_block(VALUE refinement, VALUE refinements);
1581
+ VALUE ruby_vm_special_exception_copy(VALUE);
1582
+ PUREFUNC(st_table *rb_vm_fstring_table(void));
1583
+
1584
+
1585
+ /* vm_dump.c */
1586
+ void rb_print_backtrace(void);
1587
+
1588
+ /* vm_eval.c */
1589
+ void Init_vm_eval(void);
1590
+ VALUE rb_current_realfilepath(void);
1591
+ VALUE rb_check_block_call(VALUE, ID, int, const VALUE *, rb_block_call_func_t, VALUE);
1592
+ typedef void rb_check_funcall_hook(int, VALUE, ID, int, const VALUE *, VALUE);
1593
+ VALUE rb_check_funcall_with_hook(VALUE recv, ID mid, int argc, const VALUE *argv,
1594
+ rb_check_funcall_hook *hook, VALUE arg);
1595
+ VALUE rb_check_funcall_default(VALUE, ID, int, const VALUE *, VALUE);
1596
+ VALUE rb_catch_protect(VALUE t, rb_block_call_func *func, VALUE data, int *stateptr);
1597
+ VALUE rb_yield_1(VALUE val);
1598
+ VALUE rb_yield_lambda(VALUE values);
1599
+
1600
+ /* vm_insnhelper.c */
1601
+ VALUE rb_equal_opt(VALUE obj1, VALUE obj2);
1602
+
1603
+ /* vm_method.c */
1604
+ void Init_eval_method(void);
1605
+ int rb_method_defined_by(VALUE obj, ID mid, VALUE (*cfunc)(ANYARGS));
1606
+
1607
+ /* miniprelude.c, prelude.c */
1608
+ void Init_prelude(void);
1609
+
1610
+ /* vm_backtrace.c */
1611
+ void Init_vm_backtrace(void);
1612
+ VALUE rb_vm_thread_backtrace(int argc, const VALUE *argv, VALUE thval);
1613
+ VALUE rb_vm_thread_backtrace_locations(int argc, const VALUE *argv, VALUE thval);
1614
+
1615
+ VALUE rb_make_backtrace(void);
1616
+ void rb_backtrace_print_as_bugreport(void);
1617
+ int rb_backtrace_p(VALUE obj);
1618
+ VALUE rb_backtrace_to_str_ary(VALUE obj);
1619
+ VALUE rb_backtrace_to_location_ary(VALUE obj);
1620
+ void rb_backtrace_print_to(VALUE output);
1621
+ VALUE rb_vm_backtrace_object(void);
1622
+
1623
+ RUBY_SYMBOL_EXPORT_BEGIN
1624
+ const char *rb_objspace_data_type_name(VALUE obj);
1625
+
1626
+ /* Temporary. This API will be removed (renamed). */
1627
+ VALUE rb_thread_io_blocking_region(rb_blocking_function_t *func, void *data1, int fd);
1628
+
1629
+ /* bignum.c (export) */
1630
+ VALUE rb_big_mul_normal(VALUE x, VALUE y);
1631
+ VALUE rb_big_mul_balance(VALUE x, VALUE y);
1632
+ VALUE rb_big_mul_karatsuba(VALUE x, VALUE y);
1633
+ VALUE rb_big_mul_toom3(VALUE x, VALUE y);
1634
+ VALUE rb_big_sq_fast(VALUE x);
1635
+ VALUE rb_big_divrem_normal(VALUE x, VALUE y);
1636
+ VALUE rb_big2str_poweroftwo(VALUE x, int base);
1637
+ VALUE rb_big2str_generic(VALUE x, int base);
1638
+ VALUE rb_str2big_poweroftwo(VALUE arg, int base, int badcheck);
1639
+ VALUE rb_str2big_normal(VALUE arg, int base, int badcheck);
1640
+ VALUE rb_str2big_karatsuba(VALUE arg, int base, int badcheck);
1641
+ #if defined(HAVE_LIBGMP) && defined(HAVE_GMP_H)
1642
+ VALUE rb_big_mul_gmp(VALUE x, VALUE y);
1643
+ VALUE rb_big_divrem_gmp(VALUE x, VALUE y);
1644
+ VALUE rb_big2str_gmp(VALUE x, int base);
1645
+ VALUE rb_str2big_gmp(VALUE arg, int base, int badcheck);
1646
+ #endif
1647
+
1648
+ /* error.c (export) */
1649
+ int rb_bug_reporter_add(void (*func)(FILE *, void *), void *data);
1650
+ NORETURN(void rb_unexpected_type(VALUE,int));
1651
+ #undef Check_Type
1652
+ #define Check_Type(v, t) \
1653
+ (!RB_TYPE_P((VALUE)(v), (t)) || \
1654
+ ((t) == RUBY_T_DATA && RTYPEDDATA_P(v)) ? \
1655
+ rb_unexpected_type((VALUE)(v), (t)) : (void)0)
1656
+
1657
+ /* file.c (export) */
1658
+ #ifdef HAVE_READLINK
1659
+ VALUE rb_readlink(VALUE path, rb_encoding *enc);
1660
+ #endif
1661
+ #ifdef __APPLE__
1662
+ VALUE rb_str_normalize_ospath(const char *ptr, long len);
1663
+ #endif
1664
+
1665
+ /* hash.c (export) */
1666
+ VALUE rb_hash_delete_entry(VALUE hash, VALUE key);
1667
+ VALUE rb_ident_hash_new(void);
1668
+
1669
+ /* io.c (export) */
1670
+ void rb_maygvl_fd_fix_cloexec(int fd);
1671
+ int rb_gc_for_fd(int err);
1672
+ void rb_write_error_str(VALUE mesg);
1673
+
1674
+ /* numeric.c (export) */
1675
+ VALUE rb_int_positive_pow(long x, unsigned long y);
1676
+
1677
+ /* process.c (export) */
1678
+ int rb_exec_async_signal_safe(const struct rb_execarg *e, char *errmsg, size_t errmsg_buflen);
1679
+ rb_pid_t rb_fork_async_signal_safe(int *status, int (*chfunc)(void*, char *, size_t), void *charg, VALUE fds, char *errmsg, size_t errmsg_buflen);
1680
+ VALUE rb_execarg_new(int argc, const VALUE *argv, int accept_shell);
1681
+ struct rb_execarg *rb_execarg_get(VALUE execarg_obj); /* dangerous. needs GC guard. */
1682
+ VALUE rb_execarg_init(int argc, const VALUE *argv, int accept_shell, VALUE execarg_obj);
1683
+ int rb_execarg_addopt(VALUE execarg_obj, VALUE key, VALUE val);
1684
+ void rb_execarg_parent_start(VALUE execarg_obj);
1685
+ void rb_execarg_parent_end(VALUE execarg_obj);
1686
+ int rb_execarg_run_options(const struct rb_execarg *e, struct rb_execarg *s, char* errmsg, size_t errmsg_buflen);
1687
+ VALUE rb_execarg_extract_options(VALUE execarg_obj, VALUE opthash);
1688
+ void rb_execarg_setenv(VALUE execarg_obj, VALUE env);
1689
+
1690
+ /* rational.c (export) */
1691
+ VALUE rb_gcd(VALUE x, VALUE y);
1692
+ VALUE rb_gcd_normal(VALUE self, VALUE other);
1693
+ #if defined(HAVE_LIBGMP) && defined(HAVE_GMP_H)
1694
+ VALUE rb_gcd_gmp(VALUE x, VALUE y);
1695
+ #endif
1696
+
1697
+ /* string.c (export) */
1698
+ #ifdef RUBY_ENCODING_H
1699
+ /* internal use */
1700
+ VALUE rb_setup_fake_str(struct RString *fake_str, const char *name, long len, rb_encoding *enc);
1701
+ #endif
1702
+
1703
+ /* thread.c (export) */
1704
+ int ruby_thread_has_gvl_p(void); /* for ext/fiddle/closure.c */
1705
+
1706
+ /* util.c (export) */
1707
+ extern const signed char ruby_digit36_to_number_table[];
1708
+ extern const char ruby_hexdigits[];
1709
+ extern unsigned long ruby_scan_digits(const char *str, ssize_t len, int base, size_t *retlen, int *overflow);
1710
+
1711
+ /* variable.c (export) */
1712
+ void rb_mark_generic_ivar(VALUE);
1713
+ VALUE rb_const_missing(VALUE klass, VALUE name);
1714
+ int rb_class_ivar_set(VALUE klass, ID vid, VALUE value);
1715
+ st_table *rb_st_copy(VALUE obj, struct st_table *orig_tbl);
1716
+
1717
+ /* gc.c (export) */
1718
+ VALUE rb_wb_protected_newobj_of(VALUE, VALUE);
1719
+ VALUE rb_wb_unprotected_newobj_of(VALUE, VALUE);
1720
+
1721
+ size_t rb_obj_memsize_of(VALUE);
1722
+ void rb_gc_verify_internal_consistency(void);
1723
+
1724
+ #define RB_OBJ_GC_FLAGS_MAX 5
1725
+ size_t rb_obj_gc_flags(VALUE, ID[], size_t);
1726
+ void rb_gc_mark_values(long n, const VALUE *values);
1727
+
1728
+ #if IMEMO_DEBUG
1729
+ VALUE rb_imemo_new_debug(enum imemo_type type, VALUE v1, VALUE v2, VALUE v3, VALUE v0, const char *file, int line);
1730
+ #define rb_imemo_new(type, v1, v2, v3, v0) rb_imemo_new_debug(type, v1, v2, v3, v0, __FILE__, __LINE__)
1731
+ #else
1732
+ VALUE rb_imemo_new(enum imemo_type type, VALUE v1, VALUE v2, VALUE v3, VALUE v0);
1733
+ #endif
1734
+
1735
+ RUBY_SYMBOL_EXPORT_END
1736
+
1737
+ #define RUBY_DTRACE_CREATE_HOOK(name, arg) \
1738
+ RUBY_DTRACE_HOOK(name##_CREATE, arg)
1739
+ #define RUBY_DTRACE_HOOK(name, arg) \
1740
+ do { \
1741
+ if (UNLIKELY(RUBY_DTRACE_##name##_ENABLED())) { \
1742
+ int dtrace_line; \
1743
+ const char *dtrace_file = rb_source_loc(&dtrace_line); \
1744
+ if (!dtrace_file) dtrace_file = ""; \
1745
+ RUBY_DTRACE_##name(arg, dtrace_file, dtrace_line); \
1746
+ } \
1747
+ } while (0)
1748
+
1749
+ #define RB_OBJ_BUILTIN_TYPE(obj) rb_obj_builtin_type(obj)
1750
+ #define OBJ_BUILTIN_TYPE(obj) RB_OBJ_BUILTIN_TYPE(obj)
1751
+ #ifdef __GNUC__
1752
+ #define rb_obj_builtin_type(obj) \
1753
+ __extension__({ \
1754
+ VALUE arg_obj = (obj); \
1755
+ RB_SPECIAL_CONST_P(arg_obj) ? -1 : \
1756
+ RB_BUILTIN_TYPE(arg_obj); \
1757
+ })
1758
+ #else
1759
+ static inline int
1760
+ rb_obj_builtin_type(VALUE obj)
1761
+ {
1762
+ return RB_SPECIAL_CONST_P(obj) ? -1 :
1763
+ RB_BUILTIN_TYPE(obj);
1764
+ }
1765
+ #endif
1766
+
1767
+ #if defined(__cplusplus)
1768
+ #if 0
1769
+ { /* satisfy cc-mode */
1770
+ #endif
1771
+ } /* extern "C" { */
1772
+ #endif
1773
+
1774
+ #endif /* RUBY_INTERNAL_H */