zscan 2.0.3 → 2.0.4

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