unmixer 0.4.0 → 0.5.0

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