zscan 2.0.4 → 2.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a03973730c36e6d060cb90d6289d1ffbf4487382
4
- data.tar.gz: fc7cfa3c9b2929436352610d9675b277f1d41fe1
2
+ SHA256:
3
+ metadata.gz: 1be51b6ecf31eddb1ac288b01afa7310073e4c628f70da82ebb27f9781f4aed2
4
+ data.tar.gz: 12309705effd8a214f450483d931c6ff312b2fcc89655f1c36caeb1a746f8543
5
5
  SHA512:
6
- metadata.gz: 4ea820c8109ee28d3f9b36b14b52806d3c92ca9d763e03eb778ee7117320c623b28344c850fbcc2f837b53b4e7668b8b115a7e7c107e5a2daec204b6f7aea36e
7
- data.tar.gz: 35935a34c3afe3d2574a1773f2a02b3906c70f572704535f0ae2b0bc4601b85f3772b237cb21fa31e47ba6a17d14f38a181eabb9db7725fefebd00ad3dab6a75
6
+ metadata.gz: 27a59bf9310081f6b5da2a9da83dfa4c1a9c1232c66aac2bf0eaaffb0cce7944dd5871ce56e6f16516edfcfa21c3d74b8a135312b800c4133eda3ca1fb0f587e
7
+ data.tar.gz: 0021552b20639b67f4663128cce02d8d208ea477de5fed7f56262ea28599219c51281c841da860328701e45141a51a4a157860099aa083202faecf9d62d0688f
@@ -9,7 +9,10 @@ create_makefile 'zscan'
9
9
 
10
10
  makefile = File.read 'Makefile'
11
11
 
12
- if RUBY_VERSION > '2.4'
12
+ if RUBY_VERSION >= '2.6'
13
+ FileUtils.cp "pack/internal-26.h", "pack/internal.h"
14
+ FileUtils.cp "pack/pack-26.c", "pack/pack.c"
15
+ elsif RUBY_VERSION > '2.4'
13
16
  FileUtils.cp "pack/internal-25.h", "pack/internal.h"
14
17
  FileUtils.cp "pack/pack-25.c", "pack/pack.c"
15
18
  else
@@ -0,0 +1,2141 @@
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
+
17
+ #if defined(__cplusplus)
18
+ extern "C" {
19
+ #if 0
20
+ } /* satisfy cc-mode */
21
+ #endif
22
+ #endif
23
+
24
+ #ifdef HAVE_STDBOOL_H
25
+ # include <stdbool.h>
26
+ #endif
27
+
28
+ #ifndef __bool_true_false_are_defined
29
+ # ifndef __cplusplus
30
+ # undef bool
31
+ # undef false
32
+ # undef true
33
+ # define bool signed char
34
+ # define false 0
35
+ # define true 1
36
+ # define __bool_true_false_are_defined 1
37
+ # endif
38
+ #endif
39
+
40
+ /* The most significant bit of the lower part of half-long integer.
41
+ * If sizeof(long) == 4, this is 0x8000.
42
+ * If sizeof(long) == 8, this is 0x80000000.
43
+ */
44
+ #define HALF_LONG_MSB ((SIGNED_VALUE)1<<((SIZEOF_LONG*CHAR_BIT-1)/2))
45
+
46
+ #define LIKELY(x) RB_LIKELY(x)
47
+ #define UNLIKELY(x) RB_UNLIKELY(x)
48
+
49
+ #ifndef MAYBE_UNUSED
50
+ # define MAYBE_UNUSED(x) x
51
+ #endif
52
+
53
+ #ifndef WARN_UNUSED_RESULT
54
+ # define WARN_UNUSED_RESULT(x) x
55
+ #endif
56
+
57
+ #ifdef HAVE_VALGRIND_MEMCHECK_H
58
+ # include <valgrind/memcheck.h>
59
+ # ifndef VALGRIND_MAKE_MEM_DEFINED
60
+ # define VALGRIND_MAKE_MEM_DEFINED(p, n) VALGRIND_MAKE_READABLE((p), (n))
61
+ # endif
62
+ # ifndef VALGRIND_MAKE_MEM_UNDEFINED
63
+ # define VALGRIND_MAKE_MEM_UNDEFINED(p, n) VALGRIND_MAKE_WRITABLE((p), (n))
64
+ # endif
65
+ #else
66
+ # define VALGRIND_MAKE_MEM_DEFINED(p, n) 0
67
+ # define VALGRIND_MAKE_MEM_UNDEFINED(p, n) 0
68
+ #endif
69
+
70
+ #define numberof(array) ((int)(sizeof(array) / sizeof((array)[0])))
71
+
72
+ #ifndef __has_feature
73
+ # define __has_feature(x) 0
74
+ #endif
75
+
76
+ #ifndef __has_extension
77
+ # define __has_extension __has_feature
78
+ #endif
79
+
80
+ #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
81
+ # define STATIC_ASSERT(name, expr) _Static_assert(expr, #name ": " #expr)
82
+ #elif GCC_VERSION_SINCE(4, 6, 0) || __has_extension(c_static_assert)
83
+ # define STATIC_ASSERT(name, expr) RB_GNUC_EXTENSION _Static_assert(expr, #name ": " #expr)
84
+ #else
85
+ # define STATIC_ASSERT(name, expr) typedef int static_assert_##name##_check[1 - 2*!(expr)]
86
+ #endif
87
+
88
+ #define SIGNED_INTEGER_TYPE_P(int_type) (0 > ((int_type)0)-1)
89
+ #define SIGNED_INTEGER_MAX(sint_type) \
90
+ (sint_type) \
91
+ ((((sint_type)1) << (sizeof(sint_type) * CHAR_BIT - 2)) | \
92
+ ((((sint_type)1) << (sizeof(sint_type) * CHAR_BIT - 2)) - 1))
93
+ #define SIGNED_INTEGER_MIN(sint_type) (-SIGNED_INTEGER_MAX(sint_type)-1)
94
+ #define UNSIGNED_INTEGER_MAX(uint_type) (~(uint_type)0)
95
+
96
+ #if SIGNEDNESS_OF_TIME_T < 0 /* signed */
97
+ # define TIMET_MAX SIGNED_INTEGER_MAX(time_t)
98
+ # define TIMET_MIN SIGNED_INTEGER_MIN(time_t)
99
+ #elif SIGNEDNESS_OF_TIME_T > 0 /* unsigned */
100
+ # define TIMET_MAX UNSIGNED_INTEGER_MAX(time_t)
101
+ # define TIMET_MIN ((time_t)0)
102
+ #endif
103
+ #define TIMET_MAX_PLUS_ONE (2*(double)(TIMET_MAX/2+1))
104
+
105
+ #ifdef HAVE_BUILTIN___BUILTIN_MUL_OVERFLOW_P
106
+ #define MUL_OVERFLOW_P(a, b) \
107
+ __builtin_mul_overflow_p((a), (b), (__typeof__(a * b))0)
108
+ #elif defined HAVE_BUILTIN___BUILTIN_MUL_OVERFLOW
109
+ #define MUL_OVERFLOW_P(a, b) \
110
+ RB_GNUC_EXTENSION_BLOCK(__typeof__(a) c; __builtin_mul_overflow((a), (b), &c))
111
+ #endif
112
+
113
+ #define MUL_OVERFLOW_SIGNED_INTEGER_P(a, b, min, max) ( \
114
+ (a) == 0 ? 0 : \
115
+ (a) == -1 ? (b) < -(max) : \
116
+ (a) > 0 ? \
117
+ ((b) > 0 ? (max) / (a) < (b) : (min) / (a) > (b)) : \
118
+ ((b) > 0 ? (min) / (a) < (b) : (max) / (a) > (b)))
119
+
120
+ #ifdef HAVE_BUILTIN___BUILTIN_MUL_OVERFLOW_P
121
+ /* __builtin_mul_overflow_p can take bitfield */
122
+ /* and GCC permits bitfields for integers other than int */
123
+ #define MUL_OVERFLOW_FIXNUM_P(a, b) RB_GNUC_EXTENSION_BLOCK( \
124
+ struct { long fixnum : SIZEOF_LONG * CHAR_BIT - 1; } c; \
125
+ __builtin_mul_overflow_p((a), (b), c.fixnum); \
126
+ )
127
+ #else
128
+ #define MUL_OVERFLOW_FIXNUM_P(a, b) MUL_OVERFLOW_SIGNED_INTEGER_P(a, b, FIXNUM_MIN, FIXNUM_MAX)
129
+ #endif
130
+
131
+ #ifdef MUL_OVERFLOW_P
132
+ #define MUL_OVERFLOW_LONG_LONG_P(a, b) MUL_OVERFLOW_P(a, b)
133
+ #define MUL_OVERFLOW_LONG_P(a, b) MUL_OVERFLOW_P(a, b)
134
+ #define MUL_OVERFLOW_INT_P(a, b) MUL_OVERFLOW_P(a, b)
135
+ #else
136
+ #define MUL_OVERFLOW_LONG_LONG_P(a, b) MUL_OVERFLOW_SIGNED_INTEGER_P(a, b, LLONG_MIN, LLONG_MAX)
137
+ #define MUL_OVERFLOW_LONG_P(a, b) MUL_OVERFLOW_SIGNED_INTEGER_P(a, b, LONG_MIN, LONG_MAX)
138
+ #define MUL_OVERFLOW_INT_P(a, b) MUL_OVERFLOW_SIGNED_INTEGER_P(a, b, INT_MIN, INT_MAX)
139
+ #endif
140
+
141
+ #ifndef swap16
142
+ # ifdef HAVE_BUILTIN___BUILTIN_BSWAP16
143
+ # define swap16(x) __builtin_bswap16(x)
144
+ # endif
145
+ #endif
146
+
147
+ #ifndef swap16
148
+ # define swap16(x) ((uint16_t)((((x)&0xFF)<<8) | (((x)>>8)&0xFF)))
149
+ #endif
150
+
151
+ #ifndef swap32
152
+ # ifdef HAVE_BUILTIN___BUILTIN_BSWAP32
153
+ # define swap32(x) __builtin_bswap32(x)
154
+ # endif
155
+ #endif
156
+
157
+ #ifndef swap32
158
+ # define swap32(x) ((uint32_t)((((x)&0xFF)<<24) \
159
+ |(((x)>>24)&0xFF) \
160
+ |(((x)&0x0000FF00)<<8) \
161
+ |(((x)&0x00FF0000)>>8) ))
162
+ #endif
163
+
164
+ #ifndef swap64
165
+ # ifdef HAVE_BUILTIN___BUILTIN_BSWAP64
166
+ # define swap64(x) __builtin_bswap64(x)
167
+ # endif
168
+ #endif
169
+
170
+ #ifndef swap64
171
+ # ifdef HAVE_INT64_T
172
+ # define byte_in_64bit(n) ((uint64_t)0xff << (n))
173
+ # define swap64(x) ((uint64_t)((((x)&byte_in_64bit(0))<<56) \
174
+ |(((x)>>56)&0xFF) \
175
+ |(((x)&byte_in_64bit(8))<<40) \
176
+ |(((x)&byte_in_64bit(48))>>40) \
177
+ |(((x)&byte_in_64bit(16))<<24) \
178
+ |(((x)&byte_in_64bit(40))>>24) \
179
+ |(((x)&byte_in_64bit(24))<<8) \
180
+ |(((x)&byte_in_64bit(32))>>8)))
181
+ # endif
182
+ #endif
183
+
184
+ static inline unsigned int
185
+ nlz_int(unsigned int x)
186
+ {
187
+ #if defined(HAVE_BUILTIN___BUILTIN_CLZ)
188
+ if (x == 0) return SIZEOF_INT * CHAR_BIT;
189
+ return (unsigned int)__builtin_clz(x);
190
+ #else
191
+ unsigned int y;
192
+ # if 64 < SIZEOF_INT * CHAR_BIT
193
+ unsigned int n = 128;
194
+ # elif 32 < SIZEOF_INT * CHAR_BIT
195
+ unsigned int n = 64;
196
+ # else
197
+ unsigned int n = 32;
198
+ # endif
199
+ # if 64 < SIZEOF_INT * CHAR_BIT
200
+ y = x >> 64; if (y) {n -= 64; x = y;}
201
+ # endif
202
+ # if 32 < SIZEOF_INT * CHAR_BIT
203
+ y = x >> 32; if (y) {n -= 32; x = y;}
204
+ # endif
205
+ y = x >> 16; if (y) {n -= 16; x = y;}
206
+ y = x >> 8; if (y) {n -= 8; x = y;}
207
+ y = x >> 4; if (y) {n -= 4; x = y;}
208
+ y = x >> 2; if (y) {n -= 2; x = y;}
209
+ y = x >> 1; if (y) {return n - 2;}
210
+ return (unsigned int)(n - x);
211
+ #endif
212
+ }
213
+
214
+ static inline unsigned int
215
+ nlz_long(unsigned long x)
216
+ {
217
+ #if defined(HAVE_BUILTIN___BUILTIN_CLZL)
218
+ if (x == 0) return SIZEOF_LONG * CHAR_BIT;
219
+ return (unsigned int)__builtin_clzl(x);
220
+ #else
221
+ unsigned long y;
222
+ # if 64 < SIZEOF_LONG * CHAR_BIT
223
+ unsigned int n = 128;
224
+ # elif 32 < SIZEOF_LONG * CHAR_BIT
225
+ unsigned int n = 64;
226
+ # else
227
+ unsigned int n = 32;
228
+ # endif
229
+ # if 64 < SIZEOF_LONG * CHAR_BIT
230
+ y = x >> 64; if (y) {n -= 64; x = y;}
231
+ # endif
232
+ # if 32 < SIZEOF_LONG * CHAR_BIT
233
+ y = x >> 32; if (y) {n -= 32; x = y;}
234
+ # endif
235
+ y = x >> 16; if (y) {n -= 16; x = y;}
236
+ y = x >> 8; if (y) {n -= 8; x = y;}
237
+ y = x >> 4; if (y) {n -= 4; x = y;}
238
+ y = x >> 2; if (y) {n -= 2; x = y;}
239
+ y = x >> 1; if (y) {return n - 2;}
240
+ return (unsigned int)(n - x);
241
+ #endif
242
+ }
243
+
244
+ #ifdef HAVE_LONG_LONG
245
+ static inline unsigned int
246
+ nlz_long_long(unsigned LONG_LONG x)
247
+ {
248
+ #if defined(HAVE_BUILTIN___BUILTIN_CLZLL)
249
+ if (x == 0) return SIZEOF_LONG_LONG * CHAR_BIT;
250
+ return (unsigned int)__builtin_clzll(x);
251
+ #else
252
+ unsigned LONG_LONG y;
253
+ # if 64 < SIZEOF_LONG_LONG * CHAR_BIT
254
+ unsigned int n = 128;
255
+ # elif 32 < SIZEOF_LONG_LONG * CHAR_BIT
256
+ unsigned int n = 64;
257
+ # else
258
+ unsigned int n = 32;
259
+ # endif
260
+ # if 64 < SIZEOF_LONG_LONG * CHAR_BIT
261
+ y = x >> 64; if (y) {n -= 64; x = y;}
262
+ # endif
263
+ # if 32 < SIZEOF_LONG_LONG * CHAR_BIT
264
+ y = x >> 32; if (y) {n -= 32; x = y;}
265
+ # endif
266
+ y = x >> 16; if (y) {n -= 16; x = y;}
267
+ y = x >> 8; if (y) {n -= 8; x = y;}
268
+ y = x >> 4; if (y) {n -= 4; x = y;}
269
+ y = x >> 2; if (y) {n -= 2; x = y;}
270
+ y = x >> 1; if (y) {return n - 2;}
271
+ return (unsigned int)(n - x);
272
+ #endif
273
+ }
274
+ #endif
275
+
276
+ #ifdef HAVE_UINT128_T
277
+ static inline unsigned int
278
+ nlz_int128(uint128_t x)
279
+ {
280
+ uint128_t y;
281
+ unsigned int n = 128;
282
+ y = x >> 64; if (y) {n -= 64; x = y;}
283
+ y = x >> 32; if (y) {n -= 32; x = y;}
284
+ y = x >> 16; if (y) {n -= 16; x = y;}
285
+ y = x >> 8; if (y) {n -= 8; x = y;}
286
+ y = x >> 4; if (y) {n -= 4; x = y;}
287
+ y = x >> 2; if (y) {n -= 2; x = y;}
288
+ y = x >> 1; if (y) {return n - 2;}
289
+ return (unsigned int)(n - x);
290
+ }
291
+ #endif
292
+
293
+ static inline unsigned int
294
+ nlz_intptr(uintptr_t x)
295
+ {
296
+ #if SIZEOF_UINTPTR_T == SIZEOF_INT
297
+ return nlz_int(x);
298
+ #elif SIZEOF_UINTPTR_T == SIZEOF_LONG
299
+ return nlz_long(x);
300
+ #elif SIZEOF_UINTPTR_T == SIZEOF_LONG_LONG
301
+ return nlz_long_long(x);
302
+ #else
303
+ #error no known integer type corresponds uintptr_t
304
+ return /* sane compiler */ ~0;
305
+ #endif
306
+ }
307
+
308
+ static inline unsigned int
309
+ rb_popcount32(uint32_t x)
310
+ {
311
+ #ifdef HAVE_BUILTIN___BUILTIN_POPCOUNT
312
+ return (unsigned int)__builtin_popcount(x);
313
+ #else
314
+ x = (x & 0x55555555) + (x >> 1 & 0x55555555);
315
+ x = (x & 0x33333333) + (x >> 2 & 0x33333333);
316
+ x = (x & 0x0f0f0f0f) + (x >> 4 & 0x0f0f0f0f);
317
+ x = (x & 0x001f001f) + (x >> 8 & 0x001f001f);
318
+ return (x & 0x0000003f) + (x >>16 & 0x0000003f);
319
+ #endif
320
+ }
321
+
322
+ static inline int
323
+ rb_popcount64(uint64_t x)
324
+ {
325
+ #ifdef HAVE_BUILTIN___BUILTIN_POPCOUNT
326
+ return __builtin_popcountll(x);
327
+ #else
328
+ x = (x & 0x5555555555555555) + (x >> 1 & 0x5555555555555555);
329
+ x = (x & 0x3333333333333333) + (x >> 2 & 0x3333333333333333);
330
+ x = (x & 0x0707070707070707) + (x >> 4 & 0x0707070707070707);
331
+ x = (x & 0x001f001f001f001f) + (x >> 8 & 0x001f001f001f001f);
332
+ x = (x & 0x0000003f0000003f) + (x >>16 & 0x0000003f0000003f);
333
+ return (x & 0x7f) + (x >>32 & 0x7f);
334
+ #endif
335
+ }
336
+
337
+ static inline int
338
+ rb_popcount_intptr(uintptr_t x)
339
+ {
340
+ #if SIZEOF_VOIDP == 8
341
+ return rb_popcount64(x);
342
+ #elif SIZEOF_VOIDP == 4
343
+ return rb_popcount32(x);
344
+ #endif
345
+ }
346
+
347
+ static inline int
348
+ ntz_int32(uint32_t x)
349
+ {
350
+ #ifdef HAVE_BUILTIN___BUILTIN_CTZ
351
+ return __builtin_ctz(x);
352
+ #else
353
+ return rb_popcount32((~x) & (x-1));
354
+ #endif
355
+ }
356
+
357
+ static inline int
358
+ ntz_int64(uint64_t x)
359
+ {
360
+ #ifdef HAVE_BUILTIN___BUILTIN_CTZLL
361
+ return __builtin_ctzll(x);
362
+ #else
363
+ return rb_popcount64((~x) & (x-1));
364
+ #endif
365
+ }
366
+
367
+ static inline int
368
+ ntz_intptr(uintptr_t x)
369
+ {
370
+ #if SIZEOF_VOIDP == 8
371
+ return ntz_int64(x);
372
+ #elif SIZEOF_VOIDP == 4
373
+ return ntz_int32(x);
374
+ #endif
375
+ }
376
+
377
+ #if HAVE_LONG_LONG && SIZEOF_LONG * 2 <= SIZEOF_LONG_LONG
378
+ # define DLONG LONG_LONG
379
+ # define DL2NUM(x) LL2NUM(x)
380
+ #elif defined(HAVE_INT128_T)
381
+ # define DLONG int128_t
382
+ # define DL2NUM(x) (RB_FIXABLE(x) ? LONG2FIX(x) : rb_int128t2big(x))
383
+ VALUE rb_int128t2big(int128_t n);
384
+ #endif
385
+
386
+ static inline long
387
+ rb_overflowed_fix_to_int(long x)
388
+ {
389
+ return (long)((unsigned long)(x >> 1) ^ (1LU << (SIZEOF_LONG * CHAR_BIT - 1)));
390
+ }
391
+
392
+ static inline VALUE
393
+ rb_fix_plus_fix(VALUE x, VALUE y)
394
+ {
395
+ #ifdef HAVE_BUILTIN___BUILTIN_ADD_OVERFLOW
396
+ long lz;
397
+ /* NOTE
398
+ * (1) `LONG2FIX(FIX2LONG(x)+FIX2LONG(y))`
399
+ + = `((lx*2+1)/2 + (ly*2+1)/2)*2+1`
400
+ + = `lx*2 + ly*2 + 1`
401
+ + = `(lx*2+1) + (ly*2+1) - 1`
402
+ + = `x + y - 1`
403
+ * (2) Fixnum's LSB is always 1.
404
+ * It means you can always run `x - 1` without overflow.
405
+ * (3) Of course `z = x + (y-1)` may overflow.
406
+ * At that time true value is
407
+ * * positive: 0b0 1xxx...1, and z = 0b1xxx...1
408
+ * * nevative: 0b1 0xxx...1, and z = 0b0xxx...1
409
+ * To convert this true value to long,
410
+ * (a) Use arithmetic shift
411
+ * * positive: 0b11xxx...
412
+ * * negative: 0b00xxx...
413
+ * (b) invert MSB
414
+ * * positive: 0b01xxx...
415
+ * * negative: 0b10xxx...
416
+ */
417
+ if (__builtin_add_overflow((long)x, (long)y-1, &lz)) {
418
+ return rb_int2big(rb_overflowed_fix_to_int(lz));
419
+ }
420
+ else {
421
+ return (VALUE)lz;
422
+ }
423
+ #else
424
+ long lz = FIX2LONG(x) + FIX2LONG(y);
425
+ return LONG2NUM(lz);
426
+ #endif
427
+ }
428
+
429
+ static inline VALUE
430
+ rb_fix_minus_fix(VALUE x, VALUE y)
431
+ {
432
+ #ifdef HAVE_BUILTIN___BUILTIN_SUB_OVERFLOW
433
+ long lz;
434
+ if (__builtin_sub_overflow((long)x, (long)y-1, &lz)) {
435
+ return rb_int2big(rb_overflowed_fix_to_int(lz));
436
+ }
437
+ else {
438
+ return (VALUE)lz;
439
+ }
440
+ #else
441
+ long lz = FIX2LONG(x) - FIX2LONG(y);
442
+ return LONG2NUM(lz);
443
+ #endif
444
+ }
445
+
446
+ /* arguments must be Fixnum */
447
+ static inline VALUE
448
+ rb_fix_mul_fix(VALUE x, VALUE y)
449
+ {
450
+ long lx = FIX2LONG(x);
451
+ long ly = FIX2LONG(y);
452
+ #ifdef DLONG
453
+ return DL2NUM((DLONG)lx * (DLONG)ly);
454
+ #else
455
+ if (MUL_OVERFLOW_FIXNUM_P(lx, ly)) {
456
+ return rb_big_mul(rb_int2big(lx), rb_int2big(ly));
457
+ }
458
+ else {
459
+ return LONG2FIX(lx * ly);
460
+ }
461
+ #endif
462
+ }
463
+
464
+ /*
465
+ * This behaves different from C99 for negative arguments.
466
+ * Note that div may overflow fixnum.
467
+ */
468
+ static inline void
469
+ rb_fix_divmod_fix(VALUE a, VALUE b, VALUE *divp, VALUE *modp)
470
+ {
471
+ /* assume / and % comply C99.
472
+ * ldiv(3) won't be inlined by GCC and clang.
473
+ * I expect / and % are compiled as single idiv.
474
+ */
475
+ long x = FIX2LONG(a);
476
+ long y = FIX2LONG(b);
477
+ long div, mod;
478
+ if (x == FIXNUM_MIN && y == -1) {
479
+ if (divp) *divp = LONG2NUM(-FIXNUM_MIN);
480
+ if (modp) *modp = LONG2FIX(0);
481
+ return;
482
+ }
483
+ div = x / y;
484
+ mod = x % y;
485
+ if (y > 0 ? mod < 0 : mod > 0) {
486
+ mod += y;
487
+ div -= 1;
488
+ }
489
+ if (divp) *divp = LONG2FIX(div);
490
+ if (modp) *modp = LONG2FIX(mod);
491
+ }
492
+
493
+ /* div() for Ruby
494
+ * This behaves different from C99 for negative arguments.
495
+ */
496
+ static inline VALUE
497
+ rb_fix_div_fix(VALUE x, VALUE y)
498
+ {
499
+ VALUE div;
500
+ rb_fix_divmod_fix(x, y, &div, NULL);
501
+ return div;
502
+ }
503
+
504
+ /* mod() for Ruby
505
+ * This behaves different from C99 for negative arguments.
506
+ */
507
+ static inline VALUE
508
+ rb_fix_mod_fix(VALUE x, VALUE y)
509
+ {
510
+ VALUE mod;
511
+ rb_fix_divmod_fix(x, y, NULL, &mod);
512
+ return mod;
513
+ }
514
+
515
+ #if defined(HAVE_UINT128_T) && defined(HAVE_LONG_LONG)
516
+ # define bit_length(x) \
517
+ (unsigned int) \
518
+ (sizeof(x) <= SIZEOF_INT ? SIZEOF_INT * CHAR_BIT - nlz_int((unsigned int)(x)) : \
519
+ sizeof(x) <= SIZEOF_LONG ? SIZEOF_LONG * CHAR_BIT - nlz_long((unsigned long)(x)) : \
520
+ sizeof(x) <= SIZEOF_LONG_LONG ? SIZEOF_LONG_LONG * CHAR_BIT - nlz_long_long((unsigned LONG_LONG)(x)) : \
521
+ SIZEOF_INT128_T * CHAR_BIT - nlz_int128((uint128_t)(x)))
522
+ #elif defined(HAVE_UINT128_T)
523
+ # define bit_length(x) \
524
+ (unsigned int) \
525
+ (sizeof(x) <= SIZEOF_INT ? SIZEOF_INT * CHAR_BIT - nlz_int((unsigned int)(x)) : \
526
+ sizeof(x) <= SIZEOF_LONG ? SIZEOF_LONG * CHAR_BIT - nlz_long((unsigned long)(x)) : \
527
+ SIZEOF_INT128_T * CHAR_BIT - nlz_int128((uint128_t)(x)))
528
+ #elif defined(HAVE_LONG_LONG)
529
+ # define bit_length(x) \
530
+ (unsigned int) \
531
+ (sizeof(x) <= SIZEOF_INT ? SIZEOF_INT * CHAR_BIT - nlz_int((unsigned int)(x)) : \
532
+ sizeof(x) <= SIZEOF_LONG ? SIZEOF_LONG * CHAR_BIT - nlz_long((unsigned long)(x)) : \
533
+ SIZEOF_LONG_LONG * CHAR_BIT - nlz_long_long((unsigned LONG_LONG)(x)))
534
+ #else
535
+ # define bit_length(x) \
536
+ (unsigned int) \
537
+ (sizeof(x) <= SIZEOF_INT ? SIZEOF_INT * CHAR_BIT - nlz_int((unsigned int)(x)) : \
538
+ SIZEOF_LONG * CHAR_BIT - nlz_long((unsigned long)(x)))
539
+ #endif
540
+
541
+ #ifndef BDIGIT
542
+ # if SIZEOF_INT*2 <= SIZEOF_LONG_LONG
543
+ # define BDIGIT unsigned int
544
+ # define SIZEOF_BDIGIT SIZEOF_INT
545
+ # define BDIGIT_DBL unsigned LONG_LONG
546
+ # define BDIGIT_DBL_SIGNED LONG_LONG
547
+ # define PRI_BDIGIT_PREFIX ""
548
+ # define PRI_BDIGIT_DBL_PREFIX PRI_LL_PREFIX
549
+ # elif SIZEOF_INT*2 <= SIZEOF_LONG
550
+ # define BDIGIT unsigned int
551
+ # define SIZEOF_BDIGIT SIZEOF_INT
552
+ # define BDIGIT_DBL unsigned long
553
+ # define BDIGIT_DBL_SIGNED long
554
+ # define PRI_BDIGIT_PREFIX ""
555
+ # define PRI_BDIGIT_DBL_PREFIX "l"
556
+ # elif SIZEOF_SHORT*2 <= SIZEOF_LONG
557
+ # define BDIGIT unsigned short
558
+ # define SIZEOF_BDIGIT SIZEOF_SHORT
559
+ # define BDIGIT_DBL unsigned long
560
+ # define BDIGIT_DBL_SIGNED long
561
+ # define PRI_BDIGIT_PREFIX "h"
562
+ # define PRI_BDIGIT_DBL_PREFIX "l"
563
+ # else
564
+ # define BDIGIT unsigned short
565
+ # define SIZEOF_BDIGIT (SIZEOF_LONG/2)
566
+ # define SIZEOF_ACTUAL_BDIGIT SIZEOF_LONG
567
+ # define BDIGIT_DBL unsigned long
568
+ # define BDIGIT_DBL_SIGNED long
569
+ # define PRI_BDIGIT_PREFIX "h"
570
+ # define PRI_BDIGIT_DBL_PREFIX "l"
571
+ # endif
572
+ #endif
573
+ #ifndef SIZEOF_ACTUAL_BDIGIT
574
+ # define SIZEOF_ACTUAL_BDIGIT SIZEOF_BDIGIT
575
+ #endif
576
+
577
+ #ifdef PRI_BDIGIT_PREFIX
578
+ # define PRIdBDIGIT PRI_BDIGIT_PREFIX"d"
579
+ # define PRIiBDIGIT PRI_BDIGIT_PREFIX"i"
580
+ # define PRIoBDIGIT PRI_BDIGIT_PREFIX"o"
581
+ # define PRIuBDIGIT PRI_BDIGIT_PREFIX"u"
582
+ # define PRIxBDIGIT PRI_BDIGIT_PREFIX"x"
583
+ # define PRIXBDIGIT PRI_BDIGIT_PREFIX"X"
584
+ #endif
585
+
586
+ #ifdef PRI_BDIGIT_DBL_PREFIX
587
+ # define PRIdBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"d"
588
+ # define PRIiBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"i"
589
+ # define PRIoBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"o"
590
+ # define PRIuBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"u"
591
+ # define PRIxBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"x"
592
+ # define PRIXBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"X"
593
+ #endif
594
+
595
+ #define BIGNUM_EMBED_LEN_NUMBITS 3
596
+ #ifndef BIGNUM_EMBED_LEN_MAX
597
+ # if (SIZEOF_VALUE*3/SIZEOF_ACTUAL_BDIGIT) < (1 << BIGNUM_EMBED_LEN_NUMBITS)-1
598
+ # define BIGNUM_EMBED_LEN_MAX (SIZEOF_VALUE*3/SIZEOF_ACTUAL_BDIGIT)
599
+ # else
600
+ # define BIGNUM_EMBED_LEN_MAX ((1 << BIGNUM_EMBED_LEN_NUMBITS)-1)
601
+ # endif
602
+ #endif
603
+
604
+ struct RBignum {
605
+ struct RBasic basic;
606
+ union {
607
+ struct {
608
+ size_t len;
609
+ BDIGIT *digits;
610
+ } heap;
611
+ BDIGIT ary[BIGNUM_EMBED_LEN_MAX];
612
+ } as;
613
+ };
614
+ #define BIGNUM_SIGN_BIT ((VALUE)FL_USER1)
615
+ /* sign: positive:1, negative:0 */
616
+ #define BIGNUM_SIGN(b) ((RBASIC(b)->flags & BIGNUM_SIGN_BIT) != 0)
617
+ #define BIGNUM_SET_SIGN(b,sign) \
618
+ ((sign) ? (RBASIC(b)->flags |= BIGNUM_SIGN_BIT) \
619
+ : (RBASIC(b)->flags &= ~BIGNUM_SIGN_BIT))
620
+ #define BIGNUM_POSITIVE_P(b) BIGNUM_SIGN(b)
621
+ #define BIGNUM_NEGATIVE_P(b) (!BIGNUM_SIGN(b))
622
+ #define BIGNUM_NEGATE(b) (RBASIC(b)->flags ^= BIGNUM_SIGN_BIT)
623
+
624
+ #define BIGNUM_EMBED_FLAG ((VALUE)FL_USER2)
625
+ #define BIGNUM_EMBED_LEN_MASK ((VALUE)(FL_USER5|FL_USER4|FL_USER3))
626
+ #define BIGNUM_EMBED_LEN_SHIFT (FL_USHIFT+BIGNUM_EMBED_LEN_NUMBITS)
627
+ #define BIGNUM_LEN(b) \
628
+ ((RBASIC(b)->flags & BIGNUM_EMBED_FLAG) ? \
629
+ (size_t)((RBASIC(b)->flags >> BIGNUM_EMBED_LEN_SHIFT) & \
630
+ (BIGNUM_EMBED_LEN_MASK >> BIGNUM_EMBED_LEN_SHIFT)) : \
631
+ RBIGNUM(b)->as.heap.len)
632
+ /* LSB:BIGNUM_DIGITS(b)[0], MSB:BIGNUM_DIGITS(b)[BIGNUM_LEN(b)-1] */
633
+ #define BIGNUM_DIGITS(b) \
634
+ ((RBASIC(b)->flags & BIGNUM_EMBED_FLAG) ? \
635
+ RBIGNUM(b)->as.ary : \
636
+ RBIGNUM(b)->as.heap.digits)
637
+ #define BIGNUM_LENINT(b) rb_long2int(BIGNUM_LEN(b))
638
+
639
+ #define RBIGNUM(obj) (R_CAST(RBignum)(obj))
640
+
641
+ struct RRational {
642
+ struct RBasic basic;
643
+ const VALUE num;
644
+ const VALUE den;
645
+ };
646
+
647
+ #define RRATIONAL(obj) (R_CAST(RRational)(obj))
648
+ #define RRATIONAL_SET_NUM(rat, n) RB_OBJ_WRITE((rat), &((struct RRational *)(rat))->num,(n))
649
+ #define RRATIONAL_SET_DEN(rat, d) RB_OBJ_WRITE((rat), &((struct RRational *)(rat))->den,(d))
650
+
651
+ struct RFloat {
652
+ struct RBasic basic;
653
+ double float_value;
654
+ };
655
+
656
+ #define RFLOAT(obj) (R_CAST(RFloat)(obj))
657
+
658
+ struct RComplex {
659
+ struct RBasic basic;
660
+ const VALUE real;
661
+ const VALUE imag;
662
+ };
663
+
664
+ #define RCOMPLEX(obj) (R_CAST(RComplex)(obj))
665
+
666
+ #ifdef RCOMPLEX_SET_REAL /* shortcut macro for internal only */
667
+ #undef RCOMPLEX_SET_REAL
668
+ #undef RCOMPLEX_SET_IMAG
669
+ #define RCOMPLEX_SET_REAL(cmp, r) RB_OBJ_WRITE((cmp), &((struct RComplex *)(cmp))->real,(r))
670
+ #define RCOMPLEX_SET_IMAG(cmp, i) RB_OBJ_WRITE((cmp), &((struct RComplex *)(cmp))->imag,(i))
671
+ #endif
672
+
673
+ struct RHash {
674
+ struct RBasic basic;
675
+ struct st_table *ntbl; /* possibly 0 */
676
+ int iter_lev;
677
+ const VALUE ifnone;
678
+ };
679
+
680
+ #define RHASH(obj) (R_CAST(RHash)(obj))
681
+
682
+ #ifdef RHASH_ITER_LEV
683
+ #undef RHASH_ITER_LEV
684
+ #undef RHASH_IFNONE
685
+ #undef RHASH_SIZE
686
+ #define RHASH_ITER_LEV(h) (RHASH(h)->iter_lev)
687
+ #define RHASH_IFNONE(h) (RHASH(h)->ifnone)
688
+ #define RHASH_SIZE(h) (RHASH(h)->ntbl ? RHASH(h)->ntbl->num_entries : (st_index_t)0)
689
+ #endif
690
+
691
+ /* missing/setproctitle.c */
692
+ #ifndef HAVE_SETPROCTITLE
693
+ extern void ruby_init_setproctitle(int argc, char *argv[]);
694
+ #endif
695
+
696
+ #define RSTRUCT_EMBED_LEN_MAX RSTRUCT_EMBED_LEN_MAX
697
+ #define RSTRUCT_EMBED_LEN_MASK RSTRUCT_EMBED_LEN_MASK
698
+ #define RSTRUCT_EMBED_LEN_SHIFT RSTRUCT_EMBED_LEN_SHIFT
699
+ enum {
700
+ RSTRUCT_EMBED_LEN_MAX = 3,
701
+ RSTRUCT_EMBED_LEN_MASK = (RUBY_FL_USER2|RUBY_FL_USER1),
702
+ RSTRUCT_EMBED_LEN_SHIFT = (RUBY_FL_USHIFT+1),
703
+
704
+ RSTRUCT_ENUM_END
705
+ };
706
+
707
+ struct RStruct {
708
+ struct RBasic basic;
709
+ union {
710
+ struct {
711
+ long len;
712
+ const VALUE *ptr;
713
+ } heap;
714
+ const VALUE ary[RSTRUCT_EMBED_LEN_MAX];
715
+ } as;
716
+ };
717
+
718
+ #undef RSTRUCT_LEN
719
+ #undef RSTRUCT_PTR
720
+ #undef RSTRUCT_SET
721
+ #undef RSTRUCT_GET
722
+ #define RSTRUCT_EMBED_LEN(st) \
723
+ (long)((RBASIC(st)->flags >> RSTRUCT_EMBED_LEN_SHIFT) & \
724
+ (RSTRUCT_EMBED_LEN_MASK >> RSTRUCT_EMBED_LEN_SHIFT))
725
+ #define RSTRUCT_LEN(st) rb_struct_len(st)
726
+ #define RSTRUCT_LENINT(st) rb_long2int(RSTRUCT_LEN(st))
727
+ #define RSTRUCT_CONST_PTR(st) rb_struct_const_ptr(st)
728
+ #define RSTRUCT_PTR(st) ((VALUE *)RSTRUCT_CONST_PTR(RB_OBJ_WB_UNPROTECT_FOR(STRUCT, st)))
729
+ #define RSTRUCT_SET(st, idx, v) RB_OBJ_WRITE(st, &RSTRUCT_CONST_PTR(st)[idx], (v))
730
+ #define RSTRUCT_GET(st, idx) (RSTRUCT_CONST_PTR(st)[idx])
731
+ #define RSTRUCT(obj) (R_CAST(RStruct)(obj))
732
+
733
+ static inline long
734
+ rb_struct_len(VALUE st)
735
+ {
736
+ return (RBASIC(st)->flags & RSTRUCT_EMBED_LEN_MASK) ?
737
+ RSTRUCT_EMBED_LEN(st) : RSTRUCT(st)->as.heap.len;
738
+ }
739
+
740
+ static inline const VALUE *
741
+ rb_struct_const_ptr(VALUE st)
742
+ {
743
+ return FIX_CONST_VALUE_PTR((RBASIC(st)->flags & RSTRUCT_EMBED_LEN_MASK) ?
744
+ RSTRUCT(st)->as.ary : RSTRUCT(st)->as.heap.ptr);
745
+ }
746
+
747
+ /* class.c */
748
+
749
+ struct rb_deprecated_classext_struct {
750
+ char conflict[sizeof(VALUE) * 3];
751
+ };
752
+
753
+ struct rb_subclass_entry;
754
+ typedef struct rb_subclass_entry rb_subclass_entry_t;
755
+
756
+ struct rb_subclass_entry {
757
+ VALUE klass;
758
+ rb_subclass_entry_t *next;
759
+ };
760
+
761
+ #if defined(HAVE_LONG_LONG)
762
+ typedef unsigned LONG_LONG rb_serial_t;
763
+ #define SERIALT2NUM ULL2NUM
764
+ #define PRI_SERIALT_PREFIX PRI_LL_PREFIX
765
+ #elif defined(HAVE_UINT64_T)
766
+ typedef uint64_t rb_serial_t;
767
+ #define SERIALT2NUM SIZET2NUM
768
+ #define PRI_SERIALT_PREFIX PRI_64_PREFIX
769
+ #else
770
+ typedef unsigned long rb_serial_t;
771
+ #define SERIALT2NUM ULONG2NUM
772
+ #define PRI_SERIALT_PREFIX PRI_LONG_PREFIX
773
+ #endif
774
+
775
+ struct rb_classext_struct {
776
+ struct st_table *iv_index_tbl;
777
+ struct st_table *iv_tbl;
778
+ struct rb_id_table *const_tbl;
779
+ struct rb_id_table *callable_m_tbl;
780
+ rb_subclass_entry_t *subclasses;
781
+ rb_subclass_entry_t **parent_subclasses;
782
+ /**
783
+ * In the case that this is an `ICLASS`, `module_subclasses` points to the link
784
+ * in the module's `subclasses` list that indicates that the klass has been
785
+ * included. Hopefully that makes sense.
786
+ */
787
+ rb_subclass_entry_t **module_subclasses;
788
+ rb_serial_t class_serial;
789
+ const VALUE origin_;
790
+ VALUE refined_class;
791
+ rb_alloc_func_t allocator;
792
+ };
793
+
794
+ typedef struct rb_classext_struct rb_classext_t;
795
+
796
+ #undef RClass
797
+ struct RClass {
798
+ struct RBasic basic;
799
+ VALUE super;
800
+ rb_classext_t *ptr;
801
+ struct rb_id_table *m_tbl;
802
+ };
803
+
804
+ void rb_class_subclass_add(VALUE super, VALUE klass);
805
+ void rb_class_remove_from_super_subclasses(VALUE);
806
+ int rb_singleton_class_internal_p(VALUE sklass);
807
+
808
+ #define RCLASS_EXT(c) (RCLASS(c)->ptr)
809
+ #define RCLASS_IV_TBL(c) (RCLASS_EXT(c)->iv_tbl)
810
+ #define RCLASS_CONST_TBL(c) (RCLASS_EXT(c)->const_tbl)
811
+ #define RCLASS_M_TBL(c) (RCLASS(c)->m_tbl)
812
+ #define RCLASS_CALLABLE_M_TBL(c) (RCLASS_EXT(c)->callable_m_tbl)
813
+ #define RCLASS_IV_INDEX_TBL(c) (RCLASS_EXT(c)->iv_index_tbl)
814
+ #define RCLASS_ORIGIN(c) (RCLASS_EXT(c)->origin_)
815
+ #define RCLASS_REFINED_CLASS(c) (RCLASS_EXT(c)->refined_class)
816
+ #define RCLASS_SERIAL(c) (RCLASS_EXT(c)->class_serial)
817
+
818
+ #define RICLASS_IS_ORIGIN FL_USER5
819
+
820
+ static inline void
821
+ RCLASS_SET_ORIGIN(VALUE klass, VALUE origin)
822
+ {
823
+ RB_OBJ_WRITE(klass, &RCLASS_ORIGIN(klass), origin);
824
+ if (klass != origin) FL_SET(origin, RICLASS_IS_ORIGIN);
825
+ }
826
+
827
+ #undef RCLASS_SUPER
828
+ static inline VALUE
829
+ RCLASS_SUPER(VALUE klass)
830
+ {
831
+ return RCLASS(klass)->super;
832
+ }
833
+
834
+ static inline VALUE
835
+ RCLASS_SET_SUPER(VALUE klass, VALUE super)
836
+ {
837
+ if (super) {
838
+ rb_class_remove_from_super_subclasses(klass);
839
+ rb_class_subclass_add(super, klass);
840
+ }
841
+ RB_OBJ_WRITE(klass, &RCLASS(klass)->super, super);
842
+ return super;
843
+ }
844
+ /* IMEMO: Internal memo object */
845
+
846
+ #ifndef IMEMO_DEBUG
847
+ #define IMEMO_DEBUG 0
848
+ #endif
849
+
850
+ struct RIMemo {
851
+ VALUE flags;
852
+ VALUE v0;
853
+ VALUE v1;
854
+ VALUE v2;
855
+ VALUE v3;
856
+ };
857
+
858
+ enum imemo_type {
859
+ imemo_env = 0,
860
+ imemo_cref = 1, /*!< class reference */
861
+ imemo_svar = 2, /*!< special variable */
862
+ imemo_throw_data = 3,
863
+ imemo_ifunc = 4, /*!< iterator function */
864
+ imemo_memo = 5,
865
+ imemo_ment = 6,
866
+ imemo_iseq = 7,
867
+ imemo_tmpbuf = 8,
868
+ imemo_ast = 9,
869
+ imemo_parser_strterm = 10
870
+ };
871
+ #define IMEMO_MASK 0x0f
872
+
873
+ static inline enum imemo_type
874
+ imemo_type(VALUE imemo)
875
+ {
876
+ return (RBASIC(imemo)->flags >> FL_USHIFT) & IMEMO_MASK;
877
+ }
878
+
879
+ static inline int
880
+ imemo_type_p(VALUE imemo, enum imemo_type imemo_type)
881
+ {
882
+ if (LIKELY(!RB_SPECIAL_CONST_P(imemo))) {
883
+ /* fixed at compile time if imemo_type is given. */
884
+ const VALUE mask = (IMEMO_MASK << FL_USHIFT) | RUBY_T_MASK;
885
+ const VALUE expected_type = (imemo_type << FL_USHIFT) | T_IMEMO;
886
+ /* fixed at runtime. */
887
+ return expected_type == (RBASIC(imemo)->flags & mask);
888
+ }
889
+ else {
890
+ return 0;
891
+ }
892
+ }
893
+
894
+ /* FL_USER0 to FL_USER3 is for type */
895
+ #define IMEMO_FL_USHIFT (FL_USHIFT + 4)
896
+ #define IMEMO_FL_USER0 FL_USER4
897
+ #define IMEMO_FL_USER1 FL_USER5
898
+ #define IMEMO_FL_USER2 FL_USER6
899
+ #define IMEMO_FL_USER3 FL_USER7
900
+ #define IMEMO_FL_USER4 FL_USER8
901
+
902
+ /* CREF (Class REFerence) is defined in method.h */
903
+
904
+ /*! SVAR (Special VARiable) */
905
+ struct vm_svar {
906
+ VALUE flags;
907
+ const VALUE cref_or_me; /*!< class reference or rb_method_entry_t */
908
+ const VALUE lastline;
909
+ const VALUE backref;
910
+ const VALUE others;
911
+ };
912
+
913
+
914
+ #define THROW_DATA_CONSUMED IMEMO_FL_USER0
915
+
916
+ /*! THROW_DATA */
917
+ struct vm_throw_data {
918
+ VALUE flags;
919
+ VALUE reserved;
920
+ const VALUE throw_obj;
921
+ const struct rb_control_frame_struct *catch_frame;
922
+ VALUE throw_state;
923
+ };
924
+
925
+ #define THROW_DATA_P(err) RB_TYPE_P((VALUE)(err), T_IMEMO)
926
+
927
+ /* IFUNC (Internal FUNCtion) */
928
+
929
+ struct vm_ifunc_argc {
930
+ #if SIZEOF_INT * 2 > SIZEOF_VALUE
931
+ signed int min: (SIZEOF_VALUE * CHAR_BIT) / 2;
932
+ signed int max: (SIZEOF_VALUE * CHAR_BIT) / 2;
933
+ #else
934
+ int min, max;
935
+ #endif
936
+ };
937
+
938
+ /*! IFUNC (Internal FUNCtion) */
939
+ struct vm_ifunc {
940
+ VALUE flags;
941
+ VALUE reserved;
942
+ VALUE (*func)(ANYARGS);
943
+ const void *data;
944
+ struct vm_ifunc_argc argc;
945
+ };
946
+
947
+ #define IFUNC_NEW(a, b, c) ((struct vm_ifunc *)rb_imemo_new(imemo_ifunc, (VALUE)(a), (VALUE)(b), (VALUE)(c), 0))
948
+ struct vm_ifunc *rb_vm_ifunc_new(VALUE (*func)(ANYARGS), const void *data, int min_argc, int max_argc);
949
+ static inline struct vm_ifunc *
950
+ rb_vm_ifunc_proc_new(VALUE (*func)(ANYARGS), const void *data)
951
+ {
952
+ return rb_vm_ifunc_new(func, data, 0, UNLIMITED_ARGUMENTS);
953
+ }
954
+
955
+ typedef struct rb_imemo_tmpbuf_struct {
956
+ VALUE flags;
957
+ VALUE reserved;
958
+ VALUE *ptr; /* malloc'ed buffer */
959
+ struct rb_imemo_tmpbuf_struct *next; /* next imemo */
960
+ size_t cnt; /* buffer size in VALUE */
961
+ } rb_imemo_tmpbuf_t;
962
+
963
+ VALUE rb_imemo_tmpbuf_auto_free_pointer(void *buf);
964
+ VALUE rb_imemo_tmpbuf_auto_free_maybe_mark_buffer(void *buf, size_t cnt);
965
+ rb_imemo_tmpbuf_t *rb_imemo_tmpbuf_parser_heap(void *buf, rb_imemo_tmpbuf_t *old_heap, size_t cnt);
966
+
967
+ #define RB_IMEMO_TMPBUF_PTR(v) \
968
+ ((void *)(((const struct rb_imemo_tmpbuf_struct *)(v))->ptr))
969
+
970
+ static inline VALUE
971
+ rb_imemo_tmpbuf_auto_free_pointer_new_from_an_RString(VALUE str)
972
+ {
973
+ const void *src;
974
+ void *dst;
975
+ size_t len;
976
+
977
+ SafeStringValue(str);
978
+ len = RSTRING_LEN(str);
979
+ src = RSTRING_PTR(str);
980
+ dst = ruby_xmalloc(len);
981
+ memcpy(dst, src, len);
982
+ return rb_imemo_tmpbuf_auto_free_pointer(dst);
983
+ }
984
+
985
+ void rb_strterm_mark(VALUE obj);
986
+
987
+ /*! MEMO
988
+ *
989
+ * @see imemo_type
990
+ * */
991
+ struct MEMO {
992
+ VALUE flags;
993
+ VALUE reserved;
994
+ const VALUE v1;
995
+ const VALUE v2;
996
+ union {
997
+ long cnt;
998
+ long state;
999
+ const VALUE value;
1000
+ VALUE (*func)(ANYARGS);
1001
+ } u3;
1002
+ };
1003
+
1004
+ #define MEMO_V1_SET(m, v) RB_OBJ_WRITE((m), &(m)->v1, (v))
1005
+ #define MEMO_V2_SET(m, v) RB_OBJ_WRITE((m), &(m)->v2, (v))
1006
+
1007
+ #define MEMO_CAST(m) ((struct MEMO *)m)
1008
+
1009
+ #define MEMO_NEW(a, b, c) ((struct MEMO *)rb_imemo_new(imemo_memo, (VALUE)(a), (VALUE)(b), (VALUE)(c), 0))
1010
+
1011
+ #define roomof(x, y) (((x) + (y) - 1) / (y))
1012
+ #define type_roomof(x, y) roomof(sizeof(x), sizeof(y))
1013
+ #define MEMO_FOR(type, value) ((type *)RARRAY_PTR(value))
1014
+ #define NEW_MEMO_FOR(type, value) \
1015
+ ((value) = rb_ary_tmp_new_fill(type_roomof(type, VALUE)), MEMO_FOR(type, value))
1016
+ #define NEW_PARTIAL_MEMO_FOR(type, value, member) \
1017
+ ((value) = rb_ary_tmp_new_fill(type_roomof(type, VALUE)), \
1018
+ rb_ary_set_len((value), offsetof(type, member) / sizeof(VALUE)), \
1019
+ MEMO_FOR(type, value))
1020
+
1021
+ #define STRING_P(s) (RB_TYPE_P((s), T_STRING) && CLASS_OF(s) == rb_cString)
1022
+
1023
+ #ifdef RUBY_INTEGER_UNIFICATION
1024
+ # define rb_cFixnum rb_cInteger
1025
+ # define rb_cBignum rb_cInteger
1026
+ #endif
1027
+
1028
+ enum {
1029
+ cmp_opt_Fixnum,
1030
+ cmp_opt_String,
1031
+ cmp_opt_Float,
1032
+ cmp_optimizable_count
1033
+ };
1034
+
1035
+ struct cmp_opt_data {
1036
+ unsigned int opt_methods;
1037
+ unsigned int opt_inited;
1038
+ };
1039
+
1040
+ #define NEW_CMP_OPT_MEMO(type, value) \
1041
+ NEW_PARTIAL_MEMO_FOR(type, value, cmp_opt)
1042
+ #define CMP_OPTIMIZABLE_BIT(type) (1U << TOKEN_PASTE(cmp_opt_,type))
1043
+ #define CMP_OPTIMIZABLE(data, type) \
1044
+ (((data).opt_inited & CMP_OPTIMIZABLE_BIT(type)) ? \
1045
+ ((data).opt_methods & CMP_OPTIMIZABLE_BIT(type)) : \
1046
+ (((data).opt_inited |= CMP_OPTIMIZABLE_BIT(type)), \
1047
+ rb_method_basic_definition_p(TOKEN_PASTE(rb_c,type), id_cmp) && \
1048
+ ((data).opt_methods |= CMP_OPTIMIZABLE_BIT(type))))
1049
+
1050
+ #define OPTIMIZED_CMP(a, b, data) \
1051
+ ((FIXNUM_P(a) && FIXNUM_P(b) && CMP_OPTIMIZABLE(data, Fixnum)) ? \
1052
+ (((long)a > (long)b) ? 1 : ((long)a < (long)b) ? -1 : 0) : \
1053
+ (STRING_P(a) && STRING_P(b) && CMP_OPTIMIZABLE(data, String)) ? \
1054
+ rb_str_cmp(a, b) : \
1055
+ (RB_FLOAT_TYPE_P(a) && RB_FLOAT_TYPE_P(b) && CMP_OPTIMIZABLE(data, Float)) ? \
1056
+ rb_float_cmp(a, b) : \
1057
+ rb_cmpint(rb_funcallv(a, id_cmp, 1, &b), a, b))
1058
+
1059
+ /* ment is in method.h */
1060
+
1061
+ /* global variable */
1062
+
1063
+ struct rb_global_entry {
1064
+ struct rb_global_variable *var;
1065
+ ID id;
1066
+ };
1067
+
1068
+ struct rb_global_entry *rb_global_entry(ID);
1069
+ VALUE rb_gvar_get(struct rb_global_entry *);
1070
+ VALUE rb_gvar_set(struct rb_global_entry *, VALUE);
1071
+ VALUE rb_gvar_defined(struct rb_global_entry *);
1072
+
1073
+ struct vtm; /* defined by timev.h */
1074
+
1075
+ /* array.c */
1076
+ VALUE rb_ary_last(int, const VALUE *, VALUE);
1077
+ void rb_ary_set_len(VALUE, long);
1078
+ void rb_ary_delete_same(VALUE, VALUE);
1079
+ VALUE rb_ary_tmp_new_fill(long capa);
1080
+ VALUE rb_ary_at(VALUE, VALUE);
1081
+ VALUE rb_ary_aref1(VALUE ary, VALUE i);
1082
+ VALUE rb_ary_aref2(VALUE ary, VALUE b, VALUE e);
1083
+ size_t rb_ary_memsize(VALUE);
1084
+ VALUE rb_to_array_type(VALUE obj);
1085
+ VALUE rb_check_to_array(VALUE ary);
1086
+ #if defined(__GNUC__) && defined(HAVE_VA_ARGS_MACRO)
1087
+ #define rb_ary_new_from_args(n, ...) \
1088
+ __extension__ ({ \
1089
+ const VALUE args_to_new_ary[] = {__VA_ARGS__}; \
1090
+ if (__builtin_constant_p(n)) { \
1091
+ STATIC_ASSERT(rb_ary_new_from_args, numberof(args_to_new_ary) == (n)); \
1092
+ } \
1093
+ rb_ary_new_from_values(numberof(args_to_new_ary), args_to_new_ary); \
1094
+ })
1095
+ #endif
1096
+
1097
+ static inline VALUE
1098
+ rb_ary_entry_internal(VALUE ary, long offset)
1099
+ {
1100
+ long len = RARRAY_LEN(ary);
1101
+ const VALUE *ptr = RARRAY_CONST_PTR(ary);
1102
+ if (len == 0) return Qnil;
1103
+ if (offset < 0) {
1104
+ offset += len;
1105
+ if (offset < 0) return Qnil;
1106
+ }
1107
+ else if (len <= offset) {
1108
+ return Qnil;
1109
+ }
1110
+ return ptr[offset];
1111
+ }
1112
+
1113
+ /* bignum.c */
1114
+ extern const char ruby_digitmap[];
1115
+ double rb_big_fdiv_double(VALUE x, VALUE y);
1116
+ VALUE rb_big_uminus(VALUE x);
1117
+ VALUE rb_big_hash(VALUE);
1118
+ VALUE rb_big_odd_p(VALUE);
1119
+ VALUE rb_big_even_p(VALUE);
1120
+ size_t rb_big_size(VALUE);
1121
+ VALUE rb_integer_float_cmp(VALUE x, VALUE y);
1122
+ VALUE rb_integer_float_eq(VALUE x, VALUE y);
1123
+ VALUE rb_cstr_parse_inum(const char *str, ssize_t len, char **endp, int base);
1124
+ VALUE rb_str_convert_to_inum(VALUE str, int base, int badcheck, int raise_exception);
1125
+ VALUE rb_big_comp(VALUE x);
1126
+ VALUE rb_big_aref(VALUE x, VALUE y);
1127
+ VALUE rb_big_abs(VALUE x);
1128
+ VALUE rb_big_size_m(VALUE big);
1129
+ VALUE rb_big_bit_length(VALUE big);
1130
+ VALUE rb_big_remainder(VALUE x, VALUE y);
1131
+ VALUE rb_big_gt(VALUE x, VALUE y);
1132
+ VALUE rb_big_ge(VALUE x, VALUE y);
1133
+ VALUE rb_big_lt(VALUE x, VALUE y);
1134
+ VALUE rb_big_le(VALUE x, VALUE y);
1135
+ VALUE rb_int_powm(int const argc, VALUE * const argv, VALUE const num);
1136
+
1137
+ /* class.c */
1138
+ VALUE rb_class_boot(VALUE);
1139
+ VALUE rb_class_inherited(VALUE, VALUE);
1140
+ VALUE rb_make_metaclass(VALUE, VALUE);
1141
+ VALUE rb_include_class_new(VALUE, VALUE);
1142
+ void rb_class_foreach_subclass(VALUE klass, void (*f)(VALUE, VALUE), VALUE);
1143
+ void rb_class_detach_subclasses(VALUE);
1144
+ void rb_class_detach_module_subclasses(VALUE);
1145
+ void rb_class_remove_from_module_subclasses(VALUE);
1146
+ VALUE rb_obj_methods(int argc, const VALUE *argv, VALUE obj);
1147
+ VALUE rb_obj_protected_methods(int argc, const VALUE *argv, VALUE obj);
1148
+ VALUE rb_obj_private_methods(int argc, const VALUE *argv, VALUE obj);
1149
+ VALUE rb_obj_public_methods(int argc, const VALUE *argv, VALUE obj);
1150
+ VALUE rb_special_singleton_class(VALUE);
1151
+ VALUE rb_singleton_class_clone_and_attach(VALUE obj, VALUE attach);
1152
+ VALUE rb_singleton_class_get(VALUE obj);
1153
+ void Init_class_hierarchy(void);
1154
+
1155
+ int rb_class_has_methods(VALUE c);
1156
+ void rb_undef_methods_from(VALUE klass, VALUE super);
1157
+
1158
+ /* compar.c */
1159
+ VALUE rb_invcmp(VALUE, VALUE);
1160
+
1161
+ /* compile.c */
1162
+ struct rb_block;
1163
+ int rb_dvar_defined(ID, const struct rb_block *);
1164
+ int rb_local_defined(ID, const struct rb_block *);
1165
+ const char * rb_insns_name(int i);
1166
+ VALUE rb_insns_name_array(void);
1167
+ int rb_vm_insn_addr2insn(const void *);
1168
+
1169
+ /* complex.c */
1170
+ VALUE rb_complex_plus(VALUE, VALUE);
1171
+ VALUE rb_complex_mul(VALUE, VALUE);
1172
+ VALUE rb_complex_abs(VALUE x);
1173
+ VALUE rb_complex_sqrt(VALUE x);
1174
+
1175
+ /* cont.c */
1176
+ VALUE rb_obj_is_fiber(VALUE);
1177
+ void rb_fiber_reset_root_local_storage(VALUE);
1178
+ void ruby_register_rollback_func_for_ensure(VALUE (*ensure_func)(ANYARGS), VALUE (*rollback_func)(ANYARGS));
1179
+
1180
+ /* debug.c */
1181
+ PRINTF_ARGS(void ruby_debug_printf(const char*, ...), 1, 2);
1182
+
1183
+ /* dir.c */
1184
+ VALUE rb_dir_getwd_ospath(void);
1185
+
1186
+ /* dmyext.c */
1187
+ void Init_enc(void);
1188
+ void Init_ext(void);
1189
+
1190
+ /* encoding.c */
1191
+ ID rb_id_encoding(void);
1192
+ void rb_gc_mark_encodings(void);
1193
+ #ifdef RUBY_ENCODING_H
1194
+ rb_encoding *rb_enc_get_from_index(int index);
1195
+ rb_encoding *rb_enc_check_str(VALUE str1, VALUE str2);
1196
+ #endif
1197
+ int rb_encdb_replicate(const char *alias, const char *orig);
1198
+ int rb_encdb_alias(const char *alias, const char *orig);
1199
+ int rb_encdb_dummy(const char *name);
1200
+ void rb_encdb_declare(const char *name);
1201
+ void rb_enc_set_base(const char *name, const char *orig);
1202
+ int rb_enc_set_dummy(int index);
1203
+ void rb_encdb_set_unicode(int index);
1204
+ PUREFUNC(int rb_data_is_encoding(VALUE obj));
1205
+
1206
+ /* enum.c */
1207
+ VALUE rb_f_send(int argc, VALUE *argv, VALUE recv);
1208
+ VALUE rb_nmin_run(VALUE obj, VALUE num, int by, int rev, int ary);
1209
+
1210
+ /* error.c */
1211
+ extern VALUE rb_eEAGAIN;
1212
+ extern VALUE rb_eEWOULDBLOCK;
1213
+ extern VALUE rb_eEINPROGRESS;
1214
+ void rb_report_bug_valist(VALUE file, int line, const char *fmt, va_list args);
1215
+ VALUE rb_check_backtrace(VALUE);
1216
+ NORETURN(void rb_async_bug_errno(const char *,int));
1217
+ const char *rb_builtin_type_name(int t);
1218
+ const char *rb_builtin_class_name(VALUE x);
1219
+ PRINTF_ARGS(void rb_sys_warn(const char *fmt, ...), 1, 2);
1220
+ PRINTF_ARGS(void rb_syserr_warn(int err, const char *fmt, ...), 2, 3);
1221
+ PRINTF_ARGS(void rb_sys_warning(const char *fmt, ...), 1, 2);
1222
+ PRINTF_ARGS(void rb_syserr_warning(int err, const char *fmt, ...), 2, 3);
1223
+ #ifdef RUBY_ENCODING_H
1224
+ VALUE rb_syntax_error_append(VALUE, VALUE, int, int, rb_encoding*, const char*, va_list);
1225
+ PRINTF_ARGS(void rb_enc_warn(rb_encoding *enc, const char *fmt, ...), 2, 3);
1226
+ PRINTF_ARGS(void rb_sys_enc_warn(rb_encoding *enc, const char *fmt, ...), 2, 3);
1227
+ PRINTF_ARGS(void rb_syserr_enc_warn(int err, rb_encoding *enc, const char *fmt, ...), 3, 4);
1228
+ PRINTF_ARGS(void rb_enc_warning(rb_encoding *enc, const char *fmt, ...), 2, 3);
1229
+ PRINTF_ARGS(void rb_sys_enc_warning(rb_encoding *enc, const char *fmt, ...), 2, 3);
1230
+ PRINTF_ARGS(void rb_syserr_enc_warning(int err, rb_encoding *enc, const char *fmt, ...), 3, 4);
1231
+ #endif
1232
+
1233
+ #define rb_raise_cstr(etype, mesg) \
1234
+ rb_exc_raise(rb_exc_new_str(etype, rb_str_new_cstr(mesg)))
1235
+ #define rb_raise_static(etype, mesg) \
1236
+ rb_exc_raise(rb_exc_new_str(etype, rb_str_new_static(mesg, rb_strlen_lit(mesg))))
1237
+
1238
+ VALUE rb_name_err_new(VALUE mesg, VALUE recv, VALUE method);
1239
+ #define rb_name_err_raise_str(mesg, recv, name) \
1240
+ rb_exc_raise(rb_name_err_new(mesg, recv, name))
1241
+ #define rb_name_err_raise(mesg, recv, name) \
1242
+ rb_name_err_raise_str(rb_fstring_cstr(mesg), (recv), (name))
1243
+ VALUE rb_nomethod_err_new(VALUE mesg, VALUE recv, VALUE method, VALUE args, int priv);
1244
+ VALUE rb_key_err_new(VALUE mesg, VALUE recv, VALUE name);
1245
+ #define rb_key_err_raise(mesg, recv, name) \
1246
+ rb_exc_raise(rb_key_err_new(mesg, recv, name))
1247
+ NORETURN(void ruby_deprecated_internal_feature(const char *));
1248
+ #define DEPRECATED_INTERNAL_FEATURE(func) \
1249
+ (ruby_deprecated_internal_feature(func), UNREACHABLE)
1250
+ VALUE rb_warning_warn(VALUE mod, VALUE str);
1251
+ VALUE rb_warning_string(const char *fmt, ...);
1252
+
1253
+ /* eval.c */
1254
+ VALUE rb_refinement_module_get_refined_class(VALUE module);
1255
+ extern ID ruby_static_id_signo, ruby_static_id_status;
1256
+ #define id_signo ruby_static_id_signo
1257
+ #define id_status ruby_static_id_status
1258
+
1259
+ /* eval_error.c */
1260
+ VALUE rb_get_backtrace(VALUE info);
1261
+
1262
+ /* eval_jump.c */
1263
+ void rb_call_end_proc(VALUE data);
1264
+ void rb_mark_end_proc(void);
1265
+
1266
+ /* file.c */
1267
+ extern const char ruby_null_device[];
1268
+ VALUE rb_home_dir_of(VALUE user, VALUE result);
1269
+ VALUE rb_default_home_dir(VALUE result);
1270
+ VALUE rb_realpath_internal(VALUE basedir, VALUE path, int strict);
1271
+ VALUE rb_check_realpath(VALUE basedir, VALUE path);
1272
+ void rb_file_const(const char*, VALUE);
1273
+ int rb_file_load_ok(const char *);
1274
+ VALUE rb_file_expand_path_fast(VALUE, VALUE);
1275
+ VALUE rb_file_expand_path_internal(VALUE, VALUE, int, int, VALUE);
1276
+ VALUE rb_get_path_check_to_string(VALUE, int);
1277
+ VALUE rb_get_path_check_convert(VALUE, VALUE, int);
1278
+ VALUE rb_get_path_check(VALUE, int);
1279
+ void Init_File(void);
1280
+ int ruby_is_fd_loadable(int fd);
1281
+
1282
+ #ifdef RUBY_FUNCTION_NAME_STRING
1283
+ # if defined __GNUC__ && __GNUC__ >= 4
1284
+ # pragma GCC visibility push(default)
1285
+ # endif
1286
+ NORETURN(void rb_sys_fail_path_in(const char *func_name, VALUE path));
1287
+ NORETURN(void rb_syserr_fail_path_in(const char *func_name, int err, VALUE path));
1288
+ # if defined __GNUC__ && __GNUC__ >= 4
1289
+ # pragma GCC visibility pop
1290
+ # endif
1291
+ # define rb_sys_fail_path(path) rb_sys_fail_path_in(RUBY_FUNCTION_NAME_STRING, path)
1292
+ # define rb_syserr_fail_path(err, path) rb_syserr_fail_path_in(RUBY_FUNCTION_NAME_STRING, (err), (path))
1293
+ #else
1294
+ # define rb_sys_fail_path(path) rb_sys_fail_str(path)
1295
+ # define rb_syserr_fail_path(err, path) rb_syserr_fail_str((err), (path))
1296
+ #endif
1297
+
1298
+ /* gc.c */
1299
+ extern VALUE *ruby_initial_gc_stress_ptr;
1300
+ extern int ruby_disable_gc;
1301
+ void Init_heap(void);
1302
+ void *ruby_mimmalloc(size_t size);
1303
+ void ruby_mimfree(void *ptr);
1304
+ void rb_objspace_set_event_hook(const rb_event_flag_t event);
1305
+ #if USE_RGENGC
1306
+ void rb_gc_writebarrier_remember(VALUE obj);
1307
+ #else
1308
+ #define rb_gc_writebarrier_remember(obj) 0
1309
+ #endif
1310
+ void ruby_gc_set_params(int safe_level);
1311
+ void rb_copy_wb_protected_attribute(VALUE dest, VALUE obj);
1312
+
1313
+ #if defined(HAVE_MALLOC_USABLE_SIZE) || defined(HAVE_MALLOC_SIZE) || defined(_WIN32)
1314
+ #define ruby_sized_xrealloc(ptr, new_size, old_size) ruby_xrealloc(ptr, new_size)
1315
+ #define ruby_sized_xrealloc2(ptr, new_count, element_size, old_count) ruby_xrealloc(ptr, new_count, element_size)
1316
+ #define ruby_sized_xfree(ptr, size) ruby_xfree(ptr)
1317
+ #define SIZED_REALLOC_N(var,type,n,old_n) REALLOC_N(var, type, n)
1318
+ #else
1319
+ RUBY_SYMBOL_EXPORT_BEGIN
1320
+ void *ruby_sized_xrealloc(void *ptr, size_t new_size, size_t old_size) RUBY_ATTR_ALLOC_SIZE((2));
1321
+ void *ruby_sized_xrealloc2(void *ptr, size_t new_count, size_t element_size, size_t old_count) RUBY_ATTR_ALLOC_SIZE((2, 3));
1322
+ void ruby_sized_xfree(void *x, size_t size);
1323
+ RUBY_SYMBOL_EXPORT_END
1324
+ #define SIZED_REALLOC_N(var,type,n,old_n) ((var)=(type*)ruby_sized_xrealloc((char*)(var), (n) * sizeof(type), (old_n) * sizeof(type)))
1325
+ #endif
1326
+
1327
+ /* optimized version of NEWOBJ() */
1328
+ #undef NEWOBJF_OF
1329
+ #undef RB_NEWOBJ_OF
1330
+ #define RB_NEWOBJ_OF(obj,type,klass,flags) \
1331
+ type *(obj) = (type*)(((flags) & FL_WB_PROTECTED) ? \
1332
+ rb_wb_protected_newobj_of(klass, (flags) & ~FL_WB_PROTECTED) : \
1333
+ rb_wb_unprotected_newobj_of(klass, flags))
1334
+ #define NEWOBJ_OF(obj,type,klass,flags) RB_NEWOBJ_OF(obj,type,klass,flags)
1335
+
1336
+ /* hash.c */
1337
+ struct st_table *rb_hash_tbl_raw(VALUE hash);
1338
+ VALUE rb_hash_new_with_size(st_index_t size);
1339
+ RUBY_SYMBOL_EXPORT_BEGIN
1340
+ VALUE rb_hash_new_compare_by_id(void);
1341
+ RUBY_SYMBOL_EXPORT_END
1342
+ VALUE rb_hash_has_key(VALUE hash, VALUE key);
1343
+ VALUE rb_hash_default_value(VALUE hash, VALUE key);
1344
+ VALUE rb_hash_set_default_proc(VALUE hash, VALUE proc);
1345
+ long rb_objid_hash(st_index_t index);
1346
+ long rb_dbl_long_hash(double d);
1347
+ st_table *rb_init_identtable(void);
1348
+ st_table *rb_init_identtable_with_size(st_index_t size);
1349
+ VALUE rb_hash_compare_by_id_p(VALUE hash);
1350
+ VALUE rb_to_hash_type(VALUE obj);
1351
+ VALUE rb_hash_key_str(VALUE);
1352
+
1353
+ #define RHASH_TBL_RAW(h) rb_hash_tbl_raw(h)
1354
+ VALUE rb_hash_keys(VALUE hash);
1355
+ VALUE rb_hash_values(VALUE hash);
1356
+ VALUE rb_hash_rehash(VALUE hash);
1357
+ int rb_hash_add_new_element(VALUE hash, VALUE key, VALUE val);
1358
+ #define HASH_PROC_DEFAULT FL_USER2
1359
+
1360
+ /* inits.c */
1361
+ void rb_call_inits(void);
1362
+
1363
+ /* io.c */
1364
+ const char *ruby_get_inplace_mode(void);
1365
+ void ruby_set_inplace_mode(const char *);
1366
+ ssize_t rb_io_bufread(VALUE io, void *buf, size_t size);
1367
+ void rb_stdio_set_default_encoding(void);
1368
+ VALUE rb_io_flush_raw(VALUE, int);
1369
+ #ifdef RUBY_IO_H
1370
+ size_t rb_io_memsize(const rb_io_t *);
1371
+ #endif
1372
+ int rb_stderr_tty_p(void);
1373
+ void rb_io_fptr_finalize_internal(void *ptr);
1374
+ #define rb_io_fptr_finalize rb_io_fptr_finalize_internal
1375
+
1376
+ /* load.c */
1377
+ VALUE rb_get_load_path(void);
1378
+ VALUE rb_get_expanded_load_path(void);
1379
+ int rb_require_internal(VALUE fname, int safe);
1380
+ NORETURN(void rb_load_fail(VALUE, const char*));
1381
+
1382
+ /* loadpath.c */
1383
+ extern const char ruby_exec_prefix[];
1384
+ extern const char ruby_initial_load_paths[];
1385
+
1386
+ /* localeinit.c */
1387
+ int Init_enc_set_filesystem_encoding(void);
1388
+
1389
+ /* math.c */
1390
+ VALUE rb_math_atan2(VALUE, VALUE);
1391
+ VALUE rb_math_cos(VALUE);
1392
+ VALUE rb_math_cosh(VALUE);
1393
+ VALUE rb_math_exp(VALUE);
1394
+ VALUE rb_math_hypot(VALUE, VALUE);
1395
+ VALUE rb_math_log(int argc, const VALUE *argv);
1396
+ VALUE rb_math_sin(VALUE);
1397
+ VALUE rb_math_sinh(VALUE);
1398
+ VALUE rb_math_sqrt(VALUE);
1399
+
1400
+ /* newline.c */
1401
+ void Init_newline(void);
1402
+
1403
+ /* numeric.c */
1404
+
1405
+ #define FIXNUM_POSITIVE_P(num) ((SIGNED_VALUE)(num) > (SIGNED_VALUE)INT2FIX(0))
1406
+ #define FIXNUM_NEGATIVE_P(num) ((SIGNED_VALUE)(num) < 0)
1407
+ #define FIXNUM_ZERO_P(num) ((num) == INT2FIX(0))
1408
+
1409
+ #define INT_NEGATIVE_P(x) (FIXNUM_P(x) ? FIXNUM_NEGATIVE_P(x) : BIGNUM_NEGATIVE_P(x))
1410
+
1411
+ #ifndef ROUND_DEFAULT
1412
+ # define ROUND_DEFAULT RUBY_NUM_ROUND_HALF_UP
1413
+ #endif
1414
+ enum ruby_num_rounding_mode {
1415
+ RUBY_NUM_ROUND_HALF_UP,
1416
+ RUBY_NUM_ROUND_HALF_EVEN,
1417
+ RUBY_NUM_ROUND_HALF_DOWN,
1418
+ RUBY_NUM_ROUND_DEFAULT = ROUND_DEFAULT
1419
+ };
1420
+ #define ROUND_TO(mode, even, up, down) \
1421
+ ((mode) == RUBY_NUM_ROUND_HALF_EVEN ? even : \
1422
+ (mode) == RUBY_NUM_ROUND_HALF_UP ? up : down)
1423
+ #define ROUND_FUNC(mode, name) \
1424
+ ROUND_TO(mode, name##_half_even, name##_half_up, name##_half_down)
1425
+ #define ROUND_CALL(mode, name, args) \
1426
+ ROUND_TO(mode, name##_half_even args, \
1427
+ name##_half_up args, name##_half_down args)
1428
+
1429
+ int rb_num_to_uint(VALUE val, unsigned int *ret);
1430
+ VALUE ruby_num_interval_step_size(VALUE from, VALUE to, VALUE step, int excl);
1431
+ int ruby_float_step(VALUE from, VALUE to, VALUE step, int excl, int allow_endless);
1432
+ double ruby_float_mod(double x, double y);
1433
+ int rb_num_negative_p(VALUE);
1434
+ VALUE rb_int_succ(VALUE num);
1435
+ VALUE rb_int_pred(VALUE num);
1436
+ VALUE rb_int_uminus(VALUE num);
1437
+ VALUE rb_float_uminus(VALUE num);
1438
+ VALUE rb_int_plus(VALUE x, VALUE y);
1439
+ VALUE rb_int_minus(VALUE x, VALUE y);
1440
+ VALUE rb_int_mul(VALUE x, VALUE y);
1441
+ VALUE rb_int_idiv(VALUE x, VALUE y);
1442
+ VALUE rb_int_modulo(VALUE x, VALUE y);
1443
+ VALUE rb_int_round(VALUE num, int ndigits, enum ruby_num_rounding_mode mode);
1444
+ VALUE rb_int2str(VALUE num, int base);
1445
+ VALUE rb_dbl_hash(double d);
1446
+ VALUE rb_fix_plus(VALUE x, VALUE y);
1447
+ VALUE rb_int_gt(VALUE x, VALUE y);
1448
+ int rb_float_cmp(VALUE x, VALUE y);
1449
+ VALUE rb_float_gt(VALUE x, VALUE y);
1450
+ VALUE rb_int_ge(VALUE x, VALUE y);
1451
+ enum ruby_num_rounding_mode rb_num_get_rounding_option(VALUE opts);
1452
+ double rb_int_fdiv_double(VALUE x, VALUE y);
1453
+ VALUE rb_int_pow(VALUE x, VALUE y);
1454
+ VALUE rb_float_pow(VALUE x, VALUE y);
1455
+ VALUE rb_int_cmp(VALUE x, VALUE y);
1456
+ VALUE rb_int_equal(VALUE x, VALUE y);
1457
+ VALUE rb_int_divmod(VALUE x, VALUE y);
1458
+ VALUE rb_int_and(VALUE x, VALUE y);
1459
+ VALUE rb_int_lshift(VALUE x, VALUE y);
1460
+ VALUE rb_int_div(VALUE x, VALUE y);
1461
+ VALUE rb_int_abs(VALUE num);
1462
+ VALUE rb_int_odd_p(VALUE num);
1463
+
1464
+ static inline VALUE
1465
+ rb_num_compare_with_zero(VALUE num, ID mid)
1466
+ {
1467
+ VALUE zero = INT2FIX(0);
1468
+ VALUE r = rb_check_funcall(num, mid, 1, &zero);
1469
+ if (r == Qundef) {
1470
+ rb_cmperr(num, zero);
1471
+ }
1472
+ return r;
1473
+ }
1474
+
1475
+ static inline int
1476
+ rb_num_positive_int_p(VALUE num)
1477
+ {
1478
+ const ID mid = '>';
1479
+
1480
+ if (FIXNUM_P(num)) {
1481
+ if (rb_method_basic_definition_p(rb_cInteger, mid))
1482
+ return FIXNUM_POSITIVE_P(num);
1483
+ }
1484
+ else if (RB_TYPE_P(num, T_BIGNUM)) {
1485
+ if (rb_method_basic_definition_p(rb_cInteger, mid))
1486
+ return BIGNUM_POSITIVE_P(num);
1487
+ }
1488
+ return RTEST(rb_num_compare_with_zero(num, mid));
1489
+ }
1490
+
1491
+
1492
+ static inline int
1493
+ rb_num_negative_int_p(VALUE num)
1494
+ {
1495
+ const ID mid = '<';
1496
+
1497
+ if (FIXNUM_P(num)) {
1498
+ if (rb_method_basic_definition_p(rb_cInteger, mid))
1499
+ return FIXNUM_NEGATIVE_P(num);
1500
+ }
1501
+ else if (RB_TYPE_P(num, T_BIGNUM)) {
1502
+ if (rb_method_basic_definition_p(rb_cInteger, mid))
1503
+ return BIGNUM_NEGATIVE_P(num);
1504
+ }
1505
+ return RTEST(rb_num_compare_with_zero(num, mid));
1506
+ }
1507
+
1508
+
1509
+ VALUE rb_float_abs(VALUE flt);
1510
+ VALUE rb_float_equal(VALUE x, VALUE y);
1511
+ VALUE rb_float_eql(VALUE x, VALUE y);
1512
+
1513
+ #if USE_FLONUM
1514
+ #define RUBY_BIT_ROTL(v, n) (((v) << (n)) | ((v) >> ((sizeof(v) * 8) - n)))
1515
+ #define RUBY_BIT_ROTR(v, n) (((v) >> (n)) | ((v) << ((sizeof(v) * 8) - n)))
1516
+ #endif
1517
+
1518
+ static inline double
1519
+ rb_float_flonum_value(VALUE v)
1520
+ {
1521
+ #if USE_FLONUM
1522
+ if (v != (VALUE)0x8000000000000002) { /* LIKELY */
1523
+ union {
1524
+ double d;
1525
+ VALUE v;
1526
+ } t;
1527
+
1528
+ VALUE b63 = (v >> 63);
1529
+ /* e: xx1... -> 011... */
1530
+ /* xx0... -> 100... */
1531
+ /* ^b63 */
1532
+ t.v = RUBY_BIT_ROTR((2 - b63) | (v & ~(VALUE)0x03), 3);
1533
+ return t.d;
1534
+ }
1535
+ #endif
1536
+ return 0.0;
1537
+ }
1538
+
1539
+ static inline double
1540
+ rb_float_noflonum_value(VALUE v)
1541
+ {
1542
+ return ((struct RFloat *)v)->float_value;
1543
+ }
1544
+
1545
+ static inline double
1546
+ rb_float_value_inline(VALUE v)
1547
+ {
1548
+ if (FLONUM_P(v)) {
1549
+ return rb_float_flonum_value(v);
1550
+ }
1551
+ return rb_float_noflonum_value(v);
1552
+ }
1553
+
1554
+ static inline VALUE
1555
+ rb_float_new_inline(double d)
1556
+ {
1557
+ #if USE_FLONUM
1558
+ union {
1559
+ double d;
1560
+ VALUE v;
1561
+ } t;
1562
+ int bits;
1563
+
1564
+ t.d = d;
1565
+ bits = (int)((VALUE)(t.v >> 60) & 0x7);
1566
+ /* bits contains 3 bits of b62..b60. */
1567
+ /* bits - 3 = */
1568
+ /* b011 -> b000 */
1569
+ /* b100 -> b001 */
1570
+
1571
+ if (t.v != 0x3000000000000000 /* 1.72723e-77 */ &&
1572
+ !((bits-3) & ~0x01)) {
1573
+ return (RUBY_BIT_ROTL(t.v, 3) & ~(VALUE)0x01) | 0x02;
1574
+ }
1575
+ else if (t.v == (VALUE)0) {
1576
+ /* +0.0 */
1577
+ return 0x8000000000000002;
1578
+ }
1579
+ /* out of range */
1580
+ #endif
1581
+ return rb_float_new_in_heap(d);
1582
+ }
1583
+
1584
+ #define rb_float_value(v) rb_float_value_inline(v)
1585
+ #define rb_float_new(d) rb_float_new_inline(d)
1586
+
1587
+ /* object.c */
1588
+ void rb_obj_copy_ivar(VALUE dest, VALUE obj);
1589
+ CONSTFUNC(VALUE rb_obj_equal(VALUE obj1, VALUE obj2));
1590
+ CONSTFUNC(VALUE rb_obj_not(VALUE obj));
1591
+ VALUE rb_class_search_ancestor(VALUE klass, VALUE super);
1592
+ NORETURN(void rb_undefined_alloc(VALUE klass));
1593
+ double rb_num_to_dbl(VALUE val);
1594
+ VALUE rb_obj_dig(int argc, VALUE *argv, VALUE self, VALUE notfound);
1595
+ VALUE rb_immutable_obj_clone(int, VALUE *, VALUE);
1596
+ VALUE rb_obj_not_equal(VALUE obj1, VALUE obj2);
1597
+ VALUE rb_convert_type_with_id(VALUE,int,const char*,ID);
1598
+ VALUE rb_check_convert_type_with_id(VALUE,int,const char*,ID);
1599
+
1600
+ struct RBasicRaw {
1601
+ VALUE flags;
1602
+ VALUE klass;
1603
+ };
1604
+
1605
+ #define RBASIC_CLEAR_CLASS(obj) memset(&(((struct RBasicRaw *)((VALUE)(obj)))->klass), 0, sizeof(VALUE))
1606
+ #define RBASIC_SET_CLASS_RAW(obj, cls) memcpy(&((struct RBasicRaw *)((VALUE)(obj)))->klass, &(cls), sizeof(VALUE))
1607
+ #define RBASIC_SET_CLASS(obj, cls) do { \
1608
+ VALUE _obj_ = (obj); \
1609
+ RB_OBJ_WRITE(_obj_, &((struct RBasicRaw *)(_obj_))->klass, cls); \
1610
+ } while (0)
1611
+
1612
+ /* parse.y */
1613
+ #ifndef USE_SYMBOL_GC
1614
+ #define USE_SYMBOL_GC 1
1615
+ #endif
1616
+ VALUE rb_parser_get_yydebug(VALUE);
1617
+ VALUE rb_parser_set_yydebug(VALUE, VALUE);
1618
+ RUBY_SYMBOL_EXPORT_BEGIN
1619
+ VALUE rb_parser_set_context(VALUE, const struct rb_block *, int);
1620
+ RUBY_SYMBOL_EXPORT_END
1621
+ void *rb_parser_load_file(VALUE parser, VALUE name);
1622
+ int rb_is_const_name(VALUE name);
1623
+ int rb_is_class_name(VALUE name);
1624
+ int rb_is_global_name(VALUE name);
1625
+ int rb_is_instance_name(VALUE name);
1626
+ int rb_is_attrset_name(VALUE name);
1627
+ int rb_is_local_name(VALUE name);
1628
+ int rb_is_method_name(VALUE name);
1629
+ int rb_is_junk_name(VALUE name);
1630
+ PUREFUNC(int rb_is_const_sym(VALUE sym));
1631
+ PUREFUNC(int rb_is_class_sym(VALUE sym));
1632
+ PUREFUNC(int rb_is_global_sym(VALUE sym));
1633
+ PUREFUNC(int rb_is_instance_sym(VALUE sym));
1634
+ PUREFUNC(int rb_is_attrset_sym(VALUE sym));
1635
+ PUREFUNC(int rb_is_local_sym(VALUE sym));
1636
+ PUREFUNC(int rb_is_method_sym(VALUE sym));
1637
+ PUREFUNC(int rb_is_junk_sym(VALUE sym));
1638
+ ID rb_make_internal_id(void);
1639
+ void rb_gc_free_dsymbol(VALUE);
1640
+ ID rb_id_attrget(ID id);
1641
+
1642
+ /* proc.c */
1643
+ VALUE rb_proc_location(VALUE self);
1644
+ st_index_t rb_hash_proc(st_index_t hash, VALUE proc);
1645
+ int rb_block_arity(void);
1646
+ int rb_block_min_max_arity(int *max);
1647
+ VALUE rb_func_proc_new(rb_block_call_func_t func, VALUE val);
1648
+ VALUE rb_func_lambda_new(rb_block_call_func_t func, VALUE val, int min_argc, int max_argc);
1649
+ VALUE rb_block_to_s(VALUE self, const struct rb_block *block, const char *additional_info);
1650
+
1651
+ /* process.c */
1652
+ #define RB_MAX_GROUPS (65536)
1653
+
1654
+ struct rb_execarg {
1655
+ union {
1656
+ struct {
1657
+ VALUE shell_script;
1658
+ } sh;
1659
+ struct {
1660
+ VALUE command_name;
1661
+ VALUE command_abspath; /* full path string or nil */
1662
+ VALUE argv_str;
1663
+ VALUE argv_buf;
1664
+ } cmd;
1665
+ } invoke;
1666
+ VALUE redirect_fds;
1667
+ VALUE envp_str;
1668
+ VALUE envp_buf;
1669
+ VALUE dup2_tmpbuf;
1670
+ unsigned use_shell : 1;
1671
+ unsigned pgroup_given : 1;
1672
+ unsigned umask_given : 1;
1673
+ unsigned unsetenv_others_given : 1;
1674
+ unsigned unsetenv_others_do : 1;
1675
+ unsigned close_others_given : 1;
1676
+ unsigned close_others_do : 1;
1677
+ unsigned chdir_given : 1;
1678
+ unsigned new_pgroup_given : 1;
1679
+ unsigned new_pgroup_flag : 1;
1680
+ unsigned uid_given : 1;
1681
+ unsigned gid_given : 1;
1682
+ unsigned exception : 1;
1683
+ rb_pid_t pgroup_pgid; /* asis(-1), new pgroup(0), specified pgroup (0<V). */
1684
+ VALUE rlimit_limits; /* Qfalse or [[rtype, softlim, hardlim], ...] */
1685
+ mode_t umask_mask;
1686
+ rb_uid_t uid;
1687
+ rb_gid_t gid;
1688
+ int close_others_maxhint;
1689
+ VALUE fd_dup2;
1690
+ VALUE fd_close;
1691
+ VALUE fd_open;
1692
+ VALUE fd_dup2_child;
1693
+ VALUE env_modification; /* Qfalse or [[k1,v1], ...] */
1694
+ VALUE path_env;
1695
+ VALUE chdir_dir;
1696
+ };
1697
+
1698
+ /* argv_str contains extra two elements.
1699
+ * The beginning one is for /bin/sh used by exec_with_sh.
1700
+ * The last one for terminating NULL used by execve.
1701
+ * See rb_exec_fillarg() in process.c. */
1702
+ #define ARGVSTR2ARGV(argv_str) ((char **)RB_IMEMO_TMPBUF_PTR(argv_str) + 1)
1703
+
1704
+ static inline size_t
1705
+ ARGVSTR2ARGC(VALUE argv_str)
1706
+ {
1707
+ size_t i = 0;
1708
+ char *const *p = ARGVSTR2ARGV(argv_str);
1709
+ while (p[i++])
1710
+ ;
1711
+ return i - 1;
1712
+ }
1713
+
1714
+ rb_pid_t rb_fork_ruby(int *status);
1715
+ void rb_last_status_clear(void);
1716
+
1717
+ /* rational.c */
1718
+ VALUE rb_rational_uminus(VALUE self);
1719
+ VALUE rb_rational_plus(VALUE self, VALUE other);
1720
+ VALUE rb_lcm(VALUE x, VALUE y);
1721
+ VALUE rb_rational_reciprocal(VALUE x);
1722
+ VALUE rb_cstr_to_rat(const char *, int);
1723
+ VALUE rb_rational_abs(VALUE self);
1724
+ VALUE rb_rational_cmp(VALUE self, VALUE other);
1725
+ VALUE rb_numeric_quo(VALUE x, VALUE y);
1726
+
1727
+ /* re.c */
1728
+ VALUE rb_reg_compile(VALUE str, int options, const char *sourcefile, int sourceline);
1729
+ VALUE rb_reg_check_preprocess(VALUE);
1730
+ long rb_reg_search0(VALUE, VALUE, long, int, int);
1731
+ VALUE rb_reg_match_p(VALUE re, VALUE str, long pos);
1732
+ bool rb_reg_start_with_p(VALUE re, VALUE str);
1733
+ void rb_backref_set_string(VALUE string, long pos, long len);
1734
+ int rb_match_count(VALUE match);
1735
+ int rb_match_nth_defined(int nth, VALUE match);
1736
+
1737
+ /* signal.c */
1738
+ extern int ruby_enable_coredump;
1739
+ int rb_get_next_signal(void);
1740
+
1741
+ /* strftime.c */
1742
+ #ifdef RUBY_ENCODING_H
1743
+ VALUE rb_strftime_timespec(const char *format, size_t format_len, rb_encoding *enc,
1744
+ const struct vtm *vtm, struct timespec *ts, int gmt);
1745
+ VALUE rb_strftime(const char *format, size_t format_len, rb_encoding *enc,
1746
+ const struct vtm *vtm, VALUE timev, int gmt);
1747
+ #endif
1748
+
1749
+ /* string.c */
1750
+ VALUE rb_fstring(VALUE);
1751
+ VALUE rb_fstring_new(const char *ptr, long len);
1752
+ #define rb_fstring_lit(str) rb_fstring_new((str), rb_strlen_lit(str))
1753
+ #define rb_fstring_literal(str) rb_fstring_lit(str)
1754
+ VALUE rb_fstring_cstr(const char *str);
1755
+ #ifdef HAVE_BUILTIN___BUILTIN_CONSTANT_P
1756
+ # define rb_fstring_cstr(str) RB_GNUC_EXTENSION_BLOCK( \
1757
+ (__builtin_constant_p(str)) ? \
1758
+ rb_fstring_new((str), (long)strlen(str)) : \
1759
+ rb_fstring_cstr(str) \
1760
+ )
1761
+ #endif
1762
+ #ifdef RUBY_ENCODING_H
1763
+ VALUE rb_fstring_enc_new(const char *ptr, long len, rb_encoding *enc);
1764
+ #define rb_fstring_enc_lit(str, enc) rb_fstring_enc_new((str), rb_strlen_lit(str), (enc))
1765
+ #define rb_fstring_enc_literal(str, enc) rb_fstring_enc_lit(str, enc)
1766
+ VALUE rb_fstring_enc_cstr(const char *ptr, rb_encoding *enc);
1767
+ # ifdef HAVE_BUILTIN___BUILTIN_CONSTANT_P
1768
+ # define rb_fstring_enc_cstr(str, enc) RB_GNUC_EXTENSION_BLOCK( \
1769
+ (__builtin_constant_p(str)) ? \
1770
+ rb_fstring_enc_new((str), (long)strlen(str), (enc)) : \
1771
+ rb_fstring_enc_cstr(str, enc) \
1772
+ )
1773
+ # endif
1774
+ #endif
1775
+ int rb_str_buf_cat_escaped_char(VALUE result, unsigned int c, int unicode_p);
1776
+ int rb_str_symname_p(VALUE);
1777
+ VALUE rb_str_quote_unprintable(VALUE);
1778
+ VALUE rb_id_quote_unprintable(ID);
1779
+ #define QUOTE(str) rb_str_quote_unprintable(str)
1780
+ #define QUOTE_ID(id) rb_id_quote_unprintable(id)
1781
+ char *rb_str_fill_terminator(VALUE str, const int termlen);
1782
+ void rb_str_change_terminator_length(VALUE str, const int oldtermlen, const int termlen);
1783
+ VALUE rb_str_locktmp_ensure(VALUE str, VALUE (*func)(VALUE), VALUE arg);
1784
+ VALUE rb_str_tmp_frozen_acquire(VALUE str);
1785
+ void rb_str_tmp_frozen_release(VALUE str, VALUE tmp);
1786
+ VALUE rb_str_chomp_string(VALUE str, VALUE chomp);
1787
+ #ifdef RUBY_ENCODING_H
1788
+ VALUE rb_external_str_with_enc(VALUE str, rb_encoding *eenc);
1789
+ VALUE rb_str_cat_conv_enc_opts(VALUE newstr, long ofs, const char *ptr, long len,
1790
+ rb_encoding *from, int ecflags, VALUE ecopts);
1791
+ VALUE rb_enc_str_scrub(rb_encoding *enc, VALUE str, VALUE repl);
1792
+ VALUE rb_str_initialize(VALUE str, const char *ptr, long len, rb_encoding *enc);
1793
+ #endif
1794
+ #define STR_NOEMBED FL_USER1
1795
+ #define STR_SHARED FL_USER2 /* = ELTS_SHARED */
1796
+ #define STR_EMBED_P(str) (!FL_TEST_RAW((str), STR_NOEMBED))
1797
+ #define STR_SHARED_P(s) FL_ALL_RAW((s), STR_NOEMBED|ELTS_SHARED)
1798
+ #define is_ascii_string(str) (rb_enc_str_coderange(str) == ENC_CODERANGE_7BIT)
1799
+ #define is_broken_string(str) (rb_enc_str_coderange(str) == ENC_CODERANGE_BROKEN)
1800
+ size_t rb_str_memsize(VALUE);
1801
+ VALUE rb_sym_proc_call(ID mid, int argc, const VALUE *argv, VALUE passed_proc);
1802
+ VALUE rb_sym_to_proc(VALUE sym);
1803
+ char *rb_str_to_cstr(VALUE str);
1804
+ VALUE rb_str_eql(VALUE str1, VALUE str2);
1805
+
1806
+ /* symbol.c */
1807
+ #ifdef RUBY_ENCODING_H
1808
+ VALUE rb_sym_intern(const char *ptr, long len, rb_encoding *enc);
1809
+ VALUE rb_sym_intern_cstr(const char *ptr, rb_encoding *enc);
1810
+ #ifdef __GNUC__
1811
+ #define rb_sym_intern_cstr(ptr, enc) __extension__ ( \
1812
+ { \
1813
+ (__builtin_constant_p(ptr)) ? \
1814
+ rb_sym_intern((ptr), (long)strlen(ptr), (enc)) : \
1815
+ rb_sym_intern_cstr((ptr), (enc)); \
1816
+ })
1817
+ #endif
1818
+ #endif
1819
+ VALUE rb_sym_intern_ascii(const char *ptr, long len);
1820
+ VALUE rb_sym_intern_ascii_cstr(const char *ptr);
1821
+ #ifdef __GNUC__
1822
+ #define rb_sym_intern_ascii_cstr(ptr) __extension__ ( \
1823
+ { \
1824
+ (__builtin_constant_p(ptr)) ? \
1825
+ rb_sym_intern_ascii((ptr), (long)strlen(ptr)) : \
1826
+ rb_sym_intern_ascii_cstr(ptr); \
1827
+ })
1828
+ #endif
1829
+ VALUE rb_to_symbol_type(VALUE obj);
1830
+
1831
+ /* struct.c */
1832
+ VALUE rb_struct_init_copy(VALUE copy, VALUE s);
1833
+ VALUE rb_struct_lookup(VALUE s, VALUE idx);
1834
+ VALUE rb_struct_s_keyword_init(VALUE klass);
1835
+
1836
+ /* time.c */
1837
+ struct timeval rb_time_timeval(VALUE);
1838
+
1839
+ /* thread.c */
1840
+ #define COVERAGE_INDEX_LINES 0
1841
+ #define COVERAGE_INDEX_BRANCHES 1
1842
+ #define COVERAGE_TARGET_LINES 1
1843
+ #define COVERAGE_TARGET_BRANCHES 2
1844
+ #define COVERAGE_TARGET_METHODS 4
1845
+
1846
+ VALUE rb_obj_is_mutex(VALUE obj);
1847
+ VALUE rb_suppress_tracing(VALUE (*func)(VALUE), VALUE arg);
1848
+ void rb_thread_execute_interrupts(VALUE th);
1849
+ void rb_clear_trace_func(void);
1850
+ VALUE rb_get_coverages(void);
1851
+ VALUE rb_default_coverage(int);
1852
+ VALUE rb_thread_shield_new(void);
1853
+ VALUE rb_thread_shield_wait(VALUE self);
1854
+ VALUE rb_thread_shield_release(VALUE self);
1855
+ VALUE rb_thread_shield_destroy(VALUE self);
1856
+ int rb_thread_to_be_killed(VALUE thread);
1857
+ void rb_mutex_allow_trap(VALUE self, int val);
1858
+ VALUE rb_uninterruptible(VALUE (*b_proc)(ANYARGS), VALUE data);
1859
+ VALUE rb_mutex_owned_p(VALUE self);
1860
+
1861
+ /* thread_pthread.c, thread_win32.c */
1862
+ int rb_divert_reserved_fd(int fd);
1863
+
1864
+ /* transcode.c */
1865
+ extern VALUE rb_cEncodingConverter;
1866
+ #ifdef RUBY_ENCODING_H
1867
+ size_t rb_econv_memsize(rb_econv_t *);
1868
+ #endif
1869
+
1870
+ /* us_ascii.c */
1871
+ #ifdef RUBY_ENCODING_H
1872
+ extern rb_encoding OnigEncodingUS_ASCII;
1873
+ #endif
1874
+
1875
+ /* util.c */
1876
+ char *ruby_dtoa(double d_, int mode, int ndigits, int *decpt, int *sign, char **rve);
1877
+ char *ruby_hdtoa(double d, const char *xdigs, int ndigits, int *decpt, int *sign, char **rve);
1878
+
1879
+ /* utf_8.c */
1880
+ #ifdef RUBY_ENCODING_H
1881
+ extern rb_encoding OnigEncodingUTF_8;
1882
+ #endif
1883
+
1884
+ /* variable.c */
1885
+ void rb_gc_mark_global_tbl(void);
1886
+ size_t rb_generic_ivar_memsize(VALUE);
1887
+ VALUE rb_search_class_path(VALUE);
1888
+ VALUE rb_attr_delete(VALUE, ID);
1889
+ VALUE rb_ivar_lookup(VALUE obj, ID id, VALUE undef);
1890
+ void rb_autoload_str(VALUE mod, ID id, VALUE file);
1891
+ void rb_deprecate_constant(VALUE mod, const char *name);
1892
+ NORETURN(VALUE rb_mod_const_missing(VALUE,VALUE));
1893
+
1894
+ /* vm_insnhelper.h */
1895
+ rb_serial_t rb_next_class_serial(void);
1896
+
1897
+ /* vm.c */
1898
+ VALUE rb_obj_is_thread(VALUE obj);
1899
+ void rb_vm_mark(void *ptr);
1900
+ void Init_BareVM(void);
1901
+ void Init_vm_objects(void);
1902
+ PUREFUNC(VALUE rb_vm_top_self(void));
1903
+ void rb_thread_recycle_stack_release(VALUE *);
1904
+ void rb_vm_change_state(void);
1905
+ void rb_vm_inc_const_missing_count(void);
1906
+ const void **rb_vm_get_insns_address_table(void);
1907
+ VALUE rb_source_location(int *pline);
1908
+ const char *rb_source_location_cstr(int *pline);
1909
+ void rb_vm_pop_cfunc_frame(void);
1910
+ int rb_vm_add_root_module(ID id, VALUE module);
1911
+ void rb_vm_check_redefinition_by_prepend(VALUE klass);
1912
+ VALUE rb_yield_refine_block(VALUE refinement, VALUE refinements);
1913
+ VALUE ruby_vm_special_exception_copy(VALUE);
1914
+ PUREFUNC(st_table *rb_vm_fstring_table(void));
1915
+
1916
+
1917
+ /* vm_dump.c */
1918
+ void rb_print_backtrace(void);
1919
+
1920
+ /* vm_eval.c */
1921
+ void Init_vm_eval(void);
1922
+ VALUE rb_current_realfilepath(void);
1923
+ VALUE rb_check_block_call(VALUE, ID, int, const VALUE *, rb_block_call_func_t, VALUE);
1924
+ typedef void rb_check_funcall_hook(int, VALUE, ID, int, const VALUE *, VALUE);
1925
+ VALUE rb_check_funcall_with_hook(VALUE recv, ID mid, int argc, const VALUE *argv,
1926
+ rb_check_funcall_hook *hook, VALUE arg);
1927
+ const char *rb_type_str(enum ruby_value_type type);
1928
+ VALUE rb_check_funcall_default(VALUE, ID, int, const VALUE *, VALUE);
1929
+ VALUE rb_yield_1(VALUE val);
1930
+ VALUE rb_yield_force_blockarg(VALUE values);
1931
+ VALUE rb_lambda_call(VALUE obj, ID mid, int argc, const VALUE *argv,
1932
+ rb_block_call_func_t bl_proc, int min_argc, int max_argc,
1933
+ VALUE data2);
1934
+
1935
+ /* vm_insnhelper.c */
1936
+ VALUE rb_equal_opt(VALUE obj1, VALUE obj2);
1937
+ VALUE rb_eql_opt(VALUE obj1, VALUE obj2);
1938
+
1939
+ /* vm_method.c */
1940
+ void Init_eval_method(void);
1941
+ int rb_method_defined_by(VALUE obj, ID mid, VALUE (*cfunc)(ANYARGS));
1942
+
1943
+ /* miniprelude.c, prelude.c */
1944
+ void Init_prelude(void);
1945
+
1946
+ /* vm_backtrace.c */
1947
+ void Init_vm_backtrace(void);
1948
+ VALUE rb_vm_thread_backtrace(int argc, const VALUE *argv, VALUE thval);
1949
+ VALUE rb_vm_thread_backtrace_locations(int argc, const VALUE *argv, VALUE thval);
1950
+
1951
+ VALUE rb_make_backtrace(void);
1952
+ void rb_backtrace_print_as_bugreport(void);
1953
+ int rb_backtrace_p(VALUE obj);
1954
+ VALUE rb_backtrace_to_str_ary(VALUE obj);
1955
+ VALUE rb_backtrace_to_location_ary(VALUE obj);
1956
+ void rb_backtrace_each(VALUE (*iter)(VALUE recv, VALUE str), VALUE output);
1957
+
1958
+ RUBY_SYMBOL_EXPORT_BEGIN
1959
+ const char *rb_objspace_data_type_name(VALUE obj);
1960
+
1961
+ /* Temporary. This API will be removed (renamed). */
1962
+ VALUE rb_thread_io_blocking_region(rb_blocking_function_t *func, void *data1, int fd);
1963
+
1964
+ /* bignum.c (export) */
1965
+ VALUE rb_big_mul_normal(VALUE x, VALUE y);
1966
+ VALUE rb_big_mul_balance(VALUE x, VALUE y);
1967
+ VALUE rb_big_mul_karatsuba(VALUE x, VALUE y);
1968
+ VALUE rb_big_mul_toom3(VALUE x, VALUE y);
1969
+ VALUE rb_big_sq_fast(VALUE x);
1970
+ VALUE rb_big_divrem_normal(VALUE x, VALUE y);
1971
+ VALUE rb_big2str_poweroftwo(VALUE x, int base);
1972
+ VALUE rb_big2str_generic(VALUE x, int base);
1973
+ VALUE rb_str2big_poweroftwo(VALUE arg, int base, int badcheck);
1974
+ VALUE rb_str2big_normal(VALUE arg, int base, int badcheck);
1975
+ VALUE rb_str2big_karatsuba(VALUE arg, int base, int badcheck);
1976
+ #if defined(HAVE_LIBGMP) && defined(HAVE_GMP_H)
1977
+ VALUE rb_big_mul_gmp(VALUE x, VALUE y);
1978
+ VALUE rb_big_divrem_gmp(VALUE x, VALUE y);
1979
+ VALUE rb_big2str_gmp(VALUE x, int base);
1980
+ VALUE rb_str2big_gmp(VALUE arg, int base, int badcheck);
1981
+ #endif
1982
+ enum rb_int_parse_flags {
1983
+ RB_INT_PARSE_SIGN = 0x01,
1984
+ RB_INT_PARSE_UNDERSCORE = 0x02,
1985
+ RB_INT_PARSE_PREFIX = 0x04,
1986
+ RB_INT_PARSE_ALL = 0x07,
1987
+ RB_INT_PARSE_DEFAULT = 0x07
1988
+ };
1989
+ VALUE rb_int_parse_cstr(const char *str, ssize_t len, char **endp, size_t *ndigits, int base, int flags);
1990
+
1991
+ /* error.c (export) */
1992
+ int rb_bug_reporter_add(void (*func)(FILE *, void *), void *data);
1993
+ NORETURN(void rb_unexpected_type(VALUE,int));
1994
+ #undef Check_Type
1995
+ #define Check_Type(v, t) \
1996
+ (!RB_TYPE_P((VALUE)(v), (t)) || \
1997
+ ((t) == RUBY_T_DATA && RTYPEDDATA_P(v)) ? \
1998
+ rb_unexpected_type((VALUE)(v), (t)) : (void)0)
1999
+
2000
+ /* file.c (export) */
2001
+ #if defined HAVE_READLINK && defined RUBY_ENCODING_H
2002
+ VALUE rb_readlink(VALUE path, rb_encoding *enc);
2003
+ #endif
2004
+ #ifdef __APPLE__
2005
+ VALUE rb_str_normalize_ospath(const char *ptr, long len);
2006
+ #endif
2007
+
2008
+ /* hash.c (export) */
2009
+ VALUE rb_hash_delete_entry(VALUE hash, VALUE key);
2010
+ VALUE rb_ident_hash_new(void);
2011
+
2012
+ /* io.c (export) */
2013
+ void rb_maygvl_fd_fix_cloexec(int fd);
2014
+ int rb_gc_for_fd(int err);
2015
+ void rb_write_error_str(VALUE mesg);
2016
+
2017
+ /* numeric.c (export) */
2018
+ VALUE rb_int_positive_pow(long x, unsigned long y);
2019
+
2020
+ /* process.c (export) */
2021
+ int rb_exec_async_signal_safe(const struct rb_execarg *e, char *errmsg, size_t errmsg_buflen);
2022
+ 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);
2023
+ VALUE rb_execarg_new(int argc, const VALUE *argv, int accept_shell, int allow_exc_opt);
2024
+ struct rb_execarg *rb_execarg_get(VALUE execarg_obj); /* dangerous. needs GC guard. */
2025
+ VALUE rb_execarg_init(int argc, const VALUE *argv, int accept_shell, VALUE execarg_obj, int allow_exc_opt);
2026
+ int rb_execarg_addopt(VALUE execarg_obj, VALUE key, VALUE val);
2027
+ void rb_execarg_parent_start(VALUE execarg_obj);
2028
+ void rb_execarg_parent_end(VALUE execarg_obj);
2029
+ int rb_execarg_run_options(const struct rb_execarg *e, struct rb_execarg *s, char* errmsg, size_t errmsg_buflen);
2030
+ VALUE rb_execarg_extract_options(VALUE execarg_obj, VALUE opthash);
2031
+ void rb_execarg_setenv(VALUE execarg_obj, VALUE env);
2032
+
2033
+ /* rational.c (export) */
2034
+ VALUE rb_gcd(VALUE x, VALUE y);
2035
+ VALUE rb_gcd_normal(VALUE self, VALUE other);
2036
+ #if defined(HAVE_LIBGMP) && defined(HAVE_GMP_H)
2037
+ VALUE rb_gcd_gmp(VALUE x, VALUE y);
2038
+ #endif
2039
+
2040
+ /* string.c (export) */
2041
+ #ifdef RUBY_ENCODING_H
2042
+ /* internal use */
2043
+ VALUE rb_setup_fake_str(struct RString *fake_str, const char *name, long len, rb_encoding *enc);
2044
+ #endif
2045
+ VALUE rb_str_upto_each(VALUE, VALUE, int, int (*each)(VALUE, VALUE), VALUE);
2046
+ VALUE rb_str_upto_endless_each(VALUE, int (*each)(VALUE, VALUE), VALUE);
2047
+
2048
+ /* thread.c (export) */
2049
+ int ruby_thread_has_gvl_p(void); /* for ext/fiddle/closure.c */
2050
+
2051
+ /* util.c (export) */
2052
+ extern const signed char ruby_digit36_to_number_table[];
2053
+ extern const char ruby_hexdigits[];
2054
+ extern unsigned long ruby_scan_digits(const char *str, ssize_t len, int base, size_t *retlen, int *overflow);
2055
+
2056
+ /* variable.c (export) */
2057
+ void rb_mark_generic_ivar(VALUE);
2058
+ VALUE rb_const_missing(VALUE klass, VALUE name);
2059
+ int rb_class_ivar_set(VALUE klass, ID vid, VALUE value);
2060
+ st_table *rb_st_copy(VALUE obj, struct st_table *orig_tbl);
2061
+
2062
+ /* gc.c (export) */
2063
+ VALUE rb_wb_protected_newobj_of(VALUE, VALUE);
2064
+ VALUE rb_wb_unprotected_newobj_of(VALUE, VALUE);
2065
+
2066
+ size_t rb_obj_memsize_of(VALUE);
2067
+ void rb_gc_verify_internal_consistency(void);
2068
+
2069
+ #define RB_OBJ_GC_FLAGS_MAX 5
2070
+ size_t rb_obj_gc_flags(VALUE, ID[], size_t);
2071
+ void rb_gc_mark_values(long n, const VALUE *values);
2072
+
2073
+ #if IMEMO_DEBUG
2074
+ VALUE rb_imemo_new_debug(enum imemo_type type, VALUE v1, VALUE v2, VALUE v3, VALUE v0, const char *file, int line);
2075
+ #define rb_imemo_new(type, v1, v2, v3, v0) rb_imemo_new_debug(type, v1, v2, v3, v0, __FILE__, __LINE__)
2076
+ #else
2077
+ VALUE rb_imemo_new(enum imemo_type type, VALUE v1, VALUE v2, VALUE v3, VALUE v0);
2078
+ #endif
2079
+
2080
+ RUBY_SYMBOL_EXPORT_END
2081
+
2082
+ #define RUBY_DTRACE_CREATE_HOOK(name, arg) \
2083
+ RUBY_DTRACE_HOOK(name##_CREATE, arg)
2084
+ #define RUBY_DTRACE_HOOK(name, arg) \
2085
+ do { \
2086
+ if (UNLIKELY(RUBY_DTRACE_##name##_ENABLED())) { \
2087
+ int dtrace_line; \
2088
+ const char *dtrace_file = rb_source_location_cstr(&dtrace_line); \
2089
+ if (!dtrace_file) dtrace_file = ""; \
2090
+ RUBY_DTRACE_##name(arg, dtrace_file, dtrace_line); \
2091
+ } \
2092
+ } while (0)
2093
+
2094
+ #define RB_OBJ_BUILTIN_TYPE(obj) rb_obj_builtin_type(obj)
2095
+ #define OBJ_BUILTIN_TYPE(obj) RB_OBJ_BUILTIN_TYPE(obj)
2096
+ #ifdef __GNUC__
2097
+ #define rb_obj_builtin_type(obj) \
2098
+ __extension__({ \
2099
+ VALUE arg_obj = (obj); \
2100
+ RB_SPECIAL_CONST_P(arg_obj) ? -1 : \
2101
+ RB_BUILTIN_TYPE(arg_obj); \
2102
+ })
2103
+ #else
2104
+ static inline int
2105
+ rb_obj_builtin_type(VALUE obj)
2106
+ {
2107
+ return RB_SPECIAL_CONST_P(obj) ? -1 :
2108
+ RB_BUILTIN_TYPE(obj);
2109
+ }
2110
+ #endif
2111
+
2112
+ /* A macro for defining a flexible array, like: VALUE ary[FLEX_ARY_LEN]; */
2113
+ #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
2114
+ # define FLEX_ARY_LEN /* VALUE ary[]; */
2115
+ #elif defined(__GNUC__) && !defined(__STRICT_ANSI__)
2116
+ # define FLEX_ARY_LEN 0 /* VALUE ary[0]; */
2117
+ #else
2118
+ # define FLEX_ARY_LEN 1 /* VALUE ary[1]; */
2119
+ #endif
2120
+
2121
+ /*
2122
+ * For declaring bitfields out of non-unsigned int types:
2123
+ * struct date {
2124
+ * BITFIELD(enum months) month:4;
2125
+ * ...
2126
+ * };
2127
+ */
2128
+ #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
2129
+ # define BITFIELD(type) type
2130
+ #else
2131
+ # define BITFIELD(type) unsigned int
2132
+ #endif
2133
+
2134
+ #if defined(__cplusplus)
2135
+ #if 0
2136
+ { /* satisfy cc-mode */
2137
+ #endif
2138
+ } /* extern "C" { */
2139
+ #endif
2140
+
2141
+ #endif /* RUBY_INTERNAL_H */