Ruby 1.9.2p136(2010-12-25revision30365)

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

# include/ruby/ruby.h

Go to the documentation of this file.

    00001 /**********************************************************************
    00002
    00003   ruby/ruby.h -
    00004
    00005   $Author: yugui $
    00006   created at: Thu Jun 10 14:26:32 JST 1993
    00007
    00008   Copyright (C) 1993-2008 Yukihiro Matsumoto
    00009   Copyright (C) 2000  Network Applied Communication Laboratory, Inc.
    00010   Copyright (C) 2000  Information-technology Promotion Agency, Japan
    00011
    00012 **********************************************************************/
    00013
    00014 #ifndef RUBY_RUBY_H
    00015 #define RUBY_RUBY_H 1
    00016
    00017 #if defined(__cplusplus)
    00018 extern "C" {
    00019 #if 0
    00020 } /* satisfy cc-mode */
    00021 #endif
    00022 #endif
    00023
    00024 #ifndef RUBY_LIB_PREFIX
    00025 #include "ruby/config.h"
    00026 #ifdef RUBY_EXTCONF_H
    00027 #include RUBY_EXTCONF_H
    00028 #endif
    00029 #endif
    00030
    00031 #define NORETURN_STYLE_NEW 1
    00032 #ifndef NORETURN
    00033 # define NORETURN(x) x
    00034 #endif
    00035 #ifndef DEPRECATED
    00036 # define DEPRECATED(x) x
    00037 #endif
    00038 #ifndef NOINLINE
    00039 # define NOINLINE(x) x
    00040 #endif
    00041
    00042 #ifdef __GNUC__
    00043 #define PRINTF_ARGS(decl, string_index, first_to_check) \
    00044   decl __attribute__((format(printf, string_index, first_to_check)))
    00045 #else
    00046 #define PRINTF_ARGS(decl, string_index, first_to_check) decl
    00047 #endif
    00048
    00049 #ifdef HAVE_STDLIB_H
    00050 # include <stdlib.h>
    00051 #endif
    00052
    00053 #ifdef HAVE_STRING_H
    00054 # include <string.h>
    00055 #else
    00056 # include <strings.h>
    00057 #endif
    00058
    00059 #ifdef HAVE_INTRINSICS_H
    00060 # include <intrinsics.h>
    00061 #endif
    00062
    00063 #ifdef HAVE_STDINT_H
    00064 # include <stdint.h>
    00065 #endif
    00066 #ifdef HAVE_INTTYPES_H
    00067 # include <inttypes.h>
    00068 #endif
    00069
    00070 #include <stdarg.h>
    00071 #include <stddef.h>
    00072 #include <stdio.h>
    00073
    00074 #include "defines.h"
    00075
    00076 #if defined(HAVE_ALLOCA_H)
    00077 #include <alloca.h>
    00078 #else
    00079 #  ifdef _AIX
    00080 #pragma alloca
    00081 #  endif
    00082 #endif
    00083
    00084 #if defined HAVE_UINTPTR_T && 0
    00085 typedef uintptr_t VALUE;
    00086 typedef uintptr_t ID;
    00087 # define SIGNED_VALUE intptr_t
    00088 # define SIZEOF_VALUE SIZEOF_UINTPTR_T
    00089 # undef PRI_VALUE_PREFIX
    00090 #elif SIZEOF_LONG == SIZEOF_VOIDP
    00091 typedef unsigned long VALUE;
    00092 typedef unsigned long ID;
    00093 # define SIGNED_VALUE long
    00094 # define SIZEOF_VALUE SIZEOF_LONG
    00095 # define PRI_VALUE_PREFIX "l"
    00096 #elif SIZEOF_LONG_LONG == SIZEOF_VOIDP
    00097 typedef unsigned LONG_LONG VALUE;
    00098 typedef unsigned LONG_LONG ID;
    00099 # define SIGNED_VALUE LONG_LONG
    00100 # define LONG_LONG_VALUE 1
    00101 # define SIZEOF_VALUE SIZEOF_LONG_LONG
    00102 # define PRI_VALUE_PREFIX "ll"
    00103 #else
    00104 # error ---->> ruby requires sizeof(void*) == sizeof(long) to be compiled. <<----
    00105 #endif
    00106
    00107 typedef char ruby_check_sizeof_int[SIZEOF_INT == sizeof(int) ? 1 : -1];
    00108 typedef char ruby_check_sizeof_long[SIZEOF_LONG == sizeof(long) ? 1 : -1];
    00109 #ifdef SIZEOF_LONG_LONG
    00110 typedef char ruby_check_sizeof_long_long[SIZEOF_LONG_LONG == sizeof(LONG_LONG) ? 1 : -1];
    00111 #endif
    00112 typedef char ruby_check_sizeof_voidp[SIZEOF_VOIDP == sizeof(void*) ? 1 : -1];
    00113
    00114 #if defined PRIdPTR && !defined PRI_VALUE_PREFIX
    00115 #define PRIdVALUE PRIdPTR
    00116 #define PRIiVALUE PRIiPTR
    00117 #define PRIoVALUE PRIoPTR
    00118 #define PRIuVALUE PRIuPTR
    00119 #define PRIxVALUE PRIxPTR
    00120 #define PRIXVALUE PRIXPTR
    00121 #else
    00122 #define PRIdVALUE PRI_VALUE_PREFIX"d"
    00123 #define PRIiVALUE PRI_VALUE_PREFIX"i"
    00124 #define PRIoVALUE PRI_VALUE_PREFIX"o"
    00125 #define PRIuVALUE PRI_VALUE_PREFIX"u"
    00126 #define PRIxVALUE PRI_VALUE_PREFIX"x"
    00127 #define PRIXVALUE PRI_VALUE_PREFIX"X"
    00128 #endif
    00129 #ifndef PRI_VALUE_PREFIX
    00130 # define PRI_VALUE_PREFIX ""
    00131 #endif
    00132
    00133 #ifndef PRI_TIMET_PREFIX
    00134 # if SIZEOF_TIME_T == SIZEOF_INT
    00135 #  define PRI_TIMET_PREFIX
    00136 # elif SIZEOF_TIME_T == SIZEOF_LONG
    00137 #  define PRI_TIMET_PREFIX "l"
    00138 # elif SIZEOF_TIME_T == SIZEOF_LONG_LONG
    00139 #  define PRI_TIMET_PREFIX "ll"
    00140 # endif
    00141 #endif
    00142
    00143 #if defined PRIdPTR
    00144 # define PRI_PTRDIFF_PREFIX "t"
    00145 #elif SIZEOF_PTRDIFF_T == SIZEOF_INT
    00146 # define PRI_PTRDIFF_PREFIX
    00147 #elif SIZEOF_PTRDIFF_T == SIZEOF_LONG
    00148 # define PRI_PTRDIFF_PREFIX "l"
    00149 #elif SIZEOF_PTRDIFF_T == SIZEOF_LONG_LONG
    00150 # define PRI_PTRDIFF_PREFIX "ll"
    00151 #endif
    00152 #define PRIdPTRDIFF PRI_PTRDIFF_PREFIX"d"
    00153 #define PRIiPTRDIFF PRI_PTRDIFF_PREFIX"i"
    00154 #define PRIoPTRDIFF PRI_PTRDIFF_PREFIX"o"
    00155 #define PRIuPTRDIFF PRI_PTRDIFF_PREFIX"u"
    00156 #define PRIxPTRDIFF PRI_PTRDIFF_PREFIX"x"
    00157 #define PRIXPTRDIFF PRI_PTRDIFF_PREFIX"X"
    00158
    00159 #if defined PRIdPTR
    00160 # define PRI_SIZE_PREFIX "z"
    00161 #elif SIZEOF_SIZE_T == SIZEOF_INT
    00162 # define PRI_SIZE_PREFIX
    00163 #elif SIZEOF_SIZE_T == SIZEOF_LONG
    00164 # define PRI_SIZE_PREFIX "l"
    00165 #elif SIZEOF_SIZE_T == SIZEOF_LONG_LONG
    00166 # define PRI_SIZE_PREFIX "ll"
    00167 #endif
    00168 #define PRIdSIZE PRI_SIZE_PREFIX"d"
    00169 #define PRIiSIZE PRI_SIZE_PREFIX"i"
    00170 #define PRIoSIZE PRI_SIZE_PREFIX"o"
    00171 #define PRIuSIZE PRI_SIZE_PREFIX"u"
    00172 #define PRIxSIZE PRI_SIZE_PREFIX"x"
    00173 #define PRIXSIZE PRI_SIZE_PREFIX"X"
    00174
    00175 #ifdef __STDC__
    00176 # include <limits.h>
    00177 #else
    00178 # ifndef LONG_MAX
    00179 #  ifdef HAVE_LIMITS_H
    00180 #   include <limits.h>
    00181 #  else
    00182     /* assuming 32bit(2's compliment) long */
    00183 #   define LONG_MAX 2147483647
    00184 #  endif
    00185 # endif
    00186 # ifndef LONG_MIN
    00187 #  define LONG_MIN (-LONG_MAX-1)
    00188 # endif
    00189 # ifndef CHAR_BIT
    00190 #  define CHAR_BIT 8
    00191 # endif
    00192 #endif
    00193
    00194 #ifdef HAVE_LONG_LONG
    00195 # ifndef LLONG_MAX
    00196 #  ifdef LONG_LONG_MAX
    00197 #   define LLONG_MAX  LONG_LONG_MAX
    00198 #  else
    00199 #   ifdef _I64_MAX
    00200 #    define LLONG_MAX _I64_MAX
    00201 #   else
    00202     /* assuming 64bit(2's complement) long long */
    00203 #    define LLONG_MAX 9223372036854775807LL
    00204 #   endif
    00205 #  endif
    00206 # endif
    00207 # ifndef LLONG_MIN
    00208 #  ifdef LONG_LONG_MIN
    00209 #   define LLONG_MIN  LONG_LONG_MIN
    00210 #  else
    00211 #   ifdef _I64_MIN
    00212 #    define LLONG_MIN _I64_MIN
    00213 #   else
    00214 #    define LLONG_MIN (-LLONG_MAX-1)
    00215 #   endif
    00216 #  endif
    00217 # endif
    00218 #endif
    00219
    00220 #define FIXNUM_MAX (LONG_MAX>>1)
    00221 #define FIXNUM_MIN RSHIFT((long)LONG_MIN,1)
    00222
    00223 #define INT2FIX(i) ((VALUE)(((SIGNED_VALUE)(i))<<1 | FIXNUM_FLAG))
    00224 #define LONG2FIX(i) INT2FIX(i)
    00225 #define rb_fix_new(v) INT2FIX(v)
    00226 VALUE rb_int2inum(SIGNED_VALUE);
    00227
    00228 #define rb_int_new(v) rb_int2inum(v)
    00229 VALUE rb_uint2inum(VALUE);
    00230
    00231 #define rb_uint_new(v) rb_uint2inum(v)
    00232
    00233 #ifdef HAVE_LONG_LONG
    00234 VALUE rb_ll2inum(LONG_LONG);
    00235 #define LL2NUM(v) rb_ll2inum(v)
    00236 VALUE rb_ull2inum(unsigned LONG_LONG);
    00237 #define ULL2NUM(v) rb_ull2inum(v)
    00238 #endif
    00239
    00240 #if SIZEOF_OFF_T > SIZEOF_LONG && defined(HAVE_LONG_LONG)
    00241 # define OFFT2NUM(v) LL2NUM(v)
    00242 #elif SIZEOF_OFF_T == SIZEOF_LONG
    00243 # define OFFT2NUM(v) LONG2NUM(v)
    00244 #else
    00245 # define OFFT2NUM(v) INT2NUM(v)
    00246 #endif
    00247
    00248 #if SIZEOF_SIZE_T > SIZEOF_LONG && defined(HAVE_LONG_LONG)
    00249 # define SIZET2NUM(v) ULL2NUM(v)
    00250 # define SSIZET2NUM(v) LL2NUM(v)
    00251 #elif SIZEOF_SIZE_T == SIZEOF_LONG
    00252 # define SIZET2NUM(v) ULONG2NUM(v)
    00253 # define SSIZET2NUM(v) LONG2NUM(v)
    00254 #else
    00255 # define SIZET2NUM(v) UINT2NUM(v)
    00256 # define SSIZET2NUM(v) INT2NUM(v)
    00257 #endif
    00258
    00259 #ifndef SSIZE_MAX
    00260 # if SIZEOF_SIZE_T > SIZEOF_LONG && defined(HAVE_LONG_LONG)
    00261 #   define SSIZE_MAX LLONG_MAX
    00262 #   define SSIZE_MIN LLONG_MIN
    00263 # elif SIZEOF_SIZE_T == SIZEOF_LONG
    00264 #   define SSIZE_MAX LONG_MAX
    00265 #   define SSIZE_MIN LONG_MIN
    00266 # elif SIZEOF_SIZE_T == SIZEOF_INT
    00267 #   define SSIZE_MAX INT_MAX
    00268 #   define SSIZE_MIN INT_MIN
    00269 # else
    00270 #   define SSIZE_MAX SHRT_MAX
    00271 #   define SSIZE_MIN SHRT_MIN
    00272 # endif
    00273 #endif
    00274
    00275 #if SIZEOF_INT < SIZEOF_VALUE
    00276 NORETURN(void rb_out_of_int(SIGNED_VALUE num));
    00277 #endif
    00278
    00279 #if SIZEOF_INT < SIZEOF_LONG
    00280 #define rb_long2int_internal(n, i) \
    00281     int i = (int)(n); \
    00282     if ((long)i != (n)) rb_out_of_int(n)
    00283 #ifdef __GNUC__
    00284 #define rb_long2int(n) __extension__ ({long i2l_n = (n); rb_long2int_internal(i2l_n, i2l_i); i2l_i;})
    00285 #else
    00286 static inline int
    00287 rb_long2int(long n) {rb_long2int_internal(n, i); return i;}
    00288 #endif
    00289 #else
    00290 #define rb_long2int(n) ((int)(n))
    00291 #endif
    00292
    00293 #ifndef PIDT2NUM
    00294 #define PIDT2NUM(v) LONG2NUM(v)
    00295 #endif
    00296 #ifndef NUM2PIDT
    00297 #define NUM2PIDT(v) NUM2LONG(v)
    00298 #endif
    00299 #ifndef UIDT2NUM
    00300 #define UIDT2NUM(v) LONG2NUM(v)
    00301 #endif
    00302 #ifndef NUM2UIDT
    00303 #define NUM2UIDT(v) NUM2LONG(v)
    00304 #endif
    00305 #ifndef GIDT2NUM
    00306 #define GIDT2NUM(v) LONG2NUM(v)
    00307 #endif
    00308 #ifndef NUM2GIDT
    00309 #define NUM2GIDT(v) NUM2LONG(v)
    00310 #endif
    00311
    00312 #define FIX2LONG(x) RSHIFT((SIGNED_VALUE)x,1)
    00313 #define FIX2ULONG(x) ((((VALUE)(x))>>1)&LONG_MAX)
    00314 #define FIXNUM_P(f) (((SIGNED_VALUE)(f))&FIXNUM_FLAG)
    00315 #define POSFIXABLE(f) ((f) < FIXNUM_MAX+1)
    00316 #define NEGFIXABLE(f) ((f) >= FIXNUM_MIN)
    00317 #define FIXABLE(f) (POSFIXABLE(f) && NEGFIXABLE(f))
    00318
    00319 #define IMMEDIATE_P(x) ((VALUE)(x) & IMMEDIATE_MASK)
    00320
    00321 #define SYMBOL_P(x) (((VALUE)(x)&~(~(VALUE)0<<RUBY_SPECIAL_SHIFT))==SYMBOL_FLAG)
    00322 #define ID2SYM(x) (((VALUE)(x)<<RUBY_SPECIAL_SHIFT)|SYMBOL_FLAG)
    00323 #define SYM2ID(x) RSHIFT((unsigned long)(x),RUBY_SPECIAL_SHIFT)
    00324
    00325 /* Module#methods, #singleton_methods and so on return Symbols */
    00326 #define USE_SYMBOL_AS_METHOD_NAME 1
    00327
    00328 /* special constants - i.e. non-zero and non-fixnum constants */
    00329 enum ruby_special_consts {
    00330     RUBY_Qfalse = 0,
    00331     RUBY_Qtrue  = 2,
    00332     RUBY_Qnil   = 4,
    00333     RUBY_Qundef = 6,
    00334
    00335     RUBY_IMMEDIATE_MASK = 0x03,
    00336     RUBY_FIXNUM_FLAG    = 0x01,
    00337     RUBY_SYMBOL_FLAG    = 0x0e,
    00338     RUBY_SPECIAL_SHIFT  = 8
    00339 };
    00340
    00341 #define Qfalse ((VALUE)RUBY_Qfalse)
    00342 #define Qtrue  ((VALUE)RUBY_Qtrue)
    00343 #define Qnil   ((VALUE)RUBY_Qnil)
    00344 #define Qundef ((VALUE)RUBY_Qundef)     /* undefined value for placeholder */
    00345 #define IMMEDIATE_MASK RUBY_IMMEDIATE_MASK
    00346 #define FIXNUM_FLAG RUBY_FIXNUM_FLAG
    00347 #define SYMBOL_FLAG RUBY_SYMBOL_FLAG
    00348
    00349 #define RTEST(v) (((VALUE)(v) & ~Qnil) != 0)
    00350 #define NIL_P(v) ((VALUE)(v) == Qnil)
    00351
    00352 #define CLASS_OF(v) rb_class_of((VALUE)(v))
    00353
    00354 enum ruby_value_type {
    00355     RUBY_T_NONE   = 0x00,
    00356
    00357     RUBY_T_OBJECT = 0x01,
    00358     RUBY_T_CLASS  = 0x02,
    00359     RUBY_T_MODULE = 0x03,
    00360     RUBY_T_FLOAT  = 0x04,
    00361     RUBY_T_STRING = 0x05,
    00362     RUBY_T_REGEXP = 0x06,
    00363     RUBY_T_ARRAY  = 0x07,
    00364     RUBY_T_HASH   = 0x08,
    00365     RUBY_T_STRUCT = 0x09,
    00366     RUBY_T_BIGNUM = 0x0a,
    00367     RUBY_T_FILE   = 0x0b,
    00368     RUBY_T_DATA   = 0x0c,
    00369     RUBY_T_MATCH  = 0x0d,
    00370     RUBY_T_COMPLEX  = 0x0e,
    00371     RUBY_T_RATIONAL = 0x0f,
    00372
    00373     RUBY_T_NIL    = 0x11,
    00374     RUBY_T_TRUE   = 0x12,
    00375     RUBY_T_FALSE  = 0x13,
    00376     RUBY_T_SYMBOL = 0x14,
    00377     RUBY_T_FIXNUM = 0x15,
    00378
    00379     RUBY_T_UNDEF  = 0x1b,
    00380     RUBY_T_NODE   = 0x1c,
    00381     RUBY_T_ICLASS = 0x1d,
    00382     RUBY_T_ZOMBIE = 0x1e,
    00383
    00384     RUBY_T_MASK   = 0x1f
    00385 };
    00386
    00387 #define T_NONE   RUBY_T_NONE
    00388 #define T_NIL    RUBY_T_NIL
    00389 #define T_OBJECT RUBY_T_OBJECT
    00390 #define T_CLASS  RUBY_T_CLASS
    00391 #define T_ICLASS RUBY_T_ICLASS
    00392 #define T_MODULE RUBY_T_MODULE
    00393 #define T_FLOAT  RUBY_T_FLOAT
    00394 #define T_STRING RUBY_T_STRING
    00395 #define T_REGEXP RUBY_T_REGEXP
    00396 #define T_ARRAY  RUBY_T_ARRAY
    00397 #define T_HASH   RUBY_T_HASH
    00398 #define T_STRUCT RUBY_T_STRUCT
    00399 #define T_BIGNUM RUBY_T_BIGNUM
    00400 #define T_FILE   RUBY_T_FILE
    00401 #define T_FIXNUM RUBY_T_FIXNUM
    00402 #define T_TRUE   RUBY_T_TRUE
    00403 #define T_FALSE  RUBY_T_FALSE
    00404 #define T_DATA   RUBY_T_DATA
    00405 #define T_MATCH  RUBY_T_MATCH
    00406 #define T_SYMBOL RUBY_T_SYMBOL
    00407 #define T_RATIONAL RUBY_T_RATIONAL
    00408 #define T_COMPLEX RUBY_T_COMPLEX
    00409 #define T_UNDEF  RUBY_T_UNDEF
    00410 #define T_NODE   RUBY_T_NODE
    00411 #define T_ZOMBIE RUBY_T_ZOMBIE
    00412 #define T_MASK   RUBY_T_MASK
    00413
    00414 #define BUILTIN_TYPE(x) (int)(((struct RBasic*)(x))->flags & T_MASK)
    00415
    00416 static inline int rb_type(VALUE obj);
    00417 #define TYPE(x) rb_type((VALUE)(x))
    00418
    00419 #ifdef __GNUC__
    00420 #define RB_GC_GUARD_PTR(ptr) \
    00421     __extension__ ({volatile VALUE *rb_gc_guarded_ptr = (ptr); rb_gc_guarded_ptr;})
    00422 #else
    00423 #ifdef _MSC_VER
    00424 #pragma optimize("", off)
    00425 #endif
    00426 static inline volatile VALUE *rb_gc_guarded_ptr(volatile VALUE *ptr) {return ptr;}
    00427 #ifdef _MSC_VER
    00428 #pragma optimize("", on)
    00429 #endif
    00430 #define RB_GC_GUARD_PTR(ptr) rb_gc_guarded_ptr(ptr)
    00431 #endif
    00432 #define RB_GC_GUARD(v) (*RB_GC_GUARD_PTR(&(v)))
    00433
    00434 void rb_check_type(VALUE,int);
    00435 #define Check_Type(v,t) rb_check_type((VALUE)(v),t)
    00436
    00437 VALUE rb_str_to_str(VALUE);
    00438 VALUE rb_string_value(volatile VALUE*);
    00439 char *rb_string_value_ptr(volatile VALUE*);
    00440 char *rb_string_value_cstr(volatile VALUE*);
    00441
    00442 #define StringValue(v) rb_string_value(&(v))
    00443 #define StringValuePtr(v) rb_string_value_ptr(&(v))
    00444 #define StringValueCStr(v) rb_string_value_cstr(&(v))
    00445
    00446 void rb_check_safe_obj(VALUE);
    00447 DEPRECATED(void rb_check_safe_str(VALUE));
    00448 #define SafeStringValue(v) do {\
    00449     StringValue(v);\
    00450     rb_check_safe_obj(v);\
    00451 } while (0)
    00452 /* obsolete macro - use SafeStringValue(v) */
    00453 #define Check_SafeStr(v) rb_check_safe_str((VALUE)(v))
    00454
    00455 VALUE rb_str_export(VALUE);
    00456 #define ExportStringValue(v) do {\
    00457     SafeStringValue(v);\
    00458    (v) = rb_str_export(v);\
    00459 } while (0)
    00460 VALUE rb_str_export_locale(VALUE);
    00461
    00462 VALUE rb_get_path(VALUE);
    00463 #define FilePathValue(v) (RB_GC_GUARD(v) = rb_get_path(v))
    00464
    00465 VALUE rb_get_path_no_checksafe(VALUE);
    00466 #define FilePathStringValue(v) ((v) = rb_get_path_no_checksafe(v))
    00467
    00468 void rb_secure(int);
    00469 int rb_safe_level(void);
    00470 void rb_set_safe_level(int);
    00471 void rb_set_safe_level_force(int);
    00472 void rb_secure_update(VALUE);
    00473 NORETURN(void rb_insecure_operation(void));
    00474
    00475 VALUE rb_errinfo(void);
    00476 void rb_set_errinfo(VALUE);
    00477
    00478 SIGNED_VALUE rb_num2long(VALUE);
    00479 VALUE rb_num2ulong(VALUE);
    00480 #define NUM2LONG_internal(x) (FIXNUM_P(x) ? FIX2LONG(x) : rb_num2long(x))
    00481 #ifdef __GNUC__
    00482 #define NUM2LONG(x) \
    00483     __extension__ ({VALUE num2long_x = (x); NUM2LONG_internal(num2long_x);})
    00484 #else
    00485 static inline long
    00486 NUM2LONG(VALUE x)
    00487 {
    00488     return NUM2LONG_internal(x);
    00489 }
    00490 #endif
    00491 #define NUM2ULONG(x) rb_num2ulong((VALUE)x)
    00492 #if SIZEOF_INT < SIZEOF_LONG
    00493 long rb_num2int(VALUE);
    00494 long rb_fix2int(VALUE);
    00495 #define FIX2INT(x) ((int)rb_fix2int((VALUE)x))
    00496 #define NUM2INT_internal(x) (FIXNUM_P(x) ? FIX2INT(x) : (int)rb_num2int(x))
    00497 #ifdef __GNUC__
    00498 #define NUM2INT(x) \
    00499     __extension__ ({VALUE num2int_x = (x); NUM2INT_internal(num2int_x);})
    00500 #else
    00501 static inline int
    00502 NUM2INT(VALUE x)
    00503 {
    00504     return NUM2INT_internal(x);
    00505 }
    00506 #endif
    00507 unsigned long rb_num2uint(VALUE);
    00508 #define NUM2UINT(x) ((unsigned int)rb_num2uint(x))
    00509 unsigned long rb_fix2uint(VALUE);
    00510 #define FIX2UINT(x) ((unsigned int)rb_fix2uint(x))
    00511 #else
    00512 #define NUM2INT(x) ((int)NUM2LONG(x))
    00513 #define NUM2UINT(x) ((unsigned int)NUM2ULONG(x))
    00514 #define FIX2INT(x) ((int)FIX2LONG(x))
    00515 #define FIX2UINT(x) ((unsigned int)FIX2ULONG(x))
    00516 #endif
    00517
    00518 #ifdef HAVE_LONG_LONG
    00519 LONG_LONG rb_num2ll(VALUE);
    00520 unsigned LONG_LONG rb_num2ull(VALUE);
    00521 # define NUM2LL_internal(x) (FIXNUM_P(x) ? FIX2LONG(x) : rb_num2ll(x))
    00522 # ifdef __GNUC__
    00523 #   define NUM2LL(x) \
    00524     __extension__ ({VALUE num2ll_x = (x); NUM2LL_internal(num2ll_x);})
    00525 # else
    00526 static inline LONG_LONG
    00527 NUM2LL(VALUE x)
    00528 {
    00529     return NUM2LL_internal(x);
    00530 }
    00531 # endif
    00532 # define NUM2ULL(x) rb_num2ull((VALUE)x)
    00533 #endif
    00534
    00535 #if defined(HAVE_LONG_LONG) && SIZEOF_OFF_T > SIZEOF_LONG
    00536 # define NUM2OFFT(x) ((off_t)NUM2LL(x))
    00537 #else
    00538 # define NUM2OFFT(x) NUM2LONG(x)
    00539 #endif
    00540
    00541 #if defined(HAVE_LONG_LONG) && SIZEOF_SIZE_T > SIZEOF_LONG
    00542 # define NUM2SIZET(x) ((size_t)NUM2ULL(x))
    00543 # define NUM2SSIZET(x) ((size_t)NUM2LL(x))
    00544 #else
    00545 # define NUM2SIZET(x) NUM2ULONG(x)
    00546 # define NUM2SSIZET(x) NUM2LONG(x)
    00547 #endif
    00548
    00549 double rb_num2dbl(VALUE);
    00550 #define NUM2DBL(x) rb_num2dbl((VALUE)(x))
    00551
    00552 VALUE rb_uint2big(VALUE);
    00553 VALUE rb_int2big(SIGNED_VALUE);
    00554
    00555 VALUE rb_newobj(void);
    00556 #define NEWOBJ(obj,type) type *obj = (type*)rb_newobj()
    00557 #define OBJSETUP(obj,c,t) do {\
    00558     RBASIC(obj)->flags = (t);\
    00559     RBASIC(obj)->klass = (c);\
    00560     if (rb_safe_level() >= 3) FL_SET(obj, FL_TAINT | FL_UNTRUSTED);\
    00561 } while (0)
    00562 #define CLONESETUP(clone,obj) do {\
    00563     OBJSETUP(clone,rb_singleton_class_clone((VALUE)obj),RBASIC(obj)->flags);\
    00564     rb_singleton_class_attached(RBASIC(clone)->klass, (VALUE)clone);\
    00565     if (FL_TEST(obj, FL_EXIVAR)) rb_copy_generic_ivar((VALUE)clone,(VALUE)obj);\
    00566 } while (0)
    00567 #define DUPSETUP(dup,obj) do {\
    00568     OBJSETUP(dup,rb_obj_class(obj), (RBASIC(obj)->flags)&(T_MASK|FL_EXIVAR|FL_TAINT|FL_UNTRUSTED)); \
    00569     if (FL_TEST(obj, FL_EXIVAR)) rb_copy_generic_ivar((VALUE)dup,(VALUE)obj);\
    00570 } while (0)
    00571
    00572 struct RBasic {
    00573     VALUE flags;
    00574     VALUE klass;
    00575 };
    00576
    00577 #define ROBJECT_EMBED_LEN_MAX 3
    00578 struct RObject {
    00579     struct RBasic basic;
    00580     union {
    00581         struct {
    00582             long numiv;
    00583             VALUE *ivptr;
    00584             struct st_table *iv_index_tbl; /* shortcut for RCLASS_IV_INDEX_TBL(rb_obj_class(obj)) */
    00585         } heap;
    00586         VALUE ary[ROBJECT_EMBED_LEN_MAX];
    00587     } as;
    00588 };
    00589 #define ROBJECT_EMBED FL_USER1
    00590 #define ROBJECT_NUMIV(o) \
    00591     ((RBASIC(o)->flags & ROBJECT_EMBED) ? \
    00592      ROBJECT_EMBED_LEN_MAX : \
    00593      ROBJECT(o)->as.heap.numiv)
    00594 #define ROBJECT_IVPTR(o) \
    00595     ((RBASIC(o)->flags & ROBJECT_EMBED) ? \
    00596      ROBJECT(o)->as.ary : \
    00597      ROBJECT(o)->as.heap.ivptr)
    00598 #define ROBJECT_IV_INDEX_TBL(o) \
    00599     ((RBASIC(o)->flags & ROBJECT_EMBED) ? \
    00600      RCLASS_IV_INDEX_TBL(rb_obj_class(o)) : \
    00601      ROBJECT(o)->as.heap.iv_index_tbl)
    00602
    00604 typedef struct {
    00605     VALUE super;
    00606     struct st_table *iv_tbl;
    00607 } rb_classext_t;
    00608
    00609 struct RClass {
    00610     struct RBasic basic;
    00611     rb_classext_t *ptr;
    00612     struct st_table *m_tbl;
    00613     struct st_table *iv_index_tbl;
    00614 };
    00615 #define RCLASS_IV_TBL(c) (RCLASS(c)->ptr->iv_tbl)
    00616 #define RCLASS_M_TBL(c) (RCLASS(c)->m_tbl)
    00617 #define RCLASS_SUPER(c) (RCLASS(c)->ptr->super)
    00618 #define RCLASS_IV_INDEX_TBL(c) (RCLASS(c)->iv_index_tbl)
    00619 #define RMODULE_IV_TBL(m) RCLASS_IV_TBL(m)
    00620 #define RMODULE_M_TBL(m) RCLASS_M_TBL(m)
    00621 #define RMODULE_SUPER(m) RCLASS_SUPER(m)
    00622
    00623 struct RFloat {
    00624     struct RBasic basic;
    00625     double float_value;
    00626 };
    00627 #define RFLOAT_VALUE(v) (RFLOAT(v)->float_value)
    00628 #define DBL2NUM(dbl)  rb_float_new(dbl)
    00629
    00630 #define ELTS_SHARED FL_USER2
    00631
    00632 #define RSTRING_EMBED_LEN_MAX ((int)((sizeof(VALUE)*3)/sizeof(char)-1))
    00633 struct RString {
    00634     struct RBasic basic;
    00635     union {
    00636         struct {
    00637             long len;
    00638             char *ptr;
    00639             union {
    00640                 long capa;
    00641                 VALUE shared;
    00642             } aux;
    00643         } heap;
    00644         char ary[RSTRING_EMBED_LEN_MAX + 1];
    00645     } as;
    00646 };
    00647 #define RSTRING_NOEMBED FL_USER1
    00648 #define RSTRING_EMBED_LEN_MASK (FL_USER2|FL_USER3|FL_USER4|FL_USER5|FL_USER6)
    00649 #define RSTRING_EMBED_LEN_SHIFT (FL_USHIFT+2)
    00650 #define RSTRING_LEN(str) \
    00651     (!(RBASIC(str)->flags & RSTRING_NOEMBED) ? \
    00652      (long)((RBASIC(str)->flags >> RSTRING_EMBED_LEN_SHIFT) & \
    00653             (RSTRING_EMBED_LEN_MASK >> RSTRING_EMBED_LEN_SHIFT)) : \
    00654      RSTRING(str)->as.heap.len)
    00655 #define RSTRING_PTR(str) \
    00656     (!(RBASIC(str)->flags & RSTRING_NOEMBED) ? \
    00657      RSTRING(str)->as.ary : \
    00658      RSTRING(str)->as.heap.ptr)
    00659 #define RSTRING_END(str) \
    00660     (!(RBASIC(str)->flags & RSTRING_NOEMBED) ? \
    00661      (RSTRING(str)->as.ary + \
    00662       ((RBASIC(str)->flags >> RSTRING_EMBED_LEN_SHIFT) & \
    00663        (RSTRING_EMBED_LEN_MASK >> RSTRING_EMBED_LEN_SHIFT))) : \
    00664      (RSTRING(str)->as.heap.ptr + RSTRING(str)->as.heap.len))
    00665 #define RSTRING_LENINT(str) rb_long2int(RSTRING_LEN(str))
    00666
    00667 #define RARRAY_EMBED_LEN_MAX 3
    00668 struct RArray {
    00669     struct RBasic basic;
    00670     union {
    00671         struct {
    00672             long len;
    00673             union {
    00674                 long capa;
    00675                 VALUE shared;
    00676             } aux;
    00677             VALUE *ptr;
    00678         } heap;
    00679         VALUE ary[RARRAY_EMBED_LEN_MAX];
    00680     } as;
    00681 };
    00682 #define RARRAY_EMBED_FLAG FL_USER1
    00683 /* FL_USER2 is for ELTS_SHARED */
    00684 #define RARRAY_EMBED_LEN_MASK (FL_USER4|FL_USER3)
    00685 #define RARRAY_EMBED_LEN_SHIFT (FL_USHIFT+3)
    00686 #define RARRAY_LEN(a) \
    00687     ((RBASIC(a)->flags & RARRAY_EMBED_FLAG) ? \
    00688      (long)((RBASIC(a)->flags >> RARRAY_EMBED_LEN_SHIFT) & \
    00689          (RARRAY_EMBED_LEN_MASK >> RARRAY_EMBED_LEN_SHIFT)) : \
    00690      RARRAY(a)->as.heap.len)
    00691 #define RARRAY_PTR(a) \
    00692     ((RBASIC(a)->flags & RARRAY_EMBED_FLAG) ? \
    00693      RARRAY(a)->as.ary : \
    00694      RARRAY(a)->as.heap.ptr)
    00695 #define RARRAY_LENINT(ary) rb_long2int(RARRAY_LEN(ary))
    00696
    00697 struct RRegexp {
    00698     struct RBasic basic;
    00699     struct re_pattern_buffer *ptr;
    00700     VALUE src;
    00701     unsigned long usecnt;
    00702 };
    00703 #define RREGEXP_SRC(r) RREGEXP(r)->src
    00704 #define RREGEXP_SRC_PTR(r) RSTRING_PTR(RREGEXP(r)->src)
    00705 #define RREGEXP_SRC_LEN(r) RSTRING_LEN(RREGEXP(r)->src)
    00706 #define RREGEXP_SRC_END(r) RSTRING_END(RREGEXP(r)->src)
    00707
    00708 struct RHash {
    00709     struct RBasic basic;
    00710     struct st_table *ntbl;      /* possibly 0 */
    00711     int iter_lev;
    00712     VALUE ifnone;
    00713 };
    00714 /* RHASH_TBL allocates st_table if not available. */
    00715 #define RHASH_TBL(h) rb_hash_tbl(h)
    00716 #define RHASH_ITER_LEV(h) (RHASH(h)->iter_lev)
    00717 #define RHASH_IFNONE(h) (RHASH(h)->ifnone)
    00718 #define RHASH_SIZE(h) (RHASH(h)->ntbl ? RHASH(h)->ntbl->num_entries : 0)
    00719 #define RHASH_EMPTY_P(h) (RHASH_SIZE(h) == 0)
    00720
    00721 struct RFile {
    00722     struct RBasic basic;
    00723     struct rb_io_t *fptr;
    00724 };
    00725
    00726 struct RRational {
    00727     struct RBasic basic;
    00728     VALUE num;
    00729     VALUE den;
    00730 };
    00731
    00732 struct RComplex {
    00733     struct RBasic basic;
    00734     VALUE real;
    00735     VALUE imag;
    00736 };
    00737
    00738 struct RData {
    00739     struct RBasic basic;
    00740     void (*dmark)(void*);
    00741     void (*dfree)(void*);
    00742     void *data;
    00743 };
    00744
    00745 typedef struct rb_data_type_struct {
    00746     const char *wrap_struct_name;
    00747     void (*dmark)(void*);
    00748     void (*dfree)(void*);
    00749     size_t (*dsize)(const void *);
    00750     void *reserved[3]; /* For future extension.
    00751                           This array *must* be filled with ZERO. */
    00752     void *data;        /* This area can be used for any purpose
    00753                           by a programmer who define the type. */
    00754 } rb_data_type_t;
    00755
    00756 struct RTypedData {
    00757     struct RBasic basic;
    00758     const rb_data_type_t *type;
    00759     VALUE typed_flag; /* 1 or not */
    00760     void *data;
    00761 };
    00762
    00763 #define DATA_PTR(dta) (RDATA(dta)->data)
    00764
    00765 #define RTYPEDDATA_P(v)    (RTYPEDDATA(v)->typed_flag == 1)
    00766 #define RTYPEDDATA_TYPE(v) (RTYPEDDATA(v)->type)
    00767 #define RTYPEDDATA_DATA(v) (RTYPEDDATA(v)->data)
    00768
    00769 /*
    00770 #define RUBY_DATA_FUNC(func) ((void (*)(void*))func)
    00771 */
    00772 typedef void (*RUBY_DATA_FUNC)(void*);
    00773
    00774 VALUE rb_data_object_alloc(VALUE,void*,RUBY_DATA_FUNC,RUBY_DATA_FUNC);
    00775 VALUE rb_data_typed_object_alloc(VALUE klass, void *datap, const rb_data_type_t *);
    00776 int rb_typeddata_is_kind_of(VALUE, const rb_data_type_t *);
    00777 void *rb_check_typeddata(VALUE, const rb_data_type_t *);
    00778 #define Check_TypedStruct(v,t) rb_check_typeddata((VALUE)(v),t)
    00779 #define RUBY_DEFAULT_FREE ((RUBY_DATA_FUNC)-1)
    00780 #define RUBY_NEVER_FREE   ((RUBY_DATA_FUNC)0)
    00781 #define RUBY_TYPED_DEFAULT_FREE RUBY_DEFAULT_FREE
    00782 #define RUBY_TYPED_NEVER_FREE   RUBY_NEVER_FREE
    00783
    00784 #define Data_Wrap_Struct(klass,mark,free,sval)\
    00785     rb_data_object_alloc(klass,sval,(RUBY_DATA_FUNC)mark,(RUBY_DATA_FUNC)free)
    00786
    00787 #define Data_Make_Struct(klass,type,mark,free,sval) (\
    00788     sval = ALLOC(type),\
    00789     memset(sval, 0, sizeof(type)),\
    00790     Data_Wrap_Struct(klass,mark,free,sval)\
    00791 )
    00792
    00793 #define TypedData_Wrap_Struct(klass,data_type,sval)\
    00794   rb_data_typed_object_alloc(klass,sval,data_type)
    00795
    00796 #define TypedData_Make_Struct(klass, type, data_type, sval) (\
    00797     sval = ALLOC(type),\
    00798     memset(sval, 0, sizeof(type)),\
    00799     TypedData_Wrap_Struct(klass,data_type,sval)\
    00800 )
    00801
    00802 #define Data_Get_Struct(obj,type,sval) do {\
    00803     Check_Type(obj, T_DATA); \
    00804     sval = (type*)DATA_PTR(obj);\
    00805 } while (0)
    00806
    00807 #define TypedData_Get_Struct(obj,type,data_type,sval) do {\
    00808     sval = (type*)rb_check_typeddata(obj, data_type); \
    00809 } while (0)
    00810
    00811 #define RSTRUCT_EMBED_LEN_MAX 3
    00812 struct RStruct {
    00813     struct RBasic basic;
    00814     union {
    00815         struct {
    00816             long len;
    00817             VALUE *ptr;
    00818         } heap;
    00819         VALUE ary[RSTRUCT_EMBED_LEN_MAX];
    00820     } as;
    00821 };
    00822 #define RSTRUCT_EMBED_LEN_MASK (FL_USER2|FL_USER1)
    00823 #define RSTRUCT_EMBED_LEN_SHIFT (FL_USHIFT+1)
    00824 #define RSTRUCT_LEN(st) \
    00825     ((RBASIC(st)->flags & RSTRUCT_EMBED_LEN_MASK) ? \
    00826      (long)((RBASIC(st)->flags >> RSTRUCT_EMBED_LEN_SHIFT) & \
    00827             (RSTRUCT_EMBED_LEN_MASK >> RSTRUCT_EMBED_LEN_SHIFT)) : \
    00828      RSTRUCT(st)->as.heap.len)
    00829 #define RSTRUCT_PTR(st) \
    00830     ((RBASIC(st)->flags & RSTRUCT_EMBED_LEN_MASK) ? \
    00831      RSTRUCT(st)->as.ary : \
    00832      RSTRUCT(st)->as.heap.ptr)
    00833 #define RSTRUCT_LENINT(st) rb_long2int(RSTRUCT_LEN(st))
    00834
    00835 #define RBIGNUM_EMBED_LEN_MAX ((int)((sizeof(VALUE)*3)/sizeof(BDIGIT)))
    00836 struct RBignum {
    00837     struct RBasic basic;
    00838     union {
    00839         struct {
    00840             long len;
    00841             BDIGIT *digits;
    00842         } heap;
    00843         BDIGIT ary[RBIGNUM_EMBED_LEN_MAX];
    00844     } as;
    00845 };
    00846 #define RBIGNUM_SIGN_BIT FL_USER1
    00847 /* sign: positive:1, negative:0 */
    00848 #define RBIGNUM_SIGN(b) ((RBASIC(b)->flags & RBIGNUM_SIGN_BIT) != 0)
    00849 #define RBIGNUM_SET_SIGN(b,sign) \
    00850   ((sign) ? (RBASIC(b)->flags |= RBIGNUM_SIGN_BIT) \
    00851           : (RBASIC(b)->flags &= ~RBIGNUM_SIGN_BIT))
    00852 #define RBIGNUM_POSITIVE_P(b) RBIGNUM_SIGN(b)
    00853 #define RBIGNUM_NEGATIVE_P(b) (!RBIGNUM_SIGN(b))
    00854
    00855 #define RBIGNUM_EMBED_FLAG FL_USER2
    00856 #define RBIGNUM_EMBED_LEN_MASK (FL_USER5|FL_USER4|FL_USER3)
    00857 #define RBIGNUM_EMBED_LEN_SHIFT (FL_USHIFT+3)
    00858 #define RBIGNUM_LEN(b) \
    00859     ((RBASIC(b)->flags & RBIGNUM_EMBED_FLAG) ? \
    00860      (long)((RBASIC(b)->flags >> RBIGNUM_EMBED_LEN_SHIFT) & \
    00861             (RBIGNUM_EMBED_LEN_MASK >> RBIGNUM_EMBED_LEN_SHIFT)) : \
    00862      RBIGNUM(b)->as.heap.len)
    00863 /* LSB:RBIGNUM_DIGITS(b)[0], MSB:RBIGNUM_DIGITS(b)[RBIGNUM_LEN(b)-1] */
    00864 #define RBIGNUM_DIGITS(b) \
    00865     ((RBASIC(b)->flags & RBIGNUM_EMBED_FLAG) ? \
    00866      RBIGNUM(b)->as.ary : \
    00867      RBIGNUM(b)->as.heap.digits)
    00868 #define RBIGNUM_LENINT(b) rb_long2int(RBIGNUM_LEN(b))
    00869
    00870 #define R_CAST(st)   (struct st*)
    00871 #define RBASIC(obj)  (R_CAST(RBasic)(obj))
    00872 #define ROBJECT(obj) (R_CAST(RObject)(obj))
    00873 #define RCLASS(obj)  (R_CAST(RClass)(obj))
    00874 #define RMODULE(obj) RCLASS(obj)
    00875 #define RFLOAT(obj)  (R_CAST(RFloat)(obj))
    00876 #define RSTRING(obj) (R_CAST(RString)(obj))
    00877 #define RREGEXP(obj) (R_CAST(RRegexp)(obj))
    00878 #define RARRAY(obj)  (R_CAST(RArray)(obj))
    00879 #define RHASH(obj)   (R_CAST(RHash)(obj))
    00880 #define RDATA(obj)   (R_CAST(RData)(obj))
    00881 #define RTYPEDDATA(obj)   (R_CAST(RTypedData)(obj))
    00882 #define RSTRUCT(obj) (R_CAST(RStruct)(obj))
    00883 #define RBIGNUM(obj) (R_CAST(RBignum)(obj))
    00884 #define RFILE(obj)   (R_CAST(RFile)(obj))
    00885 #define RRATIONAL(obj) (R_CAST(RRational)(obj))
    00886 #define RCOMPLEX(obj) (R_CAST(RComplex)(obj))
    00887
    00888 #define FL_SINGLETON FL_USER0
    00889 #define FL_MARK      (((VALUE)1)<<5)
    00890 #define FL_RESERVED  (((VALUE)1)<<6) /* will be used in the future GC */
    00891 #define FL_FINALIZE  (((VALUE)1)<<7)
    00892 #define FL_TAINT     (((VALUE)1)<<8)
    00893 #define FL_UNTRUSTED (((VALUE)1)<<9)
    00894 #define FL_EXIVAR    (((VALUE)1)<<10)
    00895 #define FL_FREEZE    (((VALUE)1)<<11)
    00896
    00897 #define FL_USHIFT    12
    00898
    00899 #define FL_USER0     (((VALUE)1)<<(FL_USHIFT+0))
    00900 #define FL_USER1     (((VALUE)1)<<(FL_USHIFT+1))
    00901 #define FL_USER2     (((VALUE)1)<<(FL_USHIFT+2))
    00902 #define FL_USER3     (((VALUE)1)<<(FL_USHIFT+3))
    00903 #define FL_USER4     (((VALUE)1)<<(FL_USHIFT+4))
    00904 #define FL_USER5     (((VALUE)1)<<(FL_USHIFT+5))
    00905 #define FL_USER6     (((VALUE)1)<<(FL_USHIFT+6))
    00906 #define FL_USER7     (((VALUE)1)<<(FL_USHIFT+7))
    00907 #define FL_USER8     (((VALUE)1)<<(FL_USHIFT+8))
    00908 #define FL_USER9     (((VALUE)1)<<(FL_USHIFT+9))
    00909 #define FL_USER10    (((VALUE)1)<<(FL_USHIFT+10))
    00910 #define FL_USER11    (((VALUE)1)<<(FL_USHIFT+11))
    00911 #define FL_USER12    (((VALUE)1)<<(FL_USHIFT+12))
    00912 #define FL_USER13    (((VALUE)1)<<(FL_USHIFT+13))
    00913 #define FL_USER14    (((VALUE)1)<<(FL_USHIFT+14))
    00914 #define FL_USER15    (((VALUE)1)<<(FL_USHIFT+15))
    00915 #define FL_USER16    (((VALUE)1)<<(FL_USHIFT+16))
    00916 #define FL_USER17    (((VALUE)1)<<(FL_USHIFT+17))
    00917 #define FL_USER18    (((VALUE)1)<<(FL_USHIFT+18))
    00918 #define FL_USER19    (((VALUE)1)<<(FL_USHIFT+19))
    00919
    00920 #define SPECIAL_CONST_P(x) (IMMEDIATE_P(x) || !RTEST(x))
    00921
    00922 #define FL_ABLE(x) (!SPECIAL_CONST_P(x) && BUILTIN_TYPE(x) != T_NODE)
    00923 #define FL_TEST(x,f) (FL_ABLE(x)?(RBASIC(x)->flags&(f)):0)
    00924 #define FL_ANY(x,f) FL_TEST(x,f)
    00925 #define FL_ALL(x,f) (FL_TEST(x,f) == (f))
    00926 #define FL_SET(x,f) do {if (FL_ABLE(x)) RBASIC(x)->flags |= (f);} while (0)
    00927 #define FL_UNSET(x,f) do {if (FL_ABLE(x)) RBASIC(x)->flags &= ~(f);} while (0)
    00928 #define FL_REVERSE(x,f) do {if (FL_ABLE(x)) RBASIC(x)->flags ^= (f);} while (0)
    00929
    00930 #define OBJ_TAINTED(x) (!!FL_TEST((x), FL_TAINT))
    00931 #define OBJ_TAINT(x) FL_SET((x), FL_TAINT)
    00932 #define OBJ_UNTRUSTED(x) (!!FL_TEST((x), FL_UNTRUSTED))
    00933 #define OBJ_UNTRUST(x) FL_SET((x), FL_UNTRUSTED)
    00934 #define OBJ_INFECT(x,s) do {if (FL_ABLE(x) && FL_ABLE(s)) RBASIC(x)->flags |= RBASIC(s)->flags & (FL_TAINT | FL_UNTRUSTED);} while (0)
    00935
    00936 #define OBJ_FROZEN(x) (!!FL_TEST((x), FL_FREEZE))
    00937 #define OBJ_FREEZE(x) FL_SET((x), FL_FREEZE)
    00938
    00939 #if SIZEOF_INT < SIZEOF_LONG
    00940 # define INT2NUM(v) INT2FIX((int)(v))
    00941 # define UINT2NUM(v) LONG2FIX((unsigned int)(v))
    00942 #else
    00943 # define INT2NUM_internal(v) (FIXABLE(v) ? INT2FIX(v) : rb_int2big(v))
    00944 # ifdef __GNUC__
    00945 #   define INT2NUM(v) __extension__ ({int int2num_v = (v); INT2NUM_internal(int2num_v);})
    00946 # else
    00947 static inline VALUE
    00948 INT2NUM(int v)
    00949 {
    00950     return INT2NUM_internal(v);
    00951 }
    00952 # endif
    00953
    00954 # define UINT2NUM_internal(v) (POSFIXABLE(v) ? LONG2FIX(v) : rb_uint2big(v))
    00955 # ifdef __GNUC__
    00956 #   define UINT2NUM(v) __extension__ ({unsigned int uint2num_v = (v); UINT2NUM_internal(uint2num_v);})
    00957 # else
    00958 static inline VALUE
    00959 UINT2NUM(unsigned int v)
    00960 {
    00961     return UINT2NUM_internal(v);
    00962 }
    00963 # endif
    00964 #endif
    00965
    00966 #define LONG2NUM_internal(v) (FIXABLE(v) ? LONG2FIX(v) : rb_int2big(v))
    00967 #ifdef __GNUC__
    00968 # define LONG2NUM(v) __extension__ ({long long2num_v = (v); LONG2NUM_internal(long2num_v);})
    00969 #else
    00970 static inline VALUE
    00971 LONG2NUM(long v)
    00972 {
    00973     return LONG2NUM_internal(v);
    00974 }
    00975 #endif
    00976
    00977 #define ULONG2NUM_internal(v) (POSFIXABLE(v) ? LONG2FIX(v) : rb_uint2big(v))
    00978 #ifdef __GNUC__
    00979 # define ULONG2NUM(v) __extension__ ({unsigned long ulong2num_v = (v); ULONG2NUM_internal(ulong2num_v);})
    00980 #else
    00981 static inline VALUE
    00982 ULONG2NUM(unsigned long v)
    00983 {
    00984     return ULONG2NUM_internal(v);
    00985 }
    00986 #endif
    00987
    00988 #define NUM2CHR_internal(x) (((TYPE(x) == T_STRING)&&(RSTRING_LEN(x)>=1))?\
    00989                      RSTRING_PTR(x)[0]:(char)(NUM2INT(x)&0xff))
    00990 #ifdef __GNUC__
    00991 # define NUM2CHR(x) __extension__ ({VALUE num2chr_x = (x); NUM2CHR_internal(num2chr_x);})
    00992 #else
    00993 static inline char
    00994 NUM2CHR(VALUE x)
    00995 {
    00996     return NUM2CHR_internal(x);
    00997 }
    00998 #endif
    00999 #define CHR2FIX(x) INT2FIX((long)((x)&0xff))
    01000
    01001 #define ALLOC_N(type,n) (type*)xmalloc2((n),sizeof(type))
    01002 #define ALLOC(type) (type*)xmalloc(sizeof(type))
    01003 #define REALLOC_N(var,type,n) (var)=(type*)xrealloc2((char*)(var),(n),sizeof(type))
    01004
    01005 #define ALLOCA_N(type,n) (type*)alloca(sizeof(type)*(n))
    01006
    01007 #define MEMZERO(p,type,n) memset((p), 0, sizeof(type)*(n))
    01008 #define MEMCPY(p1,p2,type,n) memcpy((p1), (p2), sizeof(type)*(n))
    01009 #define MEMMOVE(p1,p2,type,n) memmove((p1), (p2), sizeof(type)*(n))
    01010 #define MEMCMP(p1,p2,type,n) memcmp((p1), (p2), sizeof(type)*(n))
    01011
    01012 void rb_obj_infect(VALUE,VALUE);
    01013
    01014 typedef int ruby_glob_func(const char*,VALUE, void*);
    01015 void rb_glob(const char*,void(*)(const char*,VALUE,void*),VALUE);
    01016 int ruby_glob(const char*,int,ruby_glob_func*,VALUE);
    01017 int ruby_brace_glob(const char*,int,ruby_glob_func*,VALUE);
    01018
    01019 VALUE rb_define_class(const char*,VALUE);
    01020 VALUE rb_define_module(const char*);
    01021 VALUE rb_define_class_under(VALUE, const char*, VALUE);
    01022 VALUE rb_define_module_under(VALUE, const char*);
    01023
    01024 void rb_include_module(VALUE,VALUE);
    01025 void rb_extend_object(VALUE,VALUE);
    01026
    01027 struct rb_global_variable;
    01028
    01029 typedef VALUE rb_gvar_getter_t(ID id, void *data, struct rb_global_variable *gvar);
    01030 typedef void  rb_gvar_setter_t(VALUE val, ID id, void *data, struct rb_global_variable *gvar);
    01031 typedef void  rb_gvar_marker_t(VALUE *var);
    01032
    01033 VALUE rb_gvar_undef_getter(ID id, void *data, struct rb_global_variable *gvar);
    01034 void  rb_gvar_undef_setter(VALUE val, ID id, void *data, struct rb_global_variable *gvar);
    01035 void  rb_gvar_undef_marker(VALUE *var);
    01036
    01037 VALUE rb_gvar_val_getter(ID id, void *data, struct rb_global_variable *gvar);
    01038 void  rb_gvar_val_setter(VALUE val, ID id, void *data, struct rb_global_variable *gvar);
    01039 void  rb_gvar_val_marker(VALUE *var);
    01040
    01041 VALUE rb_gvar_var_getter(ID id, void *data, struct rb_global_variable *gvar);
    01042 void  rb_gvar_var_setter(VALUE val, ID id, void *data, struct rb_global_variable *gvar);
    01043 void  rb_gvar_var_marker(VALUE *var);
    01044
    01045 void  rb_gvar_readonly_setter(VALUE val, ID id, void *data, struct rb_global_variable *gvar);
    01046
    01047 void rb_define_variable(const char*,VALUE*);
    01048 void rb_define_virtual_variable(const char*,VALUE(*)(ANYARGS),void(*)(ANYARGS));
    01049 void rb_define_hooked_variable(const char*,VALUE*,VALUE(*)(ANYARGS),void(*)(ANYARGS));
    01050 void rb_define_readonly_variable(const char*,VALUE*);
    01051 void rb_define_const(VALUE,const char*,VALUE);
    01052 void rb_define_global_const(const char*,VALUE);
    01053
    01054 #define RUBY_METHOD_FUNC(func) ((VALUE (*)(ANYARGS))func)
    01055 void rb_define_method(VALUE,const char*,VALUE(*)(ANYARGS),int);
    01056 void rb_define_module_function(VALUE,const char*,VALUE(*)(ANYARGS),int);
    01057 void rb_define_global_function(const char*,VALUE(*)(ANYARGS),int);
    01058
    01059 void rb_undef_method(VALUE,const char*);
    01060 void rb_define_alias(VALUE,const char*,const char*);
    01061 void rb_define_attr(VALUE,const char*,int,int);
    01062
    01063 void rb_global_variable(VALUE*);
    01064 void rb_gc_register_mark_object(VALUE);
    01065 void rb_gc_register_address(VALUE*);
    01066 void rb_gc_unregister_address(VALUE*);
    01067
    01068 ID rb_intern(const char*);
    01069 ID rb_intern2(const char*, long);
    01070 ID rb_intern_str(VALUE str);
    01071 const char *rb_id2name(ID);
    01072 ID rb_to_id(VALUE);
    01073 VALUE rb_id2str(ID);
    01074
    01075 #define CONST_ID_CACHE(result, str)                     \
    01076     {                                                   \
    01077         static ID rb_intern_id_cache;                   \
    01078         if (!rb_intern_id_cache)                        \
    01079             rb_intern_id_cache = rb_intern2(str, (long)strlen(str)); \
    01080         result rb_intern_id_cache;                      \
    01081     }
    01082 #define CONST_ID(var, str) \
    01083     do CONST_ID_CACHE(var =, str) while (0)
    01084 #ifdef __GNUC__
    01085 /* __builtin_constant_p and statement expression is available
    01086  * since gcc-2.7.2.3 at least. */
    01087 #define rb_intern(str) \
    01088     (__builtin_constant_p(str) ? \
    01089         __extension__ (CONST_ID_CACHE((ID), str)) :     \
    01090         rb_intern(str))
    01091 #define rb_intern_const(str) \
    01092     (__builtin_constant_p(str) ? \
    01093      __extension__ (rb_intern2(str, (long)strlen(str))) : \
    01094      (rb_intern)(str))
    01095 #else
    01096 #define rb_intern_const(str) rb_intern2(str, (long)strlen(str))
    01097 #endif
    01098
    01099 const char *rb_class2name(VALUE);
    01100 const char *rb_obj_classname(VALUE);
    01101
    01102 void rb_p(VALUE);
    01103
    01104 VALUE rb_eval_string(const char*);
    01105 VALUE rb_eval_string_protect(const char*, int*);
    01106 VALUE rb_eval_string_wrap(const char*, int*);
    01107 VALUE rb_funcall(VALUE, ID, int, ...);
    01108 VALUE rb_funcall2(VALUE, ID, int, const VALUE*);
    01109 VALUE rb_funcall3(VALUE, ID, int, const VALUE*);
    01110 int rb_scan_args(int, const VALUE*, const char*, ...);
    01111 VALUE rb_call_super(int, const VALUE*);
    01112
    01113 VALUE rb_gv_set(const char*, VALUE);
    01114 VALUE rb_gv_get(const char*);
    01115 VALUE rb_iv_get(VALUE, const char*);
    01116 VALUE rb_iv_set(VALUE, const char*, VALUE);
    01117
    01118 VALUE rb_equal(VALUE,VALUE);
    01119
    01120 VALUE *rb_ruby_verbose_ptr(void);
    01121 VALUE *rb_ruby_debug_ptr(void);
    01122 #define ruby_verbose (*rb_ruby_verbose_ptr())
    01123 #define ruby_debug   (*rb_ruby_debug_ptr())
    01124
    01125 PRINTF_ARGS(NORETURN(void rb_raise(VALUE, const char*, ...)), 2, 3);
    01126 PRINTF_ARGS(NORETURN(void rb_fatal(const char*, ...)), 1, 2);
    01127 PRINTF_ARGS(NORETURN(void rb_bug(const char*, ...)), 1, 2);
    01128 NORETURN(void rb_bug_errno(const char*, int));
    01129 NORETURN(void rb_sys_fail(const char*));
    01130 NORETURN(void rb_mod_sys_fail(VALUE, const char*));
    01131 NORETURN(void rb_iter_break(void));
    01132 NORETURN(void rb_exit(int));
    01133 NORETURN(void rb_notimplement(void));
    01134
    01135 /* reports if `-W' specified */
    01136 PRINTF_ARGS(void rb_warning(const char*, ...), 1, 2);
    01137 PRINTF_ARGS(void rb_compile_warning(const char *, int, const char*, ...), 3, 4);
    01138 PRINTF_ARGS(void rb_sys_warning(const char*, ...), 1, 2);
    01139 /* reports always */
    01140 PRINTF_ARGS(void rb_warn(const char*, ...), 1, 2);
    01141 PRINTF_ARGS(void rb_compile_warn(const char *, int, const char*, ...), 3, 4);
    01142
    01143 typedef VALUE rb_block_call_func(VALUE, VALUE, int, VALUE*);
    01144
    01145 VALUE rb_each(VALUE);
    01146 VALUE rb_yield(VALUE);
    01147 VALUE rb_yield_values(int n, ...);
    01148 VALUE rb_yield_values2(int n, const VALUE *argv);
    01149 VALUE rb_yield_splat(VALUE);
    01150 int rb_block_given_p(void);
    01151 void rb_need_block(void);
    01152 VALUE rb_iterate(VALUE(*)(VALUE),VALUE,VALUE(*)(ANYARGS),VALUE);
    01153 VALUE rb_block_call(VALUE,ID,int,VALUE*,VALUE(*)(ANYARGS),VALUE);
    01154 VALUE rb_rescue(VALUE(*)(ANYARGS),VALUE,VALUE(*)(ANYARGS),VALUE);
    01155 VALUE rb_rescue2(VALUE(*)(ANYARGS),VALUE,VALUE(*)(ANYARGS),VALUE,...);
    01156 VALUE rb_ensure(VALUE(*)(ANYARGS),VALUE,VALUE(*)(ANYARGS),VALUE);
    01157 VALUE rb_catch(const char*,VALUE(*)(ANYARGS),VALUE);
    01158 VALUE rb_catch_obj(VALUE,VALUE(*)(ANYARGS),VALUE);
    01159 NORETURN(void rb_throw(const char*,VALUE));
    01160 NORETURN(void rb_throw_obj(VALUE,VALUE));
    01161
    01162 VALUE rb_require(const char*);
    01163
    01164 #ifdef __ia64
    01165 void ruby_init_stack(volatile VALUE*, void*);
    01166 #define ruby_init_stack(addr) ruby_init_stack(addr, rb_ia64_bsp())
    01167 #else
    01168 void ruby_init_stack(volatile VALUE*);
    01169 #endif
    01170 #define RUBY_INIT_STACK \
    01171     VALUE variable_in_this_stack_frame; \
    01172     ruby_init_stack(&variable_in_this_stack_frame);
    01173 void ruby_init(void);
    01174 void *ruby_options(int, char**);
    01175 int ruby_run_node(void *);
    01176 int ruby_exec_node(void *);
    01177
    01178 RUBY_EXTERN VALUE rb_mKernel;
    01179 RUBY_EXTERN VALUE rb_mComparable;
    01180 RUBY_EXTERN VALUE rb_mEnumerable;
    01181 RUBY_EXTERN VALUE rb_mErrno;
    01182 RUBY_EXTERN VALUE rb_mFileTest;
    01183 RUBY_EXTERN VALUE rb_mGC;
    01184 RUBY_EXTERN VALUE rb_mMath;
    01185 RUBY_EXTERN VALUE rb_mProcess;
    01186 RUBY_EXTERN VALUE rb_mWaitReadable;
    01187 RUBY_EXTERN VALUE rb_mWaitWritable;
    01188
    01189 RUBY_EXTERN VALUE rb_cBasicObject;
    01190 RUBY_EXTERN VALUE rb_cObject;
    01191 RUBY_EXTERN VALUE rb_cArray;
    01192 RUBY_EXTERN VALUE rb_cBignum;
    01193 RUBY_EXTERN VALUE rb_cBinding;
    01194 RUBY_EXTERN VALUE rb_cClass;
    01195 RUBY_EXTERN VALUE rb_cCont;
    01196 RUBY_EXTERN VALUE rb_cDir;
    01197 RUBY_EXTERN VALUE rb_cData;
    01198 RUBY_EXTERN VALUE rb_cFalseClass;
    01199 RUBY_EXTERN VALUE rb_cEncoding;
    01200 RUBY_EXTERN VALUE rb_cEnumerator;
    01201 RUBY_EXTERN VALUE rb_cFile;
    01202 RUBY_EXTERN VALUE rb_cFixnum;
    01203 RUBY_EXTERN VALUE rb_cFloat;
    01204 RUBY_EXTERN VALUE rb_cHash;
    01205 RUBY_EXTERN VALUE rb_cInteger;
    01206 RUBY_EXTERN VALUE rb_cIO;
    01207 RUBY_EXTERN VALUE rb_cMatch;
    01208 RUBY_EXTERN VALUE rb_cMethod;
    01209 RUBY_EXTERN VALUE rb_cModule;
    01210 RUBY_EXTERN VALUE rb_cNameErrorMesg;
    01211 RUBY_EXTERN VALUE rb_cNilClass;
    01212 RUBY_EXTERN VALUE rb_cNumeric;
    01213 RUBY_EXTERN VALUE rb_cProc;
    01214 RUBY_EXTERN VALUE rb_cRandom;
    01215 RUBY_EXTERN VALUE rb_cRange;
    01216 RUBY_EXTERN VALUE rb_cRational;
    01217 RUBY_EXTERN VALUE rb_cComplex;
    01218 RUBY_EXTERN VALUE rb_cRegexp;
    01219 RUBY_EXTERN VALUE rb_cStat;
    01220 RUBY_EXTERN VALUE rb_cString;
    01221 RUBY_EXTERN VALUE rb_cStruct;
    01222 RUBY_EXTERN VALUE rb_cSymbol;
    01223 RUBY_EXTERN VALUE rb_cThread;
    01224 RUBY_EXTERN VALUE rb_cTime;
    01225 RUBY_EXTERN VALUE rb_cTrueClass;
    01226 RUBY_EXTERN VALUE rb_cUnboundMethod;
    01227
    01228 RUBY_EXTERN VALUE rb_eException;
    01229 RUBY_EXTERN VALUE rb_eStandardError;
    01230 RUBY_EXTERN VALUE rb_eSystemExit;
    01231 RUBY_EXTERN VALUE rb_eInterrupt;
    01232 RUBY_EXTERN VALUE rb_eSignal;
    01233 RUBY_EXTERN VALUE rb_eFatal;
    01234 RUBY_EXTERN VALUE rb_eArgError;
    01235 RUBY_EXTERN VALUE rb_eEOFError;
    01236 RUBY_EXTERN VALUE rb_eIndexError;
    01237 RUBY_EXTERN VALUE rb_eStopIteration;
    01238 RUBY_EXTERN VALUE rb_eKeyError;
    01239 RUBY_EXTERN VALUE rb_eRangeError;
    01240 RUBY_EXTERN VALUE rb_eIOError;
    01241 RUBY_EXTERN VALUE rb_eRuntimeError;
    01242 RUBY_EXTERN VALUE rb_eSecurityError;
    01243 RUBY_EXTERN VALUE rb_eSystemCallError;
    01244 RUBY_EXTERN VALUE rb_eThreadError;
    01245 RUBY_EXTERN VALUE rb_eTypeError;
    01246 RUBY_EXTERN VALUE rb_eZeroDivError;
    01247 RUBY_EXTERN VALUE rb_eNotImpError;
    01248 RUBY_EXTERN VALUE rb_eNoMemError;
    01249 RUBY_EXTERN VALUE rb_eNoMethodError;
    01250 RUBY_EXTERN VALUE rb_eFloatDomainError;
    01251 RUBY_EXTERN VALUE rb_eLocalJumpError;
    01252 RUBY_EXTERN VALUE rb_eSysStackError;
    01253 RUBY_EXTERN VALUE rb_eRegexpError;
    01254 RUBY_EXTERN VALUE rb_eEncodingError;
    01255 RUBY_EXTERN VALUE rb_eEncCompatError;
    01256
    01257 RUBY_EXTERN VALUE rb_eScriptError;
    01258 RUBY_EXTERN VALUE rb_eNameError;
    01259 RUBY_EXTERN VALUE rb_eSyntaxError;
    01260 RUBY_EXTERN VALUE rb_eLoadError;
    01261
    01262 RUBY_EXTERN VALUE rb_eMathDomainError;
    01263
    01264 RUBY_EXTERN VALUE rb_stdin, rb_stdout, rb_stderr;
    01265
    01266 static inline VALUE
    01267 rb_class_of(VALUE obj)
    01268 {
    01269     if (IMMEDIATE_P(obj)) {
    01270         if (FIXNUM_P(obj)) return rb_cFixnum;
    01271         if (obj == Qtrue)  return rb_cTrueClass;
    01272         if (SYMBOL_P(obj)) return rb_cSymbol;
    01273     }
    01274     else if (!RTEST(obj)) {
    01275         if (obj == Qnil)   return rb_cNilClass;
    01276         if (obj == Qfalse) return rb_cFalseClass;
    01277     }
    01278     return RBASIC(obj)->klass;
    01279 }
    01280
    01281 static inline int
    01282 rb_type(VALUE obj)
    01283 {
    01284     if (IMMEDIATE_P(obj)) {
    01285         if (FIXNUM_P(obj)) return T_FIXNUM;
    01286         if (obj == Qtrue) return T_TRUE;
    01287         if (SYMBOL_P(obj)) return T_SYMBOL;
    01288         if (obj == Qundef) return T_UNDEF;
    01289     }
    01290     else if (!RTEST(obj)) {
    01291         if (obj == Qnil) return T_NIL;
    01292         if (obj == Qfalse) return T_FALSE;
    01293     }
    01294     return BUILTIN_TYPE(obj);
    01295 }
    01296
    01297 #define RB_TYPE_P(obj, type) ( \
    01298         ((type) == T_FIXNUM) ? FIXNUM_P(obj) : \
    01299         ((type) == T_TRUE) ? ((obj) == Qtrue) : \
    01300         ((type) == T_FALSE) ? ((obj) == Qfalse) : \
    01301         ((type) == T_NIL) ? ((obj) == Qnil) : \
    01302         ((type) == T_UNDEF) ? ((obj) == Qundef) : \
    01303         ((type) == T_SYMBOL) ? SYMBOL_P(obj) : \
    01304         (!SPECIAL_CONST_P(obj) && BUILTIN_TYPE(obj) == (type)))
    01305
    01306 #ifdef __GNUC__
    01307 #define rb_type_p(obj, type) \
    01308     __extension__ (__builtin_constant_p(type) ? RB_TYPE_P(obj, type) : \
    01309                    rb_type(obj) == (type))
    01310 #else
    01311 #define rb_type_p(obj, type) (rb_type(obj) == (type))
    01312 #endif
    01313
    01314 #ifdef __GNUC__
    01315 #define rb_special_const_p(obj) \
    01316     __extension__ ({VALUE special_const_obj = (obj); (int)(SPECIAL_CONST_P(special_const_obj) ? Qtrue : Qfalse);})
    01317 #else
    01318 static inline int
    01319 rb_special_const_p(VALUE obj)
    01320 {
    01321     if (SPECIAL_CONST_P(obj)) return (int)Qtrue;
    01322     return (int)Qfalse;
    01323 }
    01324 #endif
    01325
    01326 #include "ruby/missing.h"
    01327 #include "ruby/intern.h"
    01328
    01329 #if defined(EXTLIB) && defined(USE_DLN_A_OUT)
    01330 /* hook for external modules */
    01331 static char *dln_libs_to_be_linked[] = { EXTLIB, 0 };
    01332 #endif
    01333
    01334 #if (defined(__APPLE__) || defined(__NeXT__)) && defined(__MACH__)
    01335 #define RUBY_GLOBAL_SETUP /* use linker option to link startup code with ObjC support */
    01336 #else
    01337 #define RUBY_GLOBAL_SETUP
    01338 #endif
    01339
    01340 void ruby_sysinit(int *, char ***);
    01341
    01342 #define RUBY_VM 1 /* YARV */
    01343 #define HAVE_NATIVETHREAD
    01344 int ruby_native_thread_p(void);
    01345
    01346 #define RUBY_EVENT_NONE      0x0000
    01347 #define RUBY_EVENT_LINE      0x0001
    01348 #define RUBY_EVENT_CLASS     0x0002
    01349 #define RUBY_EVENT_END       0x0004
    01350 #define RUBY_EVENT_CALL      0x0008
    01351 #define RUBY_EVENT_RETURN    0x0010
    01352 #define RUBY_EVENT_C_CALL    0x0020
    01353 #define RUBY_EVENT_C_RETURN  0x0040
    01354 #define RUBY_EVENT_RAISE     0x0080
    01355 #define RUBY_EVENT_ALL       0xffff
    01356 #define RUBY_EVENT_VM       0x10000
    01357 #define RUBY_EVENT_SWITCH   0x20000
    01358 #define RUBY_EVENT_COVERAGE 0x40000
    01359
    01360 typedef unsigned int rb_event_flag_t;
    01361 typedef void (*rb_event_hook_func_t)(rb_event_flag_t, VALUE data, VALUE, ID, VALUE klass);
    01362
    01363 typedef struct rb_event_hook_struct {
    01364     rb_event_flag_t flag;
    01365     rb_event_hook_func_t func;
    01366     VALUE data;
    01367     struct rb_event_hook_struct *next;
    01368 } rb_event_hook_t;
    01369
    01370 #define RB_EVENT_HOOKS_HAVE_CALLBACK_DATA 1
    01371 void rb_add_event_hook(rb_event_hook_func_t func, rb_event_flag_t events,
    01372                        VALUE data);
    01373 int rb_remove_event_hook(rb_event_hook_func_t func);
    01374
    01375 /* locale insensitive functions */
    01376
    01377 #define rb_isascii(c) ((unsigned long)(c) < 128)
    01378 int rb_isalnum(int c);
    01379 int rb_isalpha(int c);
    01380 int rb_isblank(int c);
    01381 int rb_iscntrl(int c);
    01382 int rb_isdigit(int c);
    01383 int rb_isgraph(int c);
    01384 int rb_islower(int c);
    01385 int rb_isprint(int c);
    01386 int rb_ispunct(int c);
    01387 int rb_isspace(int c);
    01388 int rb_isupper(int c);
    01389 int rb_isxdigit(int c);
    01390 int rb_tolower(int c);
    01391 int rb_toupper(int c);
    01392
    01393 #ifndef ISPRINT
    01394 #define ISASCII(c) rb_isascii((unsigned char)(c))
    01395 #undef ISPRINT
    01396 #define ISPRINT(c) rb_isprint((unsigned char)(c))
    01397 #define ISSPACE(c) rb_isspace((unsigned char)(c))
    01398 #define ISUPPER(c) rb_isupper((unsigned char)(c))
    01399 #define ISLOWER(c) rb_islower((unsigned char)(c))
    01400 #define ISALNUM(c) rb_isalnum((unsigned char)(c))
    01401 #define ISALPHA(c) rb_isalpha((unsigned char)(c))
    01402 #define ISDIGIT(c) rb_isdigit((unsigned char)(c))
    01403 #define ISXDIGIT(c) rb_isxdigit((unsigned char)(c))
    01404 #endif
    01405 #define TOUPPER(c) rb_toupper((unsigned char)(c))
    01406 #define TOLOWER(c) rb_tolower((unsigned char)(c))
    01407
    01408 int st_strcasecmp(const char *s1, const char *s2);
    01409 int st_strncasecmp(const char *s1, const char *s2, size_t n);
    01410 #define STRCASECMP(s1, s2) (st_strcasecmp(s1, s2))
    01411 #define STRNCASECMP(s1, s2, n) (st_strncasecmp(s1, s2, n))
    01412
    01413 unsigned long ruby_strtoul(const char *str, char **endptr, int base);
    01414 #define STRTOUL(str, endptr, base) (ruby_strtoul(str, endptr, base))
    01415
    01416 #define InitVM(ext) {void InitVM_##ext(void);InitVM_##ext();}
    01417
    01418 int ruby_snprintf(char *str, size_t n, char const *fmt, ...);
    01419 int ruby_vsnprintf(char *str, size_t n, char const *fmt, va_list ap);
    01420 #undef snprintf
    01421 #undef vsnprintf
    01422 #define snprintf ruby_snprintf
    01423 #define vsnprintf ruby_vsnprintf
    01424
    01425 #ifdef BROKEN_CLOSE
    01426 #undef getpeername
    01427 #define getpeername ruby_getpeername
    01428 #undef getsockname
    01429 #define getsockname ruby_getsockname
    01430 #undef shutdown
    01431 #define shutdown ruby_shutdown
    01432 #undef close
    01433 #define close ruby_close
    01434 #endif
    01435
    01436 #if defined(__cplusplus)
    01437 #if 0
    01438 { /* satisfy cc-mode */
    01439 #endif
    01440 }  /* extern "C" { */
    01441 #endif
    01442 #endif /* RUBY_RUBY_H */
    01443