unmixer 0.1.0

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