Ruby 2.0.0p247(2013-06-27revision41674)

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

ruby.h
Go to the documentation of this file.
1 /**********************************************************************
2
3 ruby/ruby.h -
4
5 $Author: nagachika $
6 created at: Thu Jun 10 14:26:32 JST 1993
7
8 Copyright (C) 1993-2008 Yukihiro Matsumoto
9 Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
10 Copyright (C) 2000 Information-technology Promotion Agency, Japan
11
12 **********************************************************************/
13
14 #ifndef RUBY_RUBY_H
15 #define RUBY_RUBY_H 1
16
17 #if defined(__cplusplus)
18 extern "C" {
19 #if 0
20 } /* satisfy cc-mode */
21 #endif
22 #endif
23
24 #include "ruby/config.h"
25 #ifdef RUBY_EXTCONF_H
26 #include RUBY_EXTCONF_H
27 #endif
28
29 #define NORETURN_STYLE_NEW 1
30 #ifndef NORETURN
31 # define NORETURN(x) x
32 #endif
33 #ifndef DEPRECATED
34 # define DEPRECATED(x) x
35 #endif
36 #ifndef NOINLINE
37 # define NOINLINE(x) x
38 #endif
39 #ifndef UNREACHABLE
40 # define UNREACHABLE /* unreachable */
41 #endif
42
43 #ifdef __GNUC__
44 #define PRINTF_ARGS(decl, string_index, first_to_check) \
45 decl __attribute__((format(printf, string_index, first_to_check)))
46 #else
47 #define PRINTF_ARGS(decl, string_index, first_to_check) decl
48 #endif
49
50 #ifdef HAVE_STRING_H
51 # include <string.h>
52 #else
53 # include <strings.h>
54 #endif
55
56 #ifdef HAVE_INTRINSICS_H
57 # include <intrinsics.h>
58 #endif
59
60 #ifdef HAVE_STDINT_H
61 # include <stdint.h>
62 #endif
63 #ifdef HAVE_INTTYPES_H
64 # include <inttypes.h>
65 #endif
66
67 #include <stdarg.h>
68 #include <stdio.h>
69
70 #include "defines.h"
71
72 #if defined __GNUC__ && __GNUC__ >= 4
73 #pragma GCC visibility push(default)
74 #endif
75
76 /* Make alloca work the best possible way. */
77 #ifdef __GNUC__
78 # ifndef atarist
79 # ifndef alloca
80 # define alloca __builtin_alloca
81 # endif
82 # endif /* atarist */
83 #else
84 # ifdef HAVE_ALLOCA_H
85 # include <alloca.h>
86 # else
87 # ifdef _AIX
88 #pragma alloca
89 # else
90 # ifndef alloca /* predefined by HP cc +Olibcalls */
91 void *alloca();
92 # endif
93 # endif /* AIX */
94 # endif /* HAVE_ALLOCA_H */
95 #endif /* __GNUC__ */
96
97 #if defined HAVE_UINTPTR_T && 0
98 typedef uintptr_t VALUE;
99 typedef uintptr_t ID;
100 # define SIGNED_VALUE intptr_t
101 # define SIZEOF_VALUE SIZEOF_UINTPTR_T
102 # undef PRI_VALUE_PREFIX
103 #elif SIZEOF_LONG == SIZEOF_VOIDP
104 typedef unsigned long VALUE;
105 typedef unsigned long ID;
106 # define SIGNED_VALUE long
107 # define SIZEOF_VALUE SIZEOF_LONG
108 # define PRI_VALUE_PREFIX "l"
109 #elif SIZEOF_LONG_LONG == SIZEOF_VOIDP
110 typedef unsigned LONG_LONG VALUE;
111 typedef unsigned LONG_LONG ID;
112 # define SIGNED_VALUE LONG_LONG
113 # define LONG_LONG_VALUE 1
114 # define SIZEOF_VALUE SIZEOF_LONG_LONG
115 # define PRI_VALUE_PREFIX PRI_LL_PREFIX
116 #else
117 # error ---->> ruby requires sizeof(void*) == sizeof(long) or sizeof(LONG_LONG) to be compiled. <<----
118 #endif
119
120 typedef char ruby_check_sizeof_int[SIZEOF_INT == sizeof(int) ? 1 : -1];
121 typedef char ruby_check_sizeof_long[SIZEOF_LONG == sizeof(long) ? 1 : -1];
122 #ifdef SIZEOF_LONG_LONG
123 typedef char ruby_check_sizeof_long_long[SIZEOF_LONG_LONG == sizeof(LONG_LONG) ? 1 : -1];
124 #endif
125 typedef char ruby_check_sizeof_voidp[SIZEOF_VOIDP == sizeof(void*) ? 1 : -1];
126
127 #ifndef PRI_INT_PREFIX
128 #define PRI_INT_PREFIX ""
129 #endif
130 #ifndef PRI_LONG_PREFIX
131 #define PRI_LONG_PREFIX "l"
132 #endif
133
134 #if defined PRIdPTR && !defined PRI_VALUE_PREFIX
135 #define PRIdVALUE PRIdPTR
136 #define PRIoVALUE PRIoPTR
137 #define PRIuVALUE PRIuPTR
138 #define PRIxVALUE PRIxPTR
139 #define PRIXVALUE PRIXPTR
140 #define PRIsVALUE PRIiPTR
141 #else
142 #define PRIdVALUE PRI_VALUE_PREFIX"d"
143 #define PRIoVALUE PRI_VALUE_PREFIX"o"
144 #define PRIuVALUE PRI_VALUE_PREFIX"u"
145 #define PRIxVALUE PRI_VALUE_PREFIX"x"
146 #define PRIXVALUE PRI_VALUE_PREFIX"X"
147 #define PRIsVALUE PRI_VALUE_PREFIX"i"
148 #endif
149 #ifndef PRI_VALUE_PREFIX
150 # define PRI_VALUE_PREFIX ""
151 #endif
152
153 #ifndef PRI_TIMET_PREFIX
154 # if SIZEOF_TIME_T == SIZEOF_INT
155 # define PRI_TIMET_PREFIX
156 # elif SIZEOF_TIME_T == SIZEOF_LONG
157 # define PRI_TIMET_PREFIX "l"
158 # elif SIZEOF_TIME_T == SIZEOF_LONG_LONG
159 # define PRI_TIMET_PREFIX PRI_LL_PREFIX
160 # endif
161 #endif
162
163 #if defined PRI_PTRDIFF_PREFIX
164 #elif SIZEOF_PTRDIFF_T == SIZEOF_INT
165 # define PRI_PTRDIFF_PREFIX ""
166 #elif SIZEOF_PTRDIFF_T == SIZEOF_LONG
167 # define PRI_PTRDIFF_PREFIX "l"
168 #elif SIZEOF_PTRDIFF_T == SIZEOF_LONG_LONG
169 # define PRI_PTRDIFF_PREFIX PRI_LL_PREFIX
170 #endif
171 #define PRIdPTRDIFF PRI_PTRDIFF_PREFIX"d"
172 #define PRIiPTRDIFF PRI_PTRDIFF_PREFIX"i"
173 #define PRIoPTRDIFF PRI_PTRDIFF_PREFIX"o"
174 #define PRIuPTRDIFF PRI_PTRDIFF_PREFIX"u"
175 #define PRIxPTRDIFF PRI_PTRDIFF_PREFIX"x"
176 #define PRIXPTRDIFF PRI_PTRDIFF_PREFIX"X"
177
178 #if defined PRI_SIZE_PREFIX
179 #elif SIZEOF_SIZE_T == SIZEOF_INT
180 # define PRI_SIZE_PREFIX ""
181 #elif SIZEOF_SIZE_T == SIZEOF_LONG
182 # define PRI_SIZE_PREFIX "l"
183 #elif SIZEOF_SIZE_T == SIZEOF_LONG_LONG
184 # define PRI_SIZE_PREFIX PRI_LL_PREFIX
185 #endif
186 #define PRIdSIZE PRI_SIZE_PREFIX"d"
187 #define PRIiSIZE PRI_SIZE_PREFIX"i"
188 #define PRIoSIZE PRI_SIZE_PREFIX"o"
189 #define PRIuSIZE PRI_SIZE_PREFIX"u"
190 #define PRIxSIZE PRI_SIZE_PREFIX"x"
191 #define PRIXSIZE PRI_SIZE_PREFIX"X"
192
193 #ifdef __STDC__
194 # include <limits.h>
195 #else
196 # ifndef LONG_MAX
197 # ifdef HAVE_LIMITS_H
198 # include <limits.h>
199 # else
200 /* assuming 32bit(2's compliment) long */
201 # define LONG_MAX 2147483647
202 # endif
203 # endif
204 # ifndef LONG_MIN
205 # define LONG_MIN (-LONG_MAX-1)
206 # endif
207 # ifndef CHAR_BIT
208 # define CHAR_BIT 8
209 # endif
210 #endif
211
212 #ifdef HAVE_LONG_LONG
213 # ifndef LLONG_MAX
214 # ifdef LONG_LONG_MAX
215 # define LLONG_MAX LONG_LONG_MAX
216 # else
217 # ifdef _I64_MAX
218 # define LLONG_MAX _I64_MAX
219 # else
220 /* assuming 64bit(2's complement) long long */
221 # define LLONG_MAX 9223372036854775807LL
222 # endif
223 # endif
224 # endif
225 # ifndef LLONG_MIN
226 # ifdef LONG_LONG_MIN
227 # define LLONG_MIN LONG_LONG_MIN
228 # else
229 # ifdef _I64_MIN
230 # define LLONG_MIN _I64_MIN
231 # else
232 # define LLONG_MIN (-LLONG_MAX-1)
233 # endif
234 # endif
235 # endif
236 #endif
237
238 #define FIXNUM_MAX (LONG_MAX>>1)
239 #define FIXNUM_MIN RSHIFT((long)LONG_MIN,1)
240
241 #define INT2FIX(i) ((VALUE)(((SIGNED_VALUE)(i))<<1 | FIXNUM_FLAG))
242 #define LONG2FIX(i) INT2FIX(i)
243 #define rb_fix_new(v) INT2FIX(v)
244 VALUE rb_int2inum(SIGNED_VALUE);
245
246 #define rb_int_new(v) rb_int2inum(v)
247 VALUE rb_uint2inum(VALUE);
248
249 #define rb_uint_new(v) rb_uint2inum(v)
250
251 #ifdef HAVE_LONG_LONG
252 VALUE rb_ll2inum(LONG_LONG);
253 #define LL2NUM(v) rb_ll2inum(v)
254 VALUE rb_ull2inum(unsigned LONG_LONG);
255 #define ULL2NUM(v) rb_ull2inum(v)
256 #endif
257
258 #if SIZEOF_OFF_T > SIZEOF_LONG && defined(HAVE_LONG_LONG)
259 # define OFFT2NUM(v) LL2NUM(v)
260 #elif SIZEOF_OFF_T == SIZEOF_LONG
261 # define OFFT2NUM(v) LONG2NUM(v)
262 #else
263 # define OFFT2NUM(v) INT2NUM(v)
264 #endif
265
266 #if SIZEOF_SIZE_T > SIZEOF_LONG && defined(HAVE_LONG_LONG)
267 # define SIZET2NUM(v) ULL2NUM(v)
268 # define SSIZET2NUM(v) LL2NUM(v)
269 #elif SIZEOF_SIZE_T == SIZEOF_LONG
270 # define SIZET2NUM(v) ULONG2NUM(v)
271 # define SSIZET2NUM(v) LONG2NUM(v)
272 #else
273 # define SIZET2NUM(v) UINT2NUM(v)
274 # define SSIZET2NUM(v) INT2NUM(v)
275 #endif
276
277 #ifndef SIZE_MAX
278 # if SIZEOF_SIZE_T > SIZEOF_LONG && defined(HAVE_LONG_LONG)
279 # define SIZE_MAX ULLONG_MAX
280 # define SIZE_MIN ULLONG_MIN
281 # elif SIZEOF_SIZE_T == SIZEOF_LONG
282 # define SIZE_MAX ULONG_MAX
283 # define SIZE_MIN ULONG_MIN
284 # elif SIZEOF_SIZE_T == SIZEOF_INT
285 # define SIZE_MAX UINT_MAX
286 # define SIZE_MIN UINT_MIN
287 # else
288 # define SIZE_MAX USHRT_MAX
289 # define SIZE_MIN USHRT_MIN
290 # endif
291 #endif
292
293 #ifndef SSIZE_MAX
294 # if SIZEOF_SIZE_T > SIZEOF_LONG && defined(HAVE_LONG_LONG)
295 # define SSIZE_MAX LLONG_MAX
296 # define SSIZE_MIN LLONG_MIN
297 # elif SIZEOF_SIZE_T == SIZEOF_LONG
298 # define SSIZE_MAX LONG_MAX
299 # define SSIZE_MIN LONG_MIN
300 # elif SIZEOF_SIZE_T == SIZEOF_INT
301 # define SSIZE_MAX INT_MAX
302 # define SSIZE_MIN INT_MIN
303 # else
304 # define SSIZE_MAX SHRT_MAX
305 # define SSIZE_MIN SHRT_MIN
306 # endif
307 #endif
308
309 #if SIZEOF_INT < SIZEOF_VALUE
310 NORETURN(void rb_out_of_int(SIGNED_VALUE num));
311 #endif
312
313 #if SIZEOF_INT < SIZEOF_LONG
314 static inline int
315 rb_long2int_inline(long n)
316 {
317 int i = (int)n;
318 if ((long)i != n)
319 rb_out_of_int(n);
320
321 return i;
322 }
323 #define rb_long2int(n) rb_long2int_inline(n)
324 #else
325 #define rb_long2int(n) ((int)(n))
326 #endif
327
328 #ifndef PIDT2NUM
329 #define PIDT2NUM(v) LONG2NUM(v)
330 #endif
331 #ifndef NUM2PIDT
332 #define NUM2PIDT(v) NUM2LONG(v)
333 #endif
334 #ifndef UIDT2NUM
335 #define UIDT2NUM(v) LONG2NUM(v)
336 #endif
337 #ifndef NUM2UIDT
338 #define NUM2UIDT(v) NUM2LONG(v)
339 #endif
340 #ifndef GIDT2NUM
341 #define GIDT2NUM(v) LONG2NUM(v)
342 #endif
343 #ifndef NUM2GIDT
344 #define NUM2GIDT(v) NUM2LONG(v)
345 #endif
346 #ifndef NUM2MODET
347 #define NUM2MODET(v) NUM2INT(v)
348 #endif
349 #ifndef MODET2NUM
350 #define MODET2NUM(v) INT2NUM(v)
351 #endif
352
353 #define FIX2LONG(x) (long)RSHIFT((SIGNED_VALUE)(x),1)
354 #define FIX2ULONG(x) ((((VALUE)(x))>>1)&LONG_MAX)
355 #define FIXNUM_P(f) (((int)(SIGNED_VALUE)(f))&FIXNUM_FLAG)
356 #define POSFIXABLE(f) ((f) < FIXNUM_MAX+1)
357 #define NEGFIXABLE(f) ((f) >= FIXNUM_MIN)
358 #define FIXABLE(f) (POSFIXABLE(f) && NEGFIXABLE(f))
359
360 #define IMMEDIATE_P(x) ((VALUE)(x) & IMMEDIATE_MASK)
361
362 #define SYMBOL_P(x) (((VALUE)(x)&~(~(VALUE)0<<RUBY_SPECIAL_SHIFT))==SYMBOL_FLAG)
363 #define ID2SYM(x) (((VALUE)(x)<<RUBY_SPECIAL_SHIFT)|SYMBOL_FLAG)
364 #define SYM2ID(x) RSHIFT((unsigned long)(x),RUBY_SPECIAL_SHIFT)
365
366 #ifndef USE_FLONUM
367 #if SIZEOF_VALUE >= SIZEOF_DOUBLE
368 #define USE_FLONUM 1
369 #else
370 #define USE_FLONUM 0
371 #endif
372 #endif
373
374 #if USE_FLONUM
375 #define FLONUM_P(x) ((((int)(SIGNED_VALUE)(x))&FLONUM_MASK) == FLONUM_FLAG)
376 #else
377 #define FLONUM_P(x) 0
378 #endif
379
380 /* Module#methods, #singleton_methods and so on return Symbols */
381 #define USE_SYMBOL_AS_METHOD_NAME 1
382
383 /*
384 !USE_FLONUM
385 -------------------------
386 ...xxxx xxx1 Fixnum
387 ...0000 1110 Symbol
388 ...0000 0000 Qfalse
389 ...0000 0010 Qtrue
390 ...0000 0100 Qnil
391 ...0000 0110 Qundef
392
393 USE_FLONUM
394 -------------------------
395 ...xxxx xxx1 Fixnum
396 ...xxxx xx10 Flonum
397 ...0000 1100 Symbol
398 ...0000 0000 Qfalse 0x00 = 0
399 ...0000 1000 Qnil 0x08 = 8
400 ...0001 0100 Qtrue 0x14 = 20
401 ...0011 0100 Qundef 0x34 = 52
402 */
403
404 /* special constants - i.e. non-zero and non-fixnum constants */
405 enum ruby_special_consts {
406 #if USE_FLONUM
407 RUBY_Qfalse = 0x00,
408 RUBY_Qtrue = 0x14,
409 RUBY_Qnil = 0x08,
410 RUBY_Qundef = 0x34,
411
412 RUBY_IMMEDIATE_MASK = 0x07,
413 RUBY_FIXNUM_FLAG = 0x01,
414 RUBY_FLONUM_MASK = 0x03,
415 RUBY_FLONUM_FLAG = 0x02,
416 RUBY_SYMBOL_FLAG = 0x0c,
417 RUBY_SPECIAL_SHIFT = 8
418 #else
419 RUBY_Qfalse = 0,
420 RUBY_Qtrue = 2,
421 RUBY_Qnil = 4,
422 RUBY_Qundef = 6,
423
424 RUBY_IMMEDIATE_MASK = 0x03,
425 RUBY_FIXNUM_FLAG = 0x01,
426 RUBY_FLONUM_MASK = 0x00, /* any values ANDed with FLONUM_MASK cannot be FLONUM_FLAG */
427 RUBY_FLONUM_FLAG = 0x02,
428 RUBY_SYMBOL_FLAG = 0x0e,
429 RUBY_SPECIAL_SHIFT = 8
430 #endif
431 };
432
433 #define Qfalse ((VALUE)RUBY_Qfalse)
434 #define Qtrue ((VALUE)RUBY_Qtrue)
435 #define Qnil ((VALUE)RUBY_Qnil)
436 #define Qundef ((VALUE)RUBY_Qundef) /* undefined value for placeholder */
437 #define IMMEDIATE_MASK RUBY_IMMEDIATE_MASK
438 #define FIXNUM_FLAG RUBY_FIXNUM_FLAG
439 #if USE_FLONUM
440 #define FLONUM_MASK RUBY_FLONUM_MASK
441 #define FLONUM_FLAG RUBY_FLONUM_FLAG
442 #endif
443 #define SYMBOL_FLAG RUBY_SYMBOL_FLAG
444
445 #define RTEST(v) !(((VALUE)(v) & ~Qnil) == 0)
446 #define NIL_P(v) !((VALUE)(v) != Qnil)
447
448 #define CLASS_OF(v) rb_class_of((VALUE)(v))
449
450 enum ruby_value_type {
451 RUBY_T_NONE = 0x00,
452
453 RUBY_T_OBJECT = 0x01,
454 RUBY_T_CLASS = 0x02,
455 RUBY_T_MODULE = 0x03,
456 RUBY_T_FLOAT = 0x04,
457 RUBY_T_STRING = 0x05,
458 RUBY_T_REGEXP = 0x06,
459 RUBY_T_ARRAY = 0x07,
460 RUBY_T_HASH = 0x08,
461 RUBY_T_STRUCT = 0x09,
462 RUBY_T_BIGNUM = 0x0a,
463 RUBY_T_FILE = 0x0b,
464 RUBY_T_DATA = 0x0c,
465 RUBY_T_MATCH = 0x0d,
466 RUBY_T_COMPLEX = 0x0e,
467 RUBY_T_RATIONAL = 0x0f,
468
469 RUBY_T_NIL = 0x11,
470 RUBY_T_TRUE = 0x12,
471 RUBY_T_FALSE = 0x13,
472 RUBY_T_SYMBOL = 0x14,
473 RUBY_T_FIXNUM = 0x15,
474
475 RUBY_T_UNDEF = 0x1b,
476 RUBY_T_NODE = 0x1c,
477 RUBY_T_ICLASS = 0x1d,
478 RUBY_T_ZOMBIE = 0x1e,
479
480 RUBY_T_MASK = 0x1f
481 };
482
483 #define T_NONE RUBY_T_NONE
484 #define T_NIL RUBY_T_NIL
485 #define T_OBJECT RUBY_T_OBJECT
486 #define T_CLASS RUBY_T_CLASS
487 #define T_ICLASS RUBY_T_ICLASS
488 #define T_MODULE RUBY_T_MODULE
489 #define T_FLOAT RUBY_T_FLOAT
490 #define T_STRING RUBY_T_STRING
491 #define T_REGEXP RUBY_T_REGEXP
492 #define T_ARRAY RUBY_T_ARRAY
493 #define T_HASH RUBY_T_HASH
494 #define T_STRUCT RUBY_T_STRUCT
495 #define T_BIGNUM RUBY_T_BIGNUM
496 #define T_FILE RUBY_T_FILE
497 #define T_FIXNUM RUBY_T_FIXNUM
498 #define T_TRUE RUBY_T_TRUE
499 #define T_FALSE RUBY_T_FALSE
500 #define T_DATA RUBY_T_DATA
501 #define T_MATCH RUBY_T_MATCH
502 #define T_SYMBOL RUBY_T_SYMBOL
503 #define T_RATIONAL RUBY_T_RATIONAL
504 #define T_COMPLEX RUBY_T_COMPLEX
505 #define T_UNDEF RUBY_T_UNDEF
506 #define T_NODE RUBY_T_NODE
507 #define T_ZOMBIE RUBY_T_ZOMBIE
508 #define T_MASK RUBY_T_MASK
509
510 #define BUILTIN_TYPE(x) (int)(((struct RBasic*)(x))->flags & T_MASK)
511
512 static inline int rb_type(VALUE obj);
513 #define TYPE(x) rb_type((VALUE)(x))
514
515 /* RB_GC_GUARD_PTR() is an intermediate macro, and has no effect by
516 * itself. don't use it directly */
517 #ifdef __GNUC__
518 #define RB_GC_GUARD_PTR(ptr) \
519 __extension__ ({volatile VALUE *rb_gc_guarded_ptr = (ptr); rb_gc_guarded_ptr;})
520 #else
521 #ifdef _MSC_VER
522 #pragma optimize("", off)
523 #endif
524 static inline volatile VALUE *rb_gc_guarded_ptr(volatile VALUE *ptr) {return ptr;}
525 #ifdef _MSC_VER
526 #pragma optimize("", on)
527 #endif
528 #define RB_GC_GUARD_PTR(ptr) rb_gc_guarded_ptr(ptr)
529 #endif
530 #define RB_GC_GUARD(v) (*RB_GC_GUARD_PTR(&(v)))
531
532 #ifdef __GNUC__
533 #define RB_UNUSED_VAR(x) x __attribute__ ((unused))
534 #else
535 #define RB_UNUSED_VAR(x) x
536 #endif
537
538 void rb_check_type(VALUE,int);
539 #define Check_Type(v,t) rb_check_type((VALUE)(v),(t))
540
541 VALUE rb_str_to_str(VALUE);
542 VALUE rb_string_value(volatile VALUE*);
543 char *rb_string_value_ptr(volatile VALUE*);
544 char *rb_string_value_cstr(volatile VALUE*);
545
546 #define StringValue(v) rb_string_value(&(v))
547 #define StringValuePtr(v) rb_string_value_ptr(&(v))
548 #define StringValueCStr(v) rb_string_value_cstr(&(v))
549
550 void rb_check_safe_obj(VALUE);
551 DEPRECATED(void rb_check_safe_str(VALUE));
552 #define SafeStringValue(v) do {\
553 StringValue(v);\
554 rb_check_safe_obj(v);\
555 } while (0)
556 /* obsolete macro - use SafeStringValue(v) */
557 #define Check_SafeStr(v) rb_check_safe_str((VALUE)(v))
558
559 VALUE rb_str_export(VALUE);
560 #define ExportStringValue(v) do {\
561 SafeStringValue(v);\
562 (v) = rb_str_export(v);\
563 } while (0)
564 VALUE rb_str_export_locale(VALUE);
565
566 VALUE rb_get_path(VALUE);
567 #define FilePathValue(v) (RB_GC_GUARD(v) = rb_get_path(v))
568
569 VALUE rb_get_path_no_checksafe(VALUE);
570 #define FilePathStringValue(v) ((v) = rb_get_path_no_checksafe(v))
571
572 void rb_secure(int);
573 int rb_safe_level(void);
574 void rb_set_safe_level(int);
575 void rb_set_safe_level_force(int);
576 void rb_secure_update(VALUE);
577 NORETURN(void rb_insecure_operation(void));
578
579 VALUE rb_errinfo(void);
580 void rb_set_errinfo(VALUE);
581
582 SIGNED_VALUE rb_num2long(VALUE);
583 VALUE rb_num2ulong(VALUE);
584 static inline long
585 rb_num2long_inline(VALUE x)
586 {
587 if (FIXNUM_P(x))
588 return FIX2LONG(x);
589 else
590 return (long)rb_num2long(x);
591 }
592 #define NUM2LONG(x) rb_num2long_inline(x)
593 static inline unsigned long
594 rb_num2ulong_inline(VALUE x)
595 {
596 if (FIXNUM_P(x))
597 return (unsigned long)FIX2LONG(x);
598 else
599 return (unsigned long)rb_num2ulong(x);
600 }
601 #define NUM2ULONG(x) rb_num2ulong_inline(x)
602 #if SIZEOF_INT < SIZEOF_LONG
603 long rb_num2int(VALUE);
604 long rb_fix2int(VALUE);
605 #define FIX2INT(x) ((int)rb_fix2int((VALUE)(x)))
606
607 static inline int
608 rb_num2int_inline(VALUE x)
609 {
610 if (FIXNUM_P(x))
611 return FIX2INT(x);
612 else
613 return (int)rb_num2int(x);
614 }
615 #define NUM2INT(x) rb_num2int_inline(x)
616
617 unsigned long rb_num2uint(VALUE);
618 #define NUM2UINT(x) ((unsigned int)rb_num2uint(x))
619 unsigned long rb_fix2uint(VALUE);
620 #define FIX2UINT(x) ((unsigned int)rb_fix2uint(x))
621 #else /* SIZEOF_INT < SIZEOF_LONG */
622 #define NUM2INT(x) ((int)NUM2LONG(x))
623 #define NUM2UINT(x) ((unsigned int)NUM2ULONG(x))
624 #define FIX2INT(x) ((int)FIX2LONG(x))
625 #define FIX2UINT(x) ((unsigned int)FIX2ULONG(x))
626 #endif /* SIZEOF_INT < SIZEOF_LONG */
627
628 short rb_num2short(VALUE);
629 unsigned short rb_num2ushort(VALUE);
630 short rb_fix2short(VALUE);
631 unsigned short rb_fix2ushort(VALUE);
632 #define FIX2SHORT(x) (rb_fix2short((VALUE)(x)))
633 static inline short
634 rb_num2short_inline(VALUE x)
635 {
636 if (FIXNUM_P(x))
637 return FIX2SHORT(x);
638 else
639 return rb_num2short(x);
640 }
641
642 #define NUM2SHORT(x) rb_num2short_inline(x)
643 #define NUM2USHORT(x) rb_num2ushort(x)
644
645 #ifdef HAVE_LONG_LONG
646 LONG_LONG rb_num2ll(VALUE);
647 unsigned LONG_LONG rb_num2ull(VALUE);
648 static inline LONG_LONG
649 rb_num2ll_inline(VALUE x)
650 {
651 if (FIXNUM_P(x))
652 return FIX2LONG(x);
653 else
654 return rb_num2ll(x);
655 }
656 # define NUM2LL(x) rb_num2ll_inline(x)
657 # define NUM2ULL(x) rb_num2ull(x)
658 #endif
659
660 #if defined(HAVE_LONG_LONG) && SIZEOF_OFF_T > SIZEOF_LONG
661 # define NUM2OFFT(x) ((off_t)NUM2LL(x))
662 #else
663 # define NUM2OFFT(x) NUM2LONG(x)
664 #endif
665
666 #if defined(HAVE_LONG_LONG) && SIZEOF_SIZE_T > SIZEOF_LONG
667 # define NUM2SIZET(x) ((size_t)NUM2ULL(x))
668 # define NUM2SSIZET(x) ((ssize_t)NUM2LL(x))
669 #else
670 # define NUM2SIZET(x) NUM2ULONG(x)
671 # define NUM2SSIZET(x) NUM2LONG(x)
672 #endif
673
674 double rb_num2dbl(VALUE);
675 #define NUM2DBL(x) rb_num2dbl((VALUE)(x))
676
677 VALUE rb_uint2big(VALUE);
678 VALUE rb_int2big(SIGNED_VALUE);
679
680 VALUE rb_newobj(void);
681 VALUE rb_newobj_of(VALUE, VALUE);
682 #define NEWOBJ(obj,type) type *(obj) = (type*)rb_newobj()
683 #define NEWOBJ_OF(obj,type,klass,flags) type *(obj) = (type*)rb_newobj_of(klass, flags)
684 #define OBJSETUP(obj,c,t) do {\
685 RBASIC(obj)->flags = (t);\
686 RBASIC(obj)->klass = (c);\
687 if (rb_safe_level() >= 3) FL_SET((obj), FL_TAINT | FL_UNTRUSTED);\
688 } while (0)
689 #define CLONESETUP(clone,obj) do {\
690 OBJSETUP((clone),rb_singleton_class_clone((VALUE)(obj)),RBASIC(obj)->flags);\
691 rb_singleton_class_attached(RBASIC(clone)->klass, (VALUE)(clone));\
692 if (FL_TEST((obj), FL_EXIVAR)) rb_copy_generic_ivar((VALUE)(clone),(VALUE)(obj));\
693 } while (0)
694 #define DUPSETUP(dup,obj) do {\
695 OBJSETUP((dup),rb_obj_class(obj), (RBASIC(obj)->flags)&(T_MASK|FL_EXIVAR|FL_TAINT|FL_UNTRUSTED)); \
696 if (FL_TEST((obj), FL_EXIVAR)) rb_copy_generic_ivar((VALUE)(dup),(VALUE)(obj));\
697 } while (0)
698
699 struct RBasic {
700 VALUE flags;
701 VALUE klass;
702 }
703 #ifdef __GNUC__
704 __attribute__((aligned(sizeof(VALUE))))
705 #endif
706 ;
707
708 #define ROBJECT_EMBED_LEN_MAX 3
709 struct RObject {
710 struct RBasic basic;
711 union {
712 struct {
713 long numiv;
714 VALUE *ivptr;
715 struct st_table *iv_index_tbl; /* shortcut for RCLASS_IV_INDEX_TBL(rb_obj_class(obj)) */
716 } heap;
717 VALUE ary[ROBJECT_EMBED_LEN_MAX];
718 } as;
719 };
720 #define ROBJECT_EMBED FL_USER1
721 #define ROBJECT_NUMIV(o) \
722 ((RBASIC(o)->flags & ROBJECT_EMBED) ? \
723 ROBJECT_EMBED_LEN_MAX : \
724 ROBJECT(o)->as.heap.numiv)
725 #define ROBJECT_IVPTR(o) \
726 ((RBASIC(o)->flags & ROBJECT_EMBED) ? \
727 ROBJECT(o)->as.ary : \
728 ROBJECT(o)->as.heap.ivptr)
729 #define ROBJECT_IV_INDEX_TBL(o) \
730 ((RBASIC(o)->flags & ROBJECT_EMBED) ? \
731 RCLASS_IV_INDEX_TBL(rb_obj_class(o)) : \
732 ROBJECT(o)->as.heap.iv_index_tbl)
733
735 typedef struct rb_classext_struct rb_classext_t;
736
737 struct RClass {
738 struct RBasic basic;
739 rb_classext_t *ptr;
740 struct st_table *m_tbl;
741 struct st_table *iv_index_tbl;
742 };
743 #define RCLASS_SUPER(c) rb_class_get_superclass(c)
744 #define RMODULE_IV_TBL(m) RCLASS_IV_TBL(m)
745 #define RMODULE_CONST_TBL(m) RCLASS_CONST_TBL(m)
746 #define RMODULE_M_TBL(m) RCLASS_M_TBL(m)
747 #define RMODULE_SUPER(m) RCLASS_SUPER(m)
748 #define RMODULE_IS_OVERLAID FL_USER2
749 #define RMODULE_IS_REFINEMENT FL_USER3
750 #define RMODULE_INCLUDED_INTO_REFINEMENT FL_USER4
751
752 struct RFloat {
753 struct RBasic basic;
754 double float_value;
755 };
756
757 VALUE rb_float_new_in_heap(double);
758
759 #if USE_FLONUM
760 #define RUBY_BIT_ROTL(v, n) (((v) << (n)) | ((v) >> ((sizeof(v) * 8) - n)))
761 #define RUBY_BIT_ROTR(v, n) (((v) >> (n)) | ((v) << ((sizeof(v) * 8) - n)))
762
763 static inline double
764 rb_float_value(VALUE v)
765 {
766 if (FLONUM_P(v)) {
767 if (v != (VALUE)0x8000000000000002) { /* LIKELY */
768 union {
769 double d;
770 VALUE v;
771 } t;
772
773 VALUE b63 = (v >> 63);
774 /* e: xx1... -> 011... */
775 /* xx0... -> 100... */
776 /* ^b63 */
777 t.v = RUBY_BIT_ROTR((2 - b63) | (v & ~0x03), 3);
778 return t.d;
779 }
780 else {
781 return 0.0;
782 }
783 }
784 else {
785 return ((struct RFloat *)v)->float_value;
786 }
787 }
788
789 static inline VALUE
790 rb_float_new(double d)
791 {
792 union {
793 double d;
794 VALUE v;
795 } t;
796 int bits;
797
798 t.d = d;
799 bits = (int)((VALUE)(t.v >> 60) & 0x7);
800 /* bits contains 3 bits of b62..b60. */
801 /* bits - 3 = */
802 /* b011 -> b000 */
803 /* b100 -> b001 */
804
805 if (t.v != 0x3000000000000000 /* 1.72723e-77 */ &&
806 !((bits-3) & ~0x01)) {
807 return (RUBY_BIT_ROTL(t.v, 3) & ~(VALUE)0x01) | 0x02;
808 }
809 else {
810 if (t.v == (VALUE)0) {
811 /* +0.0 */
812 return 0x8000000000000002;
813 }
814 else {
815 /* out of range */
816 return rb_float_new_in_heap(d);
817 }
818 }
819 }
820
821 #else /* USE_FLONUM */
822
823 static inline double
824 rb_float_value(VALUE v)
825 {
826 return ((struct RFloat *)v)->float_value;
827 }
828
829 static inline VALUE
830 rb_float_new(double d)
831 {
832 return rb_float_new_in_heap(d);
833 }
834 #endif
835
836 #define RFLOAT_VALUE(v) rb_float_value(v)
837 #define DBL2NUM(dbl) rb_float_new(dbl)
838
839 #define ELTS_SHARED FL_USER2
840
841 #define RSTRING_EMBED_LEN_MAX ((int)((sizeof(VALUE)*3)/sizeof(char)-1))
842 struct RString {
843 struct RBasic basic;
844 union {
845 struct {
846 long len;
847 char *ptr;
848 union {
849 long capa;
850 VALUE shared;
851 } aux;
852 } heap;
853 char ary[RSTRING_EMBED_LEN_MAX + 1];
854 } as;
855 };
856 #define RSTRING_NOEMBED FL_USER1
857 #define RSTRING_EMBED_LEN_MASK (FL_USER2|FL_USER3|FL_USER4|FL_USER5|FL_USER6)
858 #define RSTRING_EMBED_LEN_SHIFT (FL_USHIFT+2)
859 #define RSTRING_EMBED_LEN(str) \
860 (long)((RBASIC(str)->flags >> RSTRING_EMBED_LEN_SHIFT) & \
861 (RSTRING_EMBED_LEN_MASK >> RSTRING_EMBED_LEN_SHIFT))
862 #define RSTRING_LEN(str) \
863 (!(RBASIC(str)->flags & RSTRING_NOEMBED) ? \
864 RSTRING_EMBED_LEN(str) : \
865 RSTRING(str)->as.heap.len)
866 #define RSTRING_PTR(str) \
867 (!(RBASIC(str)->flags & RSTRING_NOEMBED) ? \
868 RSTRING(str)->as.ary : \
869 RSTRING(str)->as.heap.ptr)
870 #define RSTRING_END(str) \
871 (!(RBASIC(str)->flags & RSTRING_NOEMBED) ? \
872 (RSTRING(str)->as.ary + RSTRING_EMBED_LEN(str)) : \
873 (RSTRING(str)->as.heap.ptr + RSTRING(str)->as.heap.len))
874 #define RSTRING_LENINT(str) rb_long2int(RSTRING_LEN(str))
875 #define RSTRING_GETMEM(str, ptrvar, lenvar) \
876 (!(RBASIC(str)->flags & RSTRING_NOEMBED) ? \
877 ((ptrvar) = RSTRING(str)->as.ary, (lenvar) = RSTRING_EMBED_LEN(str)) : \
878 ((ptrvar) = RSTRING(str)->as.heap.ptr, (lenvar) = RSTRING(str)->as.heap.len))
879
880 #define RARRAY_EMBED_LEN_MAX 3
881 struct RArray {
882 struct RBasic basic;
883 union {
884 struct {
885 long len;
886 union {
887 long capa;
888 VALUE shared;
889 } aux;
890 VALUE *ptr;
891 } heap;
892 VALUE ary[RARRAY_EMBED_LEN_MAX];
893 } as;
894 };
895 #define RARRAY_EMBED_FLAG FL_USER1
896 /* FL_USER2 is for ELTS_SHARED */
897 #define RARRAY_EMBED_LEN_MASK (FL_USER4|FL_USER3)
898 #define RARRAY_EMBED_LEN_SHIFT (FL_USHIFT+3)
899 #define RARRAY_LEN(a) \
900 ((RBASIC(a)->flags & RARRAY_EMBED_FLAG) ? \
901 (long)((RBASIC(a)->flags >> RARRAY_EMBED_LEN_SHIFT) & \
902 (RARRAY_EMBED_LEN_MASK >> RARRAY_EMBED_LEN_SHIFT)) : \
903 RARRAY(a)->as.heap.len)
904 #define RARRAY_PTR(a) \
905 ((RBASIC(a)->flags & RARRAY_EMBED_FLAG) ? \
906 RARRAY(a)->as.ary : \
907 RARRAY(a)->as.heap.ptr)
908 #define RARRAY_LENINT(ary) rb_long2int(RARRAY_LEN(ary))
909
910 struct RRegexp {
911 struct RBasic basic;
912 struct re_pattern_buffer *ptr;
913 VALUE src;
914 unsigned long usecnt;
915 };
916 #define RREGEXP_SRC(r) RREGEXP(r)->src
917 #define RREGEXP_SRC_PTR(r) RSTRING_PTR(RREGEXP(r)->src)
918 #define RREGEXP_SRC_LEN(r) RSTRING_LEN(RREGEXP(r)->src)
919 #define RREGEXP_SRC_END(r) RSTRING_END(RREGEXP(r)->src)
920
921 struct RHash {
922 struct RBasic basic;
923 struct st_table *ntbl; /* possibly 0 */
924 int iter_lev;
925 VALUE ifnone;
926 };
927 /* RHASH_TBL allocates st_table if not available. */
928 #define RHASH_TBL(h) rb_hash_tbl(h)
929 #define RHASH_ITER_LEV(h) (RHASH(h)->iter_lev)
930 #define RHASH_IFNONE(h) (RHASH(h)->ifnone)
931 #define RHASH_SIZE(h) (RHASH(h)->ntbl ? RHASH(h)->ntbl->num_entries : 0)
932 #define RHASH_EMPTY_P(h) (RHASH_SIZE(h) == 0)
933
934 struct RFile {
935 struct RBasic basic;
936 struct rb_io_t *fptr;
937 };
938
939 struct RRational {
940 struct RBasic basic;
941 VALUE num;
942 VALUE den;
943 };
944
945 struct RComplex {
946 struct RBasic basic;
947 VALUE real;
948 VALUE imag;
949 };
950
951 struct RData {
952 struct RBasic basic;
953 void (*dmark)(void*);
954 void (*dfree)(void*);
955 void *data;
956 };
957
958 typedef struct rb_data_type_struct rb_data_type_t;
959
960 struct rb_data_type_struct {
961 const char *wrap_struct_name;
962 struct {
963 void (*dmark)(void*);
964 void (*dfree)(void*);
965 size_t (*dsize)(const void *);
966 void *reserved[2]; /* For future extension.
967 This array *must* be filled with ZERO. */
968 } function;
969 const rb_data_type_t *parent;
970 void *data; /* This area can be used for any purpose
971 by a programmer who define the type. */
972 };
973
974 #define HAVE_TYPE_RB_DATA_TYPE_T 1
975 #define HAVE_RB_DATA_TYPE_T_FUNCTION 1
976 #define HAVE_RB_DATA_TYPE_T_PARENT 1
977
978 struct RTypedData {
979 struct RBasic basic;
980 const rb_data_type_t *type;
981 VALUE typed_flag; /* 1 or not */
982 void *data;
983 };
984
985 #define DATA_PTR(dta) (RDATA(dta)->data)
986
987 #define RTYPEDDATA_P(v) (RTYPEDDATA(v)->typed_flag == 1)
988 #define RTYPEDDATA_TYPE(v) (RTYPEDDATA(v)->type)
989 #define RTYPEDDATA_DATA(v) (RTYPEDDATA(v)->data)
990
991 /*
992 #define RUBY_DATA_FUNC(func) ((void (*)(void*))(func))
993 */
994 typedef void (*RUBY_DATA_FUNC)(void*);
995
996 VALUE rb_data_object_alloc(VALUE,void*,RUBY_DATA_FUNC,RUBY_DATA_FUNC);
997 VALUE rb_data_typed_object_alloc(VALUE klass, void *datap, const rb_data_type_t *);
998 int rb_typeddata_inherited_p(const rb_data_type_t *child, const rb_data_type_t *parent);
999 int rb_typeddata_is_kind_of(VALUE, const rb_data_type_t *);
1000 void *rb_check_typeddata(VALUE, const rb_data_type_t *);
1001 #define Check_TypedStruct(v,t) rb_check_typeddata((VALUE)(v),(t))
1002 #define RUBY_DEFAULT_FREE ((RUBY_DATA_FUNC)-1)
1003 #define RUBY_NEVER_FREE ((RUBY_DATA_FUNC)0)
1004 #define RUBY_TYPED_DEFAULT_FREE RUBY_DEFAULT_FREE
1005 #define RUBY_TYPED_NEVER_FREE RUBY_NEVER_FREE
1006
1007 #define Data_Wrap_Struct(klass,mark,free,sval)\
1008 rb_data_object_alloc((klass),(sval),(RUBY_DATA_FUNC)(mark),(RUBY_DATA_FUNC)(free))
1009
1010 #define Data_Make_Struct(klass,type,mark,free,sval) (\
1011 (sval) = ALLOC(type),\
1012 memset((sval), 0, sizeof(type)),\
1013 Data_Wrap_Struct((klass),(mark),(free),(sval))\
1014 )
1015
1016 #define TypedData_Wrap_Struct(klass,data_type,sval)\
1017 rb_data_typed_object_alloc((klass),(sval),(data_type))
1018
1019 #define TypedData_Make_Struct(klass, type, data_type, sval) (\
1020 (sval) = ALLOC(type),\
1021 memset((sval), 0, sizeof(type)),\
1022 TypedData_Wrap_Struct((klass),(data_type),(sval))\
1023 )
1024
1025 #define Data_Get_Struct(obj,type,sval) do {\
1026 Check_Type((obj), T_DATA); \
1027 (sval) = (type*)DATA_PTR(obj);\
1028 } while (0)
1029
1030 #define TypedData_Get_Struct(obj,type,data_type,sval) do {\
1031 (sval) = (type*)rb_check_typeddata((obj), (data_type)); \
1032 } while (0)
1033
1034 #define RSTRUCT_EMBED_LEN_MAX 3
1035 struct RStruct {
1036 struct RBasic basic;
1037 union {
1038 struct {
1039 long len;
1040 VALUE *ptr;
1041 } heap;
1042 VALUE ary[RSTRUCT_EMBED_LEN_MAX];
1043 } as;
1044 };
1045 #define RSTRUCT_EMBED_LEN_MASK (FL_USER2|FL_USER1)
1046 #define RSTRUCT_EMBED_LEN_SHIFT (FL_USHIFT+1)
1047 #define RSTRUCT_LEN(st) \
1048 ((RBASIC(st)->flags & RSTRUCT_EMBED_LEN_MASK) ? \
1049 (long)((RBASIC(st)->flags >> RSTRUCT_EMBED_LEN_SHIFT) & \
1050 (RSTRUCT_EMBED_LEN_MASK >> RSTRUCT_EMBED_LEN_SHIFT)) : \
1051 RSTRUCT(st)->as.heap.len)
1052 #define RSTRUCT_PTR(st) \
1053 ((RBASIC(st)->flags & RSTRUCT_EMBED_LEN_MASK) ? \
1054 RSTRUCT(st)->as.ary : \
1055 RSTRUCT(st)->as.heap.ptr)
1056 #define RSTRUCT_LENINT(st) rb_long2int(RSTRUCT_LEN(st))
1057
1058 #define RBIGNUM_EMBED_LEN_MAX ((int)((sizeof(VALUE)*3)/sizeof(BDIGIT)))
1059 struct RBignum {
1060 struct RBasic basic;
1061 union {
1062 struct {
1063 long len;
1064 BDIGIT *digits;
1065 } heap;
1066 BDIGIT ary[RBIGNUM_EMBED_LEN_MAX];
1067 } as;
1068 };
1069 #define RBIGNUM_SIGN_BIT FL_USER1
1070 /* sign: positive:1, negative:0 */
1071 #define RBIGNUM_SIGN(b) ((RBASIC(b)->flags & RBIGNUM_SIGN_BIT) != 0)
1072 #define RBIGNUM_SET_SIGN(b,sign) \
1073 ((sign) ? (RBASIC(b)->flags |= RBIGNUM_SIGN_BIT) \
1074 : (RBASIC(b)->flags &= ~RBIGNUM_SIGN_BIT))
1075 #define RBIGNUM_POSITIVE_P(b) RBIGNUM_SIGN(b)
1076 #define RBIGNUM_NEGATIVE_P(b) (!RBIGNUM_SIGN(b))
1077
1078 #define RBIGNUM_EMBED_FLAG FL_USER2
1079 #define RBIGNUM_EMBED_LEN_MASK (FL_USER5|FL_USER4|FL_USER3)
1080 #define RBIGNUM_EMBED_LEN_SHIFT (FL_USHIFT+3)
1081 #define RBIGNUM_LEN(b) \
1082 ((RBASIC(b)->flags & RBIGNUM_EMBED_FLAG) ? \
1083 (long)((RBASIC(b)->flags >> RBIGNUM_EMBED_LEN_SHIFT) & \
1084 (RBIGNUM_EMBED_LEN_MASK >> RBIGNUM_EMBED_LEN_SHIFT)) : \
1085 RBIGNUM(b)->as.heap.len)
1086 /* LSB:RBIGNUM_DIGITS(b)[0], MSB:RBIGNUM_DIGITS(b)[RBIGNUM_LEN(b)-1] */
1087 #define RBIGNUM_DIGITS(b) \
1088 ((RBASIC(b)->flags & RBIGNUM_EMBED_FLAG) ? \
1089 RBIGNUM(b)->as.ary : \
1090 RBIGNUM(b)->as.heap.digits)
1091 #define RBIGNUM_LENINT(b) rb_long2int(RBIGNUM_LEN(b))
1092
1093 #define R_CAST(st) (struct st*)
1094 #define RBASIC(obj) (R_CAST(RBasic)(obj))
1095 #define ROBJECT(obj) (R_CAST(RObject)(obj))
1096 #define RCLASS(obj) (R_CAST(RClass)(obj))
1097 #define RMODULE(obj) RCLASS(obj)
1098 #define RFLOAT(obj) (R_CAST(RFloat)(obj))
1099 #define RSTRING(obj) (R_CAST(RString)(obj))
1100 #define RREGEXP(obj) (R_CAST(RRegexp)(obj))
1101 #define RARRAY(obj) (R_CAST(RArray)(obj))
1102 #define RHASH(obj) (R_CAST(RHash)(obj))
1103 #define RDATA(obj) (R_CAST(RData)(obj))
1104 #define RTYPEDDATA(obj) (R_CAST(RTypedData)(obj))
1105 #define RSTRUCT(obj) (R_CAST(RStruct)(obj))
1106 #define RBIGNUM(obj) (R_CAST(RBignum)(obj))
1107 #define RFILE(obj) (R_CAST(RFile)(obj))
1108 #define RRATIONAL(obj) (R_CAST(RRational)(obj))
1109 #define RCOMPLEX(obj) (R_CAST(RComplex)(obj))
1110
1111 #define FL_SINGLETON FL_USER0
1112 #define FL_RESERVED1 (((VALUE)1)<<5)
1113 #define FL_RESERVED2 (((VALUE)1)<<6) /* will be used in the future GC */
1114 #define FL_FINALIZE (((VALUE)1)<<7)
1115 #define FL_TAINT (((VALUE)1)<<8)
1116 #define FL_UNTRUSTED (((VALUE)1)<<9)
1117 #define FL_EXIVAR (((VALUE)1)<<10)
1118 #define FL_FREEZE (((VALUE)1)<<11)
1119
1120 #define FL_USHIFT 12
1121
1122 #define FL_USER0 (((VALUE)1)<<(FL_USHIFT+0))
1123 #define FL_USER1 (((VALUE)1)<<(FL_USHIFT+1))
1124 #define FL_USER2 (((VALUE)1)<<(FL_USHIFT+2))
1125 #define FL_USER3 (((VALUE)1)<<(FL_USHIFT+3))
1126 #define FL_USER4 (((VALUE)1)<<(FL_USHIFT+4))
1127 #define FL_USER5 (((VALUE)1)<<(FL_USHIFT+5))
1128 #define FL_USER6 (((VALUE)1)<<(FL_USHIFT+6))
1129 #define FL_USER7 (((VALUE)1)<<(FL_USHIFT+7))
1130 #define FL_USER8 (((VALUE)1)<<(FL_USHIFT+8))
1131 #define FL_USER9 (((VALUE)1)<<(FL_USHIFT+9))
1132 #define FL_USER10 (((VALUE)1)<<(FL_USHIFT+10))
1133 #define FL_USER11 (((VALUE)1)<<(FL_USHIFT+11))
1134 #define FL_USER12 (((VALUE)1)<<(FL_USHIFT+12))
1135 #define FL_USER13 (((VALUE)1)<<(FL_USHIFT+13))
1136 #define FL_USER14 (((VALUE)1)<<(FL_USHIFT+14))
1137 #define FL_USER15 (((VALUE)1)<<(FL_USHIFT+15))
1138 #define FL_USER16 (((VALUE)1)<<(FL_USHIFT+16))
1139 #define FL_USER17 (((VALUE)1)<<(FL_USHIFT+17))
1140 #define FL_USER18 (((VALUE)1)<<(FL_USHIFT+18))
1141 #define FL_USER19 (((VALUE)1)<<(FL_USHIFT+19))
1142
1143 #define SPECIAL_CONST_P(x) (IMMEDIATE_P(x) || !RTEST(x))
1144
1145 #define FL_ABLE(x) (!SPECIAL_CONST_P(x) && BUILTIN_TYPE(x) != T_NODE)
1146 #define FL_TEST(x,f) (FL_ABLE(x)?(RBASIC(x)->flags&(f)):0)
1147 #define FL_ANY(x,f) FL_TEST((x),(f))
1148 #define FL_ALL(x,f) (FL_TEST((x),(f)) == (f))
1149 #define FL_SET(x,f) do {if (FL_ABLE(x)) RBASIC(x)->flags |= (f);} while (0)
1150 #define FL_UNSET(x,f) do {if (FL_ABLE(x)) RBASIC(x)->flags &= ~(f);} while (0)
1151 #define FL_REVERSE(x,f) do {if (FL_ABLE(x)) RBASIC(x)->flags ^= (f);} while (0)
1152
1153 #define OBJ_TAINTED(x) (!!FL_TEST((x), FL_TAINT))
1154 #define OBJ_TAINT(x) FL_SET((x), FL_TAINT)
1155 #define OBJ_UNTRUSTED(x) (!!FL_TEST((x), FL_UNTRUSTED))
1156 #define OBJ_UNTRUST(x) FL_SET((x), FL_UNTRUSTED)
1157 #define OBJ_INFECT(x,s) do { \
1158 if (FL_ABLE(x) && FL_ABLE(s)) \
1159 RBASIC(x)->flags |= RBASIC(s)->flags & \
1160 (FL_TAINT | FL_UNTRUSTED); \
1161 } while (0)
1162
1163 #define OBJ_FROZEN(x) (!!(FL_ABLE(x)?(RBASIC(x)->flags&(FL_FREEZE)):(FIXNUM_P(x)||FLONUM_P(x))))
1164 #define OBJ_FREEZE(x) FL_SET((x), FL_FREEZE)
1165
1166 #if SIZEOF_INT < SIZEOF_LONG
1167 # define INT2NUM(v) INT2FIX((int)(v))
1168 # define UINT2NUM(v) LONG2FIX((unsigned int)(v))
1169 #else
1170 static inline VALUE
1171 rb_int2num_inline(int v)
1172 {
1173 if (FIXABLE(v))
1174 return INT2FIX(v);
1175 else
1176 return rb_int2big(v);
1177 }
1178 #define INT2NUM(x) rb_int2num_inline(x)
1179
1180 static inline VALUE
1181 rb_uint2num_inline(unsigned int v)
1182 {
1183 if (POSFIXABLE(v))
1184 return LONG2FIX(v);
1185 else
1186 return rb_uint2big(v);
1187 }
1188 #define UINT2NUM(x) rb_uint2num_inline(x)
1189 #endif
1190
1191 static inline VALUE
1192 rb_long2num_inline(long v)
1193 {
1194 if (FIXABLE(v))
1195 return LONG2FIX(v);
1196 else
1197 return rb_int2big(v);
1198 }
1199 #define LONG2NUM(x) rb_long2num_inline(x)
1200
1201 static inline VALUE
1202 rb_ulong2num_inline(unsigned long v)
1203 {
1204 if (POSFIXABLE(v))
1205 return LONG2FIX(v);
1206 else
1207 return rb_uint2big(v);
1208 }
1209 #define ULONG2NUM(x) rb_ulong2num_inline(x)
1210
1211 static inline char
1212 rb_num2char_inline(VALUE x)
1213 {
1214 if ((TYPE(x) == T_STRING) && (RSTRING_LEN(x)>=1))
1215 return RSTRING_PTR(x)[0];
1216 else
1217 return (char)(NUM2INT(x) & 0xff);
1218 }
1219 #define NUM2CHR(x) rb_num2char_inline(x)
1220
1221 #define CHR2FIX(x) INT2FIX((long)((x)&0xff))
1222
1223 #define ALLOC_N(type,n) ((type*)xmalloc2((n),sizeof(type)))
1224 #define ALLOC(type) ((type*)xmalloc(sizeof(type)))
1225 #define REALLOC_N(var,type,n) ((var)=(type*)xrealloc2((char*)(var),(n),sizeof(type)))
1226
1227 #define ALLOCA_N(type,n) ((type*)alloca(sizeof(type)*(n)))
1228
1229 void *rb_alloc_tmp_buffer(volatile VALUE *store, long len);
1230 void rb_free_tmp_buffer(volatile VALUE *store);
1231 /* allocates _n_ bytes temporary buffer and stores VALUE including it
1232 * in _v_. _n_ may be evaluated twice. */
1233 #ifdef C_ALLOCA
1234 # define ALLOCV(v, n) rb_alloc_tmp_buffer(&(v), (n))
1235 #else
1236 # define ALLOCV(v, n) ((n) < 1024 ? (RB_GC_GUARD(v) = 0, alloca(n)) : rb_alloc_tmp_buffer(&(v), (n)))
1237 #endif
1238 #define ALLOCV_N(type, v, n) ((type*)ALLOCV((v), sizeof(type)*(n)))
1239 #define ALLOCV_END(v) rb_free_tmp_buffer(&(v))
1240
1241 #define MEMZERO(p,type,n) memset((p), 0, sizeof(type)*(n))
1242 #define MEMCPY(p1,p2,type,n) memcpy((p1), (p2), sizeof(type)*(n))
1243 #define MEMMOVE(p1,p2,type,n) memmove((p1), (p2), sizeof(type)*(n))
1244 #define MEMCMP(p1,p2,type,n) memcmp((p1), (p2), sizeof(type)*(n))
1245
1246 void rb_obj_infect(VALUE,VALUE);
1247
1248 typedef int ruby_glob_func(const char*,VALUE, void*);
1249 void rb_glob(const char*,void(*)(const char*,VALUE,void*),VALUE);
1250 int ruby_glob(const char*,int,ruby_glob_func*,VALUE);
1251 int ruby_brace_glob(const char*,int,ruby_glob_func*,VALUE);
1252
1253 VALUE rb_define_class(const char*,VALUE);
1254 VALUE rb_define_module(const char*);
1255 VALUE rb_define_class_under(VALUE, const char*, VALUE);
1256 VALUE rb_define_module_under(VALUE, const char*);
1257
1258 void rb_include_module(VALUE,VALUE);
1259 void rb_extend_object(VALUE,VALUE);
1260 void rb_prepend_module(VALUE,VALUE);
1261
1262 struct rb_global_variable;
1263
1264 typedef VALUE rb_gvar_getter_t(ID id, void *data, struct rb_global_variable *gvar);
1265 typedef void rb_gvar_setter_t(VALUE val, ID id, void *data, struct rb_global_variable *gvar);
1266 typedef void rb_gvar_marker_t(VALUE *var);
1267
1268 VALUE rb_gvar_undef_getter(ID id, void *data, struct rb_global_variable *gvar);
1269 void rb_gvar_undef_setter(VALUE val, ID id, void *data, struct rb_global_variable *gvar);
1270 void rb_gvar_undef_marker(VALUE *var);
1271
1272 VALUE rb_gvar_val_getter(ID id, void *data, struct rb_global_variable *gvar);
1273 void rb_gvar_val_setter(VALUE val, ID id, void *data, struct rb_global_variable *gvar);
1274 void rb_gvar_val_marker(VALUE *var);
1275
1276 VALUE rb_gvar_var_getter(ID id, void *data, struct rb_global_variable *gvar);
1277 void rb_gvar_var_setter(VALUE val, ID id, void *data, struct rb_global_variable *gvar);
1278 void rb_gvar_var_marker(VALUE *var);
1279
1280 void rb_gvar_readonly_setter(VALUE val, ID id, void *data, struct rb_global_variable *gvar);
1281
1282 void rb_define_variable(const char*,VALUE*);
1283 void rb_define_virtual_variable(const char*,VALUE(*)(ANYARGS),void(*)(ANYARGS));
1284 void rb_define_hooked_variable(const char*,VALUE*,VALUE(*)(ANYARGS),void(*)(ANYARGS));
1285 void rb_define_readonly_variable(const char*,VALUE*);
1286 void rb_define_const(VALUE,const char*,VALUE);
1287 void rb_define_global_const(const char*,VALUE);
1288
1289 #define RUBY_METHOD_FUNC(func) ((VALUE (*)(ANYARGS))(func))
1290 void rb_define_method(VALUE,const char*,VALUE(*)(ANYARGS),int);
1291 void rb_define_module_function(VALUE,const char*,VALUE(*)(ANYARGS),int);
1292 void rb_define_global_function(const char*,VALUE(*)(ANYARGS),int);
1293
1294 void rb_undef_method(VALUE,const char*);
1295 void rb_define_alias(VALUE,const char*,const char*);
1296 void rb_define_attr(VALUE,const char*,int,int);
1297
1298 void rb_global_variable(VALUE*);
1299 void rb_gc_register_mark_object(VALUE);
1300 void rb_gc_register_address(VALUE*);
1301 void rb_gc_unregister_address(VALUE*);
1302
1303 ID rb_intern(const char*);
1304 ID rb_intern2(const char*, long);
1305 ID rb_intern_str(VALUE str);
1306 const char *rb_id2name(ID);
1307 ID rb_check_id(volatile VALUE *);
1308 ID rb_to_id(VALUE);
1309 VALUE rb_id2str(ID);
1310
1311 #define CONST_ID_CACHE(result, str) \
1312 { \
1313 static ID rb_intern_id_cache; \
1314 if (!rb_intern_id_cache) \
1315 rb_intern_id_cache = rb_intern2((str), (long)strlen(str)); \
1316 result rb_intern_id_cache; \
1317 }
1318 #define CONST_ID(var, str) \
1319 do CONST_ID_CACHE((var) =, (str)) while (0)
1320 #ifdef __GNUC__
1321 /* __builtin_constant_p and statement expression is available
1322 * since gcc-2.7.2.3 at least. */
1323 #define rb_intern(str) \
1324 (__builtin_constant_p(str) ? \
1325 __extension__ (CONST_ID_CACHE((ID), (str))) : \
1326 rb_intern(str))
1327 #define rb_intern_const(str) \
1328 (__builtin_constant_p(str) ? \
1329 __extension__ (rb_intern2((str), (long)strlen(str))) : \
1330 (rb_intern)(str))
1331 #else
1332 #define rb_intern_const(str) rb_intern2((str), (long)strlen(str))
1333 #endif
1334
1335 const char *rb_class2name(VALUE);
1336 const char *rb_obj_classname(VALUE);
1337
1338 void rb_p(VALUE);
1339
1340 VALUE rb_eval_string(const char*);
1341 VALUE rb_eval_string_protect(const char*, int*);
1342 VALUE rb_eval_string_wrap(const char*, int*);
1343 VALUE rb_funcall(VALUE, ID, int, ...);
1344 VALUE rb_funcall2(VALUE, ID, int, const VALUE*);
1345 VALUE rb_funcall3(VALUE, ID, int, const VALUE*);
1346 VALUE rb_funcall_passing_block(VALUE, ID, int, const VALUE*);
1347 VALUE rb_funcall_with_block(VALUE, ID, int, const VALUE*, VALUE);
1348 int rb_scan_args(int, const VALUE*, const char*, ...);
1349 VALUE rb_call_super(int, const VALUE*);
1350
1351 /* rb_scan_args() format allows ':' for optional hash */
1352 #define HAVE_RB_SCAN_ARGS_OPTIONAL_HASH 1
1353
1354 VALUE rb_gv_set(const char*, VALUE);
1355 VALUE rb_gv_get(const char*);
1356 VALUE rb_iv_get(VALUE, const char*);
1357 VALUE rb_iv_set(VALUE, const char*, VALUE);
1358
1359 VALUE rb_equal(VALUE,VALUE);
1360
1361 VALUE *rb_ruby_verbose_ptr(void);
1362 VALUE *rb_ruby_debug_ptr(void);
1363 #define ruby_verbose (*rb_ruby_verbose_ptr())
1364 #define ruby_debug (*rb_ruby_debug_ptr())
1365
1366 PRINTF_ARGS(NORETURN(void rb_raise(VALUE, const char*, ...)), 2, 3);
1367 PRINTF_ARGS(NORETURN(void rb_fatal(const char*, ...)), 1, 2);
1368 PRINTF_ARGS(NORETURN(void rb_bug(const char*, ...)), 1, 2);
1369 NORETURN(void rb_bug_errno(const char*, int));
1370 NORETURN(void rb_sys_fail(const char*));
1371 NORETURN(void rb_sys_fail_str(VALUE));
1372 NORETURN(void rb_mod_sys_fail(VALUE, const char*));
1373 NORETURN(void rb_mod_sys_fail_str(VALUE, VALUE));
1374 NORETURN(void rb_iter_break(void));
1375 NORETURN(void rb_iter_break_value(VALUE));
1376 NORETURN(void rb_exit(int));
1377 NORETURN(void rb_notimplement(void));
1378 VALUE rb_syserr_new(int, const char *);
1379 VALUE rb_syserr_new_str(int n, VALUE arg);
1380 NORETURN(void rb_syserr_fail(int, const char*));
1381 NORETURN(void rb_syserr_fail_str(int, VALUE));
1382 NORETURN(void rb_mod_syserr_fail(VALUE, int, const char*));
1383 NORETURN(void rb_mod_syserr_fail_str(VALUE, int, VALUE));
1384
1385 /* reports if `-W' specified */
1386 PRINTF_ARGS(void rb_warning(const char*, ...), 1, 2);
1387 PRINTF_ARGS(void rb_compile_warning(const char *, int, const char*, ...), 3, 4);
1388 PRINTF_ARGS(void rb_sys_warning(const char*, ...), 1, 2);
1389 /* reports always */
1390 PRINTF_ARGS(void rb_warn(const char*, ...), 1, 2);
1391 PRINTF_ARGS(void rb_compile_warn(const char *, int, const char*, ...), 3, 4);
1392
1393 typedef VALUE rb_block_call_func(VALUE, VALUE, int, VALUE*);
1394
1395 VALUE rb_each(VALUE);
1396 VALUE rb_yield(VALUE);
1397 VALUE rb_yield_values(int n, ...);
1398 VALUE rb_yield_values2(int n, const VALUE *argv);
1399 VALUE rb_yield_splat(VALUE);
1400 int rb_block_given_p(void);
1401 void rb_need_block(void);
1402 VALUE rb_iterate(VALUE(*)(VALUE),VALUE,VALUE(*)(ANYARGS),VALUE);
1403 VALUE rb_block_call(VALUE,ID,int,VALUE*,VALUE(*)(ANYARGS),VALUE);
1404 VALUE rb_rescue(VALUE(*)(ANYARGS),VALUE,VALUE(*)(ANYARGS),VALUE);
1405 VALUE rb_rescue2(VALUE(*)(ANYARGS),VALUE,VALUE(*)(ANYARGS),VALUE,...);
1406 VALUE rb_ensure(VALUE(*)(ANYARGS),VALUE,VALUE(*)(ANYARGS),VALUE);
1407 VALUE rb_catch(const char*,VALUE(*)(ANYARGS),VALUE);
1408 VALUE rb_catch_obj(VALUE,VALUE(*)(ANYARGS),VALUE);
1409 NORETURN(void rb_throw(const char*,VALUE));
1410 NORETURN(void rb_throw_obj(VALUE,VALUE));
1411
1412 VALUE rb_require(const char*);
1413
1414 RUBY_EXTERN VALUE rb_mKernel;
1415 RUBY_EXTERN VALUE rb_mComparable;
1416 RUBY_EXTERN VALUE rb_mEnumerable;
1417 RUBY_EXTERN VALUE rb_mErrno;
1418 RUBY_EXTERN VALUE rb_mFileTest;
1419 RUBY_EXTERN VALUE rb_mGC;
1420 RUBY_EXTERN VALUE rb_mMath;
1421 RUBY_EXTERN VALUE rb_mProcess;
1422 RUBY_EXTERN VALUE rb_mWaitReadable;
1423 RUBY_EXTERN VALUE rb_mWaitWritable;
1424
1425 RUBY_EXTERN VALUE rb_cBasicObject;
1426 RUBY_EXTERN VALUE rb_cObject;
1427 RUBY_EXTERN VALUE rb_cArray;
1428 RUBY_EXTERN VALUE rb_cBignum;
1429 RUBY_EXTERN VALUE rb_cBinding;
1430 RUBY_EXTERN VALUE rb_cClass;
1431 RUBY_EXTERN VALUE rb_cCont;
1432 RUBY_EXTERN VALUE rb_cDir;
1433 RUBY_EXTERN VALUE rb_cData;
1434 RUBY_EXTERN VALUE rb_cFalseClass;
1435 RUBY_EXTERN VALUE rb_cEncoding;
1436 RUBY_EXTERN VALUE rb_cEnumerator;
1437 RUBY_EXTERN VALUE rb_cFile;
1438 RUBY_EXTERN VALUE rb_cFixnum;
1439 RUBY_EXTERN VALUE rb_cFloat;
1440 RUBY_EXTERN VALUE rb_cHash;
1441 RUBY_EXTERN VALUE rb_cInteger;
1442 RUBY_EXTERN VALUE rb_cIO;
1443 RUBY_EXTERN VALUE rb_cMatch;
1444 RUBY_EXTERN VALUE rb_cMethod;
1445 RUBY_EXTERN VALUE rb_cModule;
1446 RUBY_EXTERN VALUE rb_cNameErrorMesg;
1447 RUBY_EXTERN VALUE rb_cNilClass;
1448 RUBY_EXTERN VALUE rb_cNumeric;
1449 RUBY_EXTERN VALUE rb_cProc;
1450 RUBY_EXTERN VALUE rb_cRandom;
1451 RUBY_EXTERN VALUE rb_cRange;
1452 RUBY_EXTERN VALUE rb_cRational;
1453 RUBY_EXTERN VALUE rb_cComplex;
1454 RUBY_EXTERN VALUE rb_cRegexp;
1455 RUBY_EXTERN VALUE rb_cStat;
1456 RUBY_EXTERN VALUE rb_cString;
1457 RUBY_EXTERN VALUE rb_cStruct;
1458 RUBY_EXTERN VALUE rb_cSymbol;
1459 RUBY_EXTERN VALUE rb_cThread;
1460 RUBY_EXTERN VALUE rb_cTime;
1461 RUBY_EXTERN VALUE rb_cTrueClass;
1462 RUBY_EXTERN VALUE rb_cUnboundMethod;
1463
1464 RUBY_EXTERN VALUE rb_eException;
1465 RUBY_EXTERN VALUE rb_eStandardError;
1466 RUBY_EXTERN VALUE rb_eSystemExit;
1467 RUBY_EXTERN VALUE rb_eInterrupt;
1468 RUBY_EXTERN VALUE rb_eSignal;
1469 RUBY_EXTERN VALUE rb_eFatal;
1470 RUBY_EXTERN VALUE rb_eArgError;
1471 RUBY_EXTERN VALUE rb_eEOFError;
1472 RUBY_EXTERN VALUE rb_eIndexError;
1473 RUBY_EXTERN VALUE rb_eStopIteration;
1474 RUBY_EXTERN VALUE rb_eKeyError;
1475 RUBY_EXTERN VALUE rb_eRangeError;
1476 RUBY_EXTERN VALUE rb_eIOError;
1477 RUBY_EXTERN VALUE rb_eRuntimeError;
1478 RUBY_EXTERN VALUE rb_eSecurityError;
1479 RUBY_EXTERN VALUE rb_eSystemCallError;
1480 RUBY_EXTERN VALUE rb_eThreadError;
1481 RUBY_EXTERN VALUE rb_eTypeError;
1482 RUBY_EXTERN VALUE rb_eZeroDivError;
1483 RUBY_EXTERN VALUE rb_eNotImpError;
1484 RUBY_EXTERN VALUE rb_eNoMemError;
1485 RUBY_EXTERN VALUE rb_eNoMethodError;
1486 RUBY_EXTERN VALUE rb_eFloatDomainError;
1487 RUBY_EXTERN VALUE rb_eLocalJumpError;
1488 RUBY_EXTERN VALUE rb_eSysStackError;
1489 RUBY_EXTERN VALUE rb_eRegexpError;
1490 RUBY_EXTERN VALUE rb_eEncodingError;
1491 RUBY_EXTERN VALUE rb_eEncCompatError;
1492
1493 RUBY_EXTERN VALUE rb_eScriptError;
1494 RUBY_EXTERN VALUE rb_eNameError;
1495 RUBY_EXTERN VALUE rb_eSyntaxError;
1496 RUBY_EXTERN VALUE rb_eLoadError;
1497
1498 RUBY_EXTERN VALUE rb_eMathDomainError;
1499
1500 RUBY_EXTERN VALUE rb_stdin, rb_stdout, rb_stderr;
1501
1502 static inline VALUE
1503 rb_class_of(VALUE obj)
1504 {
1505 if (IMMEDIATE_P(obj)) {
1506 if (FIXNUM_P(obj)) return rb_cFixnum;
1507 if (FLONUM_P(obj)) return rb_cFloat;
1508 if (obj == Qtrue) return rb_cTrueClass;
1509 if (SYMBOL_P(obj)) return rb_cSymbol;
1510 }
1511 else if (!RTEST(obj)) {
1512 if (obj == Qnil) return rb_cNilClass;
1513 if (obj == Qfalse) return rb_cFalseClass;
1514 }
1515 return RBASIC(obj)->klass;
1516 }
1517
1518 static inline int
1519 rb_type(VALUE obj)
1520 {
1521 if (IMMEDIATE_P(obj)) {
1522 if (FIXNUM_P(obj)) return T_FIXNUM;
1523 if (FLONUM_P(obj)) return T_FLOAT;
1524 if (obj == Qtrue) return T_TRUE;
1525 if (SYMBOL_P(obj)) return T_SYMBOL;
1526 if (obj == Qundef) return T_UNDEF;
1527 }
1528 else if (!RTEST(obj)) {
1529 if (obj == Qnil) return T_NIL;
1530 if (obj == Qfalse) return T_FALSE;
1531 }
1532 return BUILTIN_TYPE(obj);
1533 }
1534
1535 #define RB_FLOAT_TYPE_P(obj) (FLONUM_P(obj) || (!SPECIAL_CONST_P(obj) && BUILTIN_TYPE(obj) == T_FLOAT))
1536
1537 #define RB_TYPE_P(obj, type) ( \
1538 ((type) == T_FIXNUM) ? FIXNUM_P(obj) : \
1539 ((type) == T_TRUE) ? ((obj) == Qtrue) : \
1540 ((type) == T_FALSE) ? ((obj) == Qfalse) : \
1541 ((type) == T_NIL) ? ((obj) == Qnil) : \
1542 ((type) == T_UNDEF) ? ((obj) == Qundef) : \
1543 ((type) == T_SYMBOL) ? SYMBOL_P(obj) : \
1544 ((type) == T_FLOAT) ? RB_FLOAT_TYPE_P(obj) : \
1545 (!SPECIAL_CONST_P(obj) && BUILTIN_TYPE(obj) == (type)))
1546
1547 #ifdef __GNUC__
1548 #define rb_type_p(obj, type) \
1549 __extension__ (__builtin_constant_p(type) ? RB_TYPE_P((obj), (type)) : \
1550 rb_type(obj) == (type))
1551 #else
1552 #define rb_type_p(obj, type) (rb_type(obj) == (type))
1553 #endif
1554
1555 #ifdef __GNUC__
1556 #define rb_special_const_p(obj) \
1557 __extension__ ({VALUE special_const_obj = (obj); (int)(SPECIAL_CONST_P(special_const_obj) ? Qtrue : Qfalse);})
1558 #else
1559 static inline int
1560 rb_special_const_p(VALUE obj)
1561 {
1562 if (SPECIAL_CONST_P(obj)) return (int)Qtrue;
1563 return (int)Qfalse;
1564 }
1565 #endif
1566
1567 #include "ruby/missing.h"
1568 #include "ruby/intern.h"
1569
1570 #if defined(EXTLIB) && defined(USE_DLN_A_OUT)
1571 /* hook for external modules */
1572 static char *dln_libs_to_be_linked[] = { EXTLIB, 0 };
1573 #endif
1574
1575 #define RUBY_VM 1 /* YARV */
1576 #define HAVE_NATIVETHREAD
1577 int ruby_native_thread_p(void);
1578
1579 /* traditional set_trace_func events */
1580 #define RUBY_EVENT_NONE 0x0000
1581 #define RUBY_EVENT_LINE 0x0001
1582 #define RUBY_EVENT_CLASS 0x0002
1583 #define RUBY_EVENT_END 0x0004
1584 #define RUBY_EVENT_CALL 0x0008
1585 #define RUBY_EVENT_RETURN 0x0010
1586 #define RUBY_EVENT_C_CALL 0x0020
1587 #define RUBY_EVENT_C_RETURN 0x0040
1588 #define RUBY_EVENT_RAISE 0x0080
1589 #define RUBY_EVENT_ALL 0x00ff
1590
1591 /* for TracePoint extended events */
1592 #define RUBY_EVENT_B_CALL 0x0100
1593 #define RUBY_EVENT_B_RETURN 0x0200
1594 #define RUBY_EVENT_THREAD_BEGIN 0x0400
1595 #define RUBY_EVENT_THREAD_END 0x0800
1596 #define RUBY_EVENT_TRACEPOINT_ALL 0xFFFF
1597
1598 /* special events */
1599 #define RUBY_EVENT_SPECIFIED_LINE 0x10000
1600 #define RUBY_EVENT_SWITCH 0x20000
1601 #define RUBY_EVENT_COVERAGE 0x40000
1602
1603 typedef unsigned long rb_event_flag_t;
1604 typedef void (*rb_event_hook_func_t)(rb_event_flag_t evflag, VALUE data, VALUE self, ID mid, VALUE klass);
1605
1606 #define RB_EVENT_HOOKS_HAVE_CALLBACK_DATA 1
1607 void rb_add_event_hook(rb_event_hook_func_t func, rb_event_flag_t events, VALUE data);
1608 int rb_remove_event_hook(rb_event_hook_func_t func);
1609
1610 /* locale insensitive functions */
1611
1612 #define rb_isascii(c) ((unsigned long)(c) < 128)
1613 int rb_isalnum(int c);
1614 int rb_isalpha(int c);
1615 int rb_isblank(int c);
1616 int rb_iscntrl(int c);
1617 int rb_isdigit(int c);
1618 int rb_isgraph(int c);
1619 int rb_islower(int c);
1620 int rb_isprint(int c);
1621 int rb_ispunct(int c);
1622 int rb_isspace(int c);
1623 int rb_isupper(int c);
1624 int rb_isxdigit(int c);
1625 int rb_tolower(int c);
1626 int rb_toupper(int c);
1627
1628 #ifndef ISPRINT
1629 #define ISASCII(c) rb_isascii((unsigned char)(c))
1630 #undef ISPRINT
1631 #define ISPRINT(c) rb_isprint((unsigned char)(c))
1632 #define ISSPACE(c) rb_isspace((unsigned char)(c))
1633 #define ISUPPER(c) rb_isupper((unsigned char)(c))
1634 #define ISLOWER(c) rb_islower((unsigned char)(c))
1635 #define ISALNUM(c) rb_isalnum((unsigned char)(c))
1636 #define ISALPHA(c) rb_isalpha((unsigned char)(c))
1637 #define ISDIGIT(c) rb_isdigit((unsigned char)(c))
1638 #define ISXDIGIT(c) rb_isxdigit((unsigned char)(c))
1639 #endif
1640 #define TOUPPER(c) rb_toupper((unsigned char)(c))
1641 #define TOLOWER(c) rb_tolower((unsigned char)(c))
1642
1643 int st_strcasecmp(const char *s1, const char *s2);
1644 int st_strncasecmp(const char *s1, const char *s2, size_t n);
1645 #define STRCASECMP(s1, s2) (st_strcasecmp((s1), (s2)))
1646 #define STRNCASECMP(s1, s2, n) (st_strncasecmp((s1), (s2), (n)))
1647
1648 unsigned long ruby_strtoul(const char *str, char **endptr, int base);
1649 #define STRTOUL(str, endptr, base) (ruby_strtoul((str), (endptr), (base)))
1650
1651 #define InitVM(ext) {void InitVM_##ext(void);InitVM_##ext();}
1652
1653 PRINTF_ARGS(int ruby_snprintf(char *str, size_t n, char const *fmt, ...), 3, 4);
1654 int ruby_vsnprintf(char *str, size_t n, char const *fmt, va_list ap);
1655
1656 #ifndef RUBY_DONT_SUBST
1657 #include "ruby/subst.h"
1658 #endif
1659
1676 void ruby_sysinit(int *argc, char ***argv);
1677 void ruby_init(void);
1678 void* ruby_options(int argc, char** argv);
1679 int ruby_executable_node(void *n, int *status);
1680 int ruby_run_node(void *n);
1681
1682 /* version.c */
1683 void ruby_show_version(void);
1684 void ruby_show_copyright(void);
1685
1686
1689 #define RUBY_INIT_STACK \
1690 VALUE variable_in_this_stack_frame; \
1691 ruby_init_stack(&variable_in_this_stack_frame);
1692
1694 #ifdef __ia64
1695 void ruby_init_stack(volatile VALUE*, void*);
1696 #define ruby_init_stack(addr) ruby_init_stack((addr), rb_ia64_bsp())
1697 #else
1698 void ruby_init_stack(volatile VALUE*);
1699 #endif
1700 #define Init_stack(addr) ruby_init_stack(addr)
1701
1702 int ruby_setup(void);
1703 int ruby_cleanup(volatile int);
1704
1705 void ruby_finalize(void);
1706 NORETURN(void ruby_stop(int));
1707
1708 void ruby_set_stack_size(size_t);
1709 int ruby_stack_check(void);
1710 size_t ruby_stack_length(VALUE**);
1711
1712 int ruby_exec_node(void *n);
1713
1714 void ruby_script(const char* name);
1715 void ruby_set_script_name(VALUE name);
1716
1717 void ruby_prog_init(void);
1718 void ruby_set_argv(int, char**);
1719 void *ruby_process_options(int, char**);
1720 void ruby_init_loadpath(void);
1721 void ruby_incpush(const char*);
1722 void ruby_sig_finalize(void);
1723
1726 #if defined __GNUC__ && __GNUC__ >= 4
1727 #pragma GCC visibility pop
1728 #endif
1729
1730 #if defined(__cplusplus)
1731 #if 0
1732 { /* satisfy cc-mode */
1733 #endif
1734 } /* extern "C" { */
1735 #endif
1736 #endif /* RUBY_RUBY_H */
1737