internal.h

Go to the documentation of this file.
00001 /**********************************************************************
00002 
00003   internal.h -
00004 
00005   $Author$
00006   created at: Tue May 17 11:42:20 JST 2011
00007 
00008   Copyright (C) 2011 Yukihiro Matsumoto
00009 
00010 **********************************************************************/
00011 
00012 #ifndef RUBY_INTERNAL_H
00013 #define RUBY_INTERNAL_H 1
00014 
00015 #if defined(__cplusplus)
00016 extern "C" {
00017 #if 0
00018 } /* satisfy cc-mode */
00019 #endif
00020 #endif
00021 
00022 #ifdef HAVE_VALGRIND_MEMCHECK_H
00023 # include <valgrind/memcheck.h>
00024 # ifndef VALGRIND_MAKE_MEM_DEFINED
00025 #  define VALGRIND_MAKE_MEM_DEFINED(p, n) VALGRIND_MAKE_READABLE((p), (n))
00026 # endif
00027 # ifndef VALGRIND_MAKE_MEM_UNDEFINED
00028 #  define VALGRIND_MAKE_MEM_UNDEFINED(p, n) VALGRIND_MAKE_WRITABLE((p), (n))
00029 # endif
00030 #else
00031 # define VALGRIND_MAKE_MEM_DEFINED(p, n) 0
00032 # define VALGRIND_MAKE_MEM_UNDEFINED(p, n) 0
00033 #endif
00034 
00035 #define numberof(array) ((int)(sizeof(array) / sizeof((array)[0])))
00036 
00037 #define STATIC_ASSERT(name, expr) typedef int static_assert_##name##_check[1 - 2*!(expr)]
00038 
00039 #define GCC_VERSION_SINCE(major, minor, patchlevel) \
00040   (defined(__GNUC__) && !defined(__INTEL_COMPILER) && \
00041    ((__GNUC__ > (major)) ||  \
00042     (__GNUC__ == (major) && __GNUC_MINOR__ > (minor)) || \
00043     (__GNUC__ == (major) && __GNUC_MINOR__ == (minor) && __GNUC_PATCHLEVEL__ >= (patchlevel))))
00044 
00045 #define SIGNED_INTEGER_TYPE_P(int_type) (0 > ((int_type)0)-1)
00046 #define SIGNED_INTEGER_MAX(sint_type) \
00047   (sint_type) \
00048   ((((sint_type)1) << (sizeof(sint_type) * CHAR_BIT - 2)) | \
00049   ((((sint_type)1) << (sizeof(sint_type) * CHAR_BIT - 2)) - 1))
00050 #define SIGNED_INTEGER_MIN(sint_type) (-SIGNED_INTEGER_MAX(sint_type)-1)
00051 #define UNSIGNED_INTEGER_MAX(uint_type) (~(uint_type)0)
00052 
00053 #if SIGNEDNESS_OF_TIME_T < 0    /* signed */
00054 # define TIMET_MAX SIGNED_INTEGER_MAX(time_t)
00055 # define TIMET_MIN SIGNED_INTEGER_MIN(time_t)
00056 #elif SIGNEDNESS_OF_TIME_T > 0  /* unsigned */
00057 # define TIMET_MAX UNSIGNED_INTEGER_MAX(time_t)
00058 # define TIMET_MIN ((time_t)0)
00059 #endif
00060 #define TIMET_MAX_PLUS_ONE (2*(double)(TIMET_MAX/2+1))
00061 
00062 #define MUL_OVERFLOW_SIGNED_INTEGER_P(a, b, min, max) ( \
00063     (a) == 0 ? 0 : \
00064     (a) == -1 ? (b) < -(max) : \
00065     (a) > 0 ? \
00066       ((b) > 0 ? (max) / (a) < (b) : (min) / (a) > (b)) : \
00067       ((b) > 0 ? (min) / (a) < (b) : (max) / (a) > (b)))
00068 #define MUL_OVERFLOW_FIXNUM_P(a, b) MUL_OVERFLOW_SIGNED_INTEGER_P(a, b, FIXNUM_MIN, FIXNUM_MAX)
00069 #define MUL_OVERFLOW_LONG_P(a, b) MUL_OVERFLOW_SIGNED_INTEGER_P(a, b, LONG_MIN, LONG_MAX)
00070 #define MUL_OVERFLOW_INT_P(a, b) MUL_OVERFLOW_SIGNED_INTEGER_P(a, b, INT_MIN, INT_MAX)
00071 
00072 #ifndef swap16
00073 # ifdef HAVE_BUILTIN___BUILTIN_BSWAP16
00074 #  define swap16(x) __builtin_bswap16(x)
00075 # endif
00076 #endif
00077 
00078 #ifndef swap16
00079 # define swap16(x)      ((uint16_t)((((x)&0xFF)<<8) | (((x)>>8)&0xFF)))
00080 #endif
00081 
00082 #ifndef swap32
00083 # ifdef HAVE_BUILTIN___BUILTIN_BSWAP32
00084 #  define swap32(x) __builtin_bswap32(x)
00085 # endif
00086 #endif
00087 
00088 #ifndef swap32
00089 # define swap32(x)      ((uint32_t)((((x)&0xFF)<<24)    \
00090                         |(((x)>>24)&0xFF)       \
00091                         |(((x)&0x0000FF00)<<8)  \
00092                         |(((x)&0x00FF0000)>>8)  ))
00093 #endif
00094 
00095 #ifndef swap64
00096 # ifdef HAVE_BUILTIN___BUILTIN_BSWAP64
00097 #  define swap64(x) __builtin_bswap64(x)
00098 # endif
00099 #endif
00100 
00101 #ifndef swap64
00102 # ifdef HAVE_INT64_T
00103 #  define byte_in_64bit(n) ((uint64_t)0xff << (n))
00104 #  define swap64(x)       ((uint64_t)((((x)&byte_in_64bit(0))<<56)      \
00105                            |(((x)>>56)&0xFF)                    \
00106                            |(((x)&byte_in_64bit(8))<<40)        \
00107                            |(((x)&byte_in_64bit(48))>>40)       \
00108                            |(((x)&byte_in_64bit(16))<<24)       \
00109                            |(((x)&byte_in_64bit(40))>>24)       \
00110                            |(((x)&byte_in_64bit(24))<<8)        \
00111                            |(((x)&byte_in_64bit(32))>>8)))
00112 # endif
00113 #endif
00114 
00115 static inline int
00116 nlz_int(unsigned int x)
00117 {
00118 #if defined(HAVE_BUILTIN___BUILTIN_CLZ)
00119     if (x == 0) return SIZEOF_INT * CHAR_BIT;
00120     return __builtin_clz(x);
00121 #else
00122     unsigned int y;
00123 # if 64 < SIZEOF_INT * CHAR_BIT
00124     int n = 128;
00125 # elif 32 < SIZEOF_INT * CHAR_BIT
00126     int n = 64;
00127 # else
00128     int n = 32;
00129 # endif
00130 # if 64 < SIZEOF_INT * CHAR_BIT
00131     y = x >> 64; if (y) {n -= 64; x = y;}
00132 # endif
00133 # if 32 < SIZEOF_INT * CHAR_BIT
00134     y = x >> 32; if (y) {n -= 32; x = y;}
00135 # endif
00136     y = x >> 16; if (y) {n -= 16; x = y;}
00137     y = x >>  8; if (y) {n -=  8; x = y;}
00138     y = x >>  4; if (y) {n -=  4; x = y;}
00139     y = x >>  2; if (y) {n -=  2; x = y;}
00140     y = x >>  1; if (y) {return n - 2;}
00141     return (int)(n - x);
00142 #endif
00143 }
00144 
00145 static inline int
00146 nlz_long(unsigned long x)
00147 {
00148 #if defined(HAVE_BUILTIN___BUILTIN_CLZL)
00149     if (x == 0) return SIZEOF_LONG * CHAR_BIT;
00150     return __builtin_clzl(x);
00151 #else
00152     unsigned long y;
00153 # if 64 < SIZEOF_LONG * CHAR_BIT
00154     int n = 128;
00155 # elif 32 < SIZEOF_LONG * CHAR_BIT
00156     int n = 64;
00157 # else
00158     int n = 32;
00159 # endif
00160 # if 64 < SIZEOF_LONG * CHAR_BIT
00161     y = x >> 64; if (y) {n -= 64; x = y;}
00162 # endif
00163 # if 32 < SIZEOF_LONG * CHAR_BIT
00164     y = x >> 32; if (y) {n -= 32; x = y;}
00165 # endif
00166     y = x >> 16; if (y) {n -= 16; x = y;}
00167     y = x >>  8; if (y) {n -=  8; x = y;}
00168     y = x >>  4; if (y) {n -=  4; x = y;}
00169     y = x >>  2; if (y) {n -=  2; x = y;}
00170     y = x >>  1; if (y) {return n - 2;}
00171     return (int)(n - x);
00172 #endif
00173 }
00174 
00175 #ifdef HAVE_LONG_LONG
00176 static inline int
00177 nlz_long_long(unsigned LONG_LONG x)
00178 {
00179 #if defined(HAVE_BUILTIN___BUILTIN_CLZLL)
00180     if (x == 0) return SIZEOF_LONG_LONG * CHAR_BIT;
00181     return __builtin_clzll(x);
00182 #else
00183     unsigned LONG_LONG y;
00184 # if 64 < SIZEOF_LONG_LONG * CHAR_BIT
00185     int n = 128;
00186 # elif 32 < SIZEOF_LONG_LONG * CHAR_BIT
00187     int n = 64;
00188 # else
00189     int n = 32;
00190 # endif
00191 # if 64 < SIZEOF_LONG_LONG * CHAR_BIT
00192     y = x >> 64; if (y) {n -= 64; x = y;}
00193 # endif
00194 # if 32 < SIZEOF_LONG_LONG * CHAR_BIT
00195     y = x >> 32; if (y) {n -= 32; x = y;}
00196 # endif
00197     y = x >> 16; if (y) {n -= 16; x = y;}
00198     y = x >>  8; if (y) {n -=  8; x = y;}
00199     y = x >>  4; if (y) {n -=  4; x = y;}
00200     y = x >>  2; if (y) {n -=  2; x = y;}
00201     y = x >>  1; if (y) {return n - 2;}
00202     return (int)(n - x);
00203 #endif
00204 }
00205 #endif
00206 
00207 #ifdef HAVE_UINT128_T
00208 static inline int
00209 nlz_int128(uint128_t x)
00210 {
00211     uint128_t y;
00212     int n = 128;
00213     y = x >> 64; if (y) {n -= 64; x = y;}
00214     y = x >> 32; if (y) {n -= 32; x = y;}
00215     y = x >> 16; if (y) {n -= 16; x = y;}
00216     y = x >>  8; if (y) {n -=  8; x = y;}
00217     y = x >>  4; if (y) {n -=  4; x = y;}
00218     y = x >>  2; if (y) {n -=  2; x = y;}
00219     y = x >>  1; if (y) {return n - 2;}
00220     return (int)(n - x);
00221 }
00222 #endif
00223 
00224 #if defined(HAVE_UINT128_T)
00225 #   define bit_length(x) \
00226     (sizeof(x) <= SIZEOF_INT ? SIZEOF_INT * CHAR_BIT - nlz_int((unsigned int)(x)) : \
00227      sizeof(x) <= SIZEOF_LONG ? SIZEOF_LONG * CHAR_BIT - nlz_long((unsigned long)(x)) : \
00228      sizeof(x) <= SIZEOF_LONG_LONG ? SIZEOF_LONG_LONG * CHAR_BIT - nlz_long_long((unsigned LONG_LONG)(x)) : \
00229      SIZEOF_INT128_T * CHAR_BIT - nlz_int128((uint128_t)(x)))
00230 #elif defined(HAVE_LONG_LONG)
00231 #   define bit_length(x) \
00232     (sizeof(x) <= SIZEOF_INT ? SIZEOF_INT * CHAR_BIT - nlz_int((unsigned int)(x)) : \
00233      sizeof(x) <= SIZEOF_LONG ? SIZEOF_LONG * CHAR_BIT - nlz_long((unsigned long)(x)) : \
00234      SIZEOF_LONG_LONG * CHAR_BIT - nlz_long_long((unsigned LONG_LONG)(x)))
00235 #else
00236 #   define bit_length(x) \
00237     (sizeof(x) <= SIZEOF_INT ? SIZEOF_INT * CHAR_BIT - nlz_int((unsigned int)(x)) : \
00238      SIZEOF_LONG * CHAR_BIT - nlz_long((unsigned long)(x)))
00239 #endif
00240 
00241 struct rb_deprecated_classext_struct {
00242     char conflict[sizeof(VALUE) * 3];
00243 };
00244 
00245 struct rb_subclass_entry;
00246 typedef struct rb_subclass_entry rb_subclass_entry_t;
00247 
00248 struct rb_subclass_entry {
00249     VALUE klass;
00250     rb_subclass_entry_t *next;
00251 };
00252 
00253 #if defined(HAVE_LONG_LONG)
00254 typedef unsigned LONG_LONG rb_serial_t;
00255 #define SERIALT2NUM ULL2NUM
00256 #elif defined(HAVE_UINT64_T)
00257 typedef uint64_t rb_serial_t;
00258 #define SERIALT2NUM SIZET2NUM
00259 #else
00260 typedef unsigned long rb_serial_t;
00261 #define SERIALT2NUM ULONG2NUM
00262 #endif
00263 
00264 struct rb_classext_struct {
00265     struct st_table *iv_index_tbl;
00266     struct st_table *iv_tbl;
00267     struct st_table *const_tbl;
00268     rb_subclass_entry_t *subclasses;
00269     rb_subclass_entry_t **parent_subclasses;
00275     rb_subclass_entry_t **module_subclasses;
00276     rb_serial_t class_serial;
00277     VALUE origin;
00278     VALUE refined_class;
00279     rb_alloc_func_t allocator;
00280 };
00281 
00282 struct method_table_wrapper {
00283     st_table *tbl;
00284     size_t serial;
00285 };
00286 
00287 /* class.c */
00288 void rb_class_subclass_add(VALUE super, VALUE klass);
00289 void rb_class_remove_from_super_subclasses(VALUE);
00290 
00291 #define RCLASS_EXT(c) (RCLASS(c)->ptr)
00292 #define RCLASS_IV_TBL(c) (RCLASS_EXT(c)->iv_tbl)
00293 #define RCLASS_CONST_TBL(c) (RCLASS_EXT(c)->const_tbl)
00294 #define RCLASS_M_TBL_WRAPPER(c) (RCLASS(c)->m_tbl_wrapper)
00295 #define RCLASS_M_TBL(c) (RCLASS_M_TBL_WRAPPER(c) ? RCLASS_M_TBL_WRAPPER(c)->tbl : 0)
00296 #define RCLASS_IV_INDEX_TBL(c) (RCLASS_EXT(c)->iv_index_tbl)
00297 #define RCLASS_ORIGIN(c) (RCLASS_EXT(c)->origin)
00298 #define RCLASS_REFINED_CLASS(c) (RCLASS_EXT(c)->refined_class)
00299 #define RCLASS_SERIAL(c) (RCLASS_EXT(c)->class_serial)
00300 
00301 static inline void
00302 RCLASS_M_TBL_INIT(VALUE c)
00303 {
00304     struct method_table_wrapper *wrapper;
00305     wrapper = ALLOC(struct method_table_wrapper);
00306     wrapper->tbl = st_init_numtable();
00307     wrapper->serial = 0;
00308     RCLASS_M_TBL_WRAPPER(c) = wrapper;
00309 }
00310 
00311 #undef RCLASS_SUPER
00312 static inline VALUE
00313 RCLASS_SUPER(VALUE klass)
00314 {
00315     return RCLASS(klass)->super;
00316 }
00317 
00318 static inline VALUE
00319 RCLASS_SET_SUPER(VALUE klass, VALUE super)
00320 {
00321     if (super) {
00322         rb_class_remove_from_super_subclasses(klass);
00323         rb_class_subclass_add(super, klass);
00324     }
00325     RB_OBJ_WRITE(klass, &RCLASS(klass)->super, super);
00326     return super;
00327 }
00328 
00329 struct vtm; /* defined by timev.h */
00330 
00331 /* array.c */
00332 VALUE rb_ary_last(int, VALUE *, VALUE);
00333 void rb_ary_set_len(VALUE, long);
00334 void rb_ary_delete_same(VALUE, VALUE);
00335 
00336 /* bignum.c */
00337 VALUE rb_big_fdiv(VALUE x, VALUE y);
00338 VALUE rb_big_uminus(VALUE x);
00339 VALUE rb_integer_float_cmp(VALUE x, VALUE y);
00340 VALUE rb_integer_float_eq(VALUE x, VALUE y);
00341 
00342 /* class.c */
00343 void rb_class_foreach_subclass(VALUE klass, void(*f)(VALUE));
00344 void rb_class_detach_subclasses(VALUE);
00345 void rb_class_detach_module_subclasses(VALUE);
00346 void rb_class_remove_from_module_subclasses(VALUE);
00347 VALUE rb_obj_methods(int argc, VALUE *argv, VALUE obj);
00348 VALUE rb_obj_protected_methods(int argc, VALUE *argv, VALUE obj);
00349 VALUE rb_obj_private_methods(int argc, VALUE *argv, VALUE obj);
00350 VALUE rb_obj_public_methods(int argc, VALUE *argv, VALUE obj);
00351 int rb_obj_basic_to_s_p(VALUE);
00352 VALUE rb_special_singleton_class(VALUE);
00353 VALUE rb_singleton_class_clone_and_attach(VALUE obj, VALUE attach);
00354 VALUE rb_singleton_class_get(VALUE obj);
00355 void Init_class_hierarchy(void);
00356 
00357 /* compar.c */
00358 VALUE rb_invcmp(VALUE, VALUE);
00359 
00360 /* compile.c */
00361 int rb_dvar_defined(ID);
00362 int rb_local_defined(ID);
00363 int rb_parse_in_eval(void);
00364 int rb_parse_in_main(void);
00365 const char * rb_insns_name(int i);
00366 VALUE rb_insns_name_array(void);
00367 
00368 /* cont.c */
00369 VALUE rb_obj_is_fiber(VALUE);
00370 void rb_fiber_reset_root_local_storage(VALUE);
00371 void ruby_register_rollback_func_for_ensure(VALUE (*ensure_func)(ANYARGS), VALUE (*rollback_func)(ANYARGS));
00372 
00373 /* debug.c */
00374 PRINTF_ARGS(void ruby_debug_printf(const char*, ...), 1, 2);
00375 
00376 /* dmyext.c */
00377 void Init_ext(void);
00378 
00379 /* encoding.c */
00380 #ifdef RUBY_ENCODING_H
00381 enum ruby_preserved_encindex {
00382     ENCINDEX_ASCII,
00383     ENCINDEX_UTF_8,
00384     ENCINDEX_US_ASCII,
00385 
00386     /* preserved indexes */
00387     ENCINDEX_UTF_16BE,
00388     ENCINDEX_UTF_16LE,
00389     ENCINDEX_UTF_32BE,
00390     ENCINDEX_UTF_32LE,
00391     ENCINDEX_UTF_16,
00392     ENCINDEX_UTF_32,
00393     ENCINDEX_UTF8_MAC,
00394 
00395     /* for old options of regexp */
00396     ENCINDEX_EUC_JP,
00397     ENCINDEX_Windows_31J,
00398 
00399     ENCINDEX_BUILTIN_MAX
00400 };
00401 #endif
00402 #define rb_ascii8bit_encindex() ENCINDEX_ASCII
00403 #define rb_utf8_encindex()      ENCINDEX_UTF_8
00404 #define rb_usascii_encindex()   ENCINDEX_US_ASCII
00405 ID rb_id_encoding(void);
00406 void rb_gc_mark_encodings(void);
00407 
00408 /* error.c */
00409 NORETURN(PRINTF_ARGS(void rb_compile_bug(const char*, int, const char*, ...), 3, 4));
00410 VALUE rb_check_backtrace(VALUE);
00411 NORETURN(void rb_async_bug_errno(const char *,int));
00412 const char *rb_builtin_type_name(int t);
00413 const char *rb_builtin_class_name(VALUE x);
00414 
00415 /* eval.c */
00416 VALUE rb_refinement_module_get_refined_class(VALUE module);
00417 
00418 /* eval_error.c */
00419 void ruby_error_print(void);
00420 VALUE rb_get_backtrace(VALUE info);
00421 
00422 /* eval_jump.c */
00423 void rb_call_end_proc(VALUE data);
00424 void rb_mark_end_proc(void);
00425 
00426 /* file.c */
00427 VALUE rb_home_dir_of(VALUE user, VALUE result);
00428 VALUE rb_default_home_dir(VALUE result);
00429 VALUE rb_realpath_internal(VALUE basedir, VALUE path, int strict);
00430 void rb_file_const(const char*, VALUE);
00431 int rb_file_load_ok(const char *);
00432 VALUE rb_file_expand_path_fast(VALUE, VALUE);
00433 VALUE rb_file_expand_path_internal(VALUE, VALUE, int, int, VALUE);
00434 VALUE rb_get_path_check_to_string(VALUE, int);
00435 VALUE rb_get_path_check_convert(VALUE, VALUE, int);
00436 void Init_File(void);
00437 
00438 #ifdef RUBY_FUNCTION_NAME_STRING
00439 # if defined __GNUC__ && __GNUC__ >= 4
00440 #   pragma GCC visibility push(default)
00441 # endif
00442 NORETURN(void rb_sys_fail_path_in(const char *func_name, VALUE path));
00443 NORETURN(void rb_syserr_fail_path_in(const char *func_name, int err, VALUE path));
00444 # if defined __GNUC__ && __GNUC__ >= 4
00445 #   pragma GCC visibility pop
00446 # endif
00447 # define rb_sys_fail_path(path) rb_sys_fail_path_in(RUBY_FUNCTION_NAME_STRING, path)
00448 # define rb_syserr_fail_path(err, path) rb_syserr_fail_path_in(RUBY_FUNCTION_NAME_STRING, (err), (path))
00449 #else
00450 # define rb_sys_fail_path(path) rb_sys_fail_str(path)
00451 # define rb_syserr_fail_path(err, path) rb_syserr_fail_str((err), (path))
00452 #endif
00453 
00454 /* gc.c */
00455 void Init_heap(void);
00456 void *ruby_mimmalloc(size_t size);
00457 void ruby_mimfree(void *ptr);
00458 void rb_objspace_set_event_hook(const rb_event_flag_t event);
00459 void rb_gc_writebarrier_remember_promoted(VALUE obj);
00460 void ruby_gc_set_params(int safe_level);
00461 
00462 #if defined(HAVE_MALLOC_USABLE_SIZE) || defined(HAVE_MALLOC_SIZE) || defined(_WIN32)
00463 #define ruby_sized_xrealloc(ptr, new_size, old_size) ruby_xrealloc(ptr, new_size)
00464 #define ruby_sized_xrealloc2(ptr, new_count, element_size, old_count) ruby_xrealloc(ptr, new_count, element_size)
00465 #define ruby_sized_xfree(ptr, size) ruby_xfree(ptr)
00466 #define SIZED_REALLOC_N(var,type,n,old_n) REALLOC_N(var, type, n)
00467 #else
00468 void *ruby_sized_xrealloc(void *ptr, size_t new_size, size_t old_size) RUBY_ATTR_ALLOC_SIZE((2));
00469 void *ruby_sized_xrealloc2(void *ptr, size_t new_count, size_t element_size, size_t old_count) RUBY_ATTR_ALLOC_SIZE((2, 3));
00470 void ruby_sized_xfree(void *x, size_t size);
00471 #define SIZED_REALLOC_N(var,type,n,old_n) ((var)=(type*)ruby_sized_xrealloc((char*)(var), (n) * sizeof(type), (old_n) * sizeof(type)))
00472 #endif
00473 
00474 void rb_gc_resurrect(VALUE ptr);
00475 
00476 /* hash.c */
00477 struct st_table *rb_hash_tbl_raw(VALUE hash);
00478 #define RHASH_TBL_RAW(h) rb_hash_tbl_raw(h)
00479 VALUE rb_hash_keys(VALUE hash);
00480 VALUE rb_hash_values(VALUE hash);
00481 #define HASH_DELETED  FL_USER1
00482 #define HASH_PROC_DEFAULT FL_USER2
00483 
00484 /* inits.c */
00485 void rb_call_inits(void);
00486 
00487 /* io.c */
00488 const char *ruby_get_inplace_mode(void);
00489 void ruby_set_inplace_mode(const char *);
00490 ssize_t rb_io_bufread(VALUE io, void *buf, size_t size);
00491 void rb_stdio_set_default_encoding(void);
00492 void rb_write_error_str(VALUE mesg);
00493 VALUE rb_io_flush_raw(VALUE, int);
00494 
00495 /* iseq.c */
00496 VALUE rb_iseq_clone(VALUE iseqval, VALUE newcbase);
00497 VALUE rb_iseq_path(VALUE iseqval);
00498 VALUE rb_iseq_absolute_path(VALUE iseqval);
00499 VALUE rb_iseq_label(VALUE iseqval);
00500 VALUE rb_iseq_base_label(VALUE iseqval);
00501 VALUE rb_iseq_first_lineno(VALUE iseqval);
00502 VALUE rb_iseq_klass(VALUE iseqval); /* completely temporary fucntion */
00503 VALUE rb_iseq_method_name(VALUE self);
00504 
00505 /* load.c */
00506 VALUE rb_get_load_path(void);
00507 VALUE rb_get_expanded_load_path(void);
00508 NORETURN(void rb_load_fail(VALUE, const char*));
00509 
00510 /* math.c */
00511 VALUE rb_math_atan2(VALUE, VALUE);
00512 VALUE rb_math_cos(VALUE);
00513 VALUE rb_math_cosh(VALUE);
00514 VALUE rb_math_exp(VALUE);
00515 VALUE rb_math_hypot(VALUE, VALUE);
00516 VALUE rb_math_log(int argc, VALUE *argv);
00517 VALUE rb_math_sin(VALUE);
00518 VALUE rb_math_sinh(VALUE);
00519 VALUE rb_math_sqrt(VALUE);
00520 
00521 /* newline.c */
00522 void Init_newline(void);
00523 
00524 /* numeric.c */
00525 int rb_num_to_uint(VALUE val, unsigned int *ret);
00526 VALUE ruby_num_interval_step_size(VALUE from, VALUE to, VALUE step, int excl);
00527 int ruby_float_step(VALUE from, VALUE to, VALUE step, int excl);
00528 double ruby_float_mod(double x, double y);
00529 int rb_num_negative_p(VALUE);
00530 VALUE rb_int_succ(VALUE num);
00531 VALUE rb_int_pred(VALUE num);
00532 
00533 #if USE_FLONUM
00534 #define RUBY_BIT_ROTL(v, n) (((v) << (n)) | ((v) >> ((sizeof(v) * 8) - n)))
00535 #define RUBY_BIT_ROTR(v, n) (((v) >> (n)) | ((v) << ((sizeof(v) * 8) - n)))
00536 #endif
00537 
00538 static inline double
00539 rb_float_value_inline(VALUE v)
00540 {
00541 #if USE_FLONUM
00542     if (FLONUM_P(v)) {
00543         if (v != (VALUE)0x8000000000000002) { /* LIKELY */
00544             union {
00545                 double d;
00546                 VALUE v;
00547             } t;
00548 
00549             VALUE b63 = (v >> 63);
00550             /* e: xx1... -> 011... */
00551             /*    xx0... -> 100... */
00552             /*      ^b63           */
00553             t.v = RUBY_BIT_ROTR((2 - b63) | (v & ~0x03), 3);
00554             return t.d;
00555         }
00556         else {
00557             return 0.0;
00558         }
00559     }
00560 #endif
00561     return ((struct RFloat *)v)->float_value;
00562 }
00563 
00564 static inline VALUE
00565 rb_float_new_inline(double d)
00566 {
00567 #if USE_FLONUM
00568     union {
00569         double d;
00570         VALUE v;
00571     } t;
00572     int bits;
00573 
00574     t.d = d;
00575     bits = (int)((VALUE)(t.v >> 60) & 0x7);
00576     /* bits contains 3 bits of b62..b60. */
00577     /* bits - 3 = */
00578     /*   b011 -> b000 */
00579     /*   b100 -> b001 */
00580 
00581     if (t.v != 0x3000000000000000 /* 1.72723e-77 */ &&
00582         !((bits-3) & ~0x01)) {
00583         return (RUBY_BIT_ROTL(t.v, 3) & ~(VALUE)0x01) | 0x02;
00584     }
00585     else if (t.v == (VALUE)0) {
00586         /* +0.0 */
00587         return 0x8000000000000002;
00588     }
00589     /* out of range */
00590 #endif
00591     return rb_float_new_in_heap(d);
00592 }
00593 
00594 #define rb_float_value(v) rb_float_value_inline(v)
00595 #define rb_float_new(d)   rb_float_new_inline(d)
00596 
00597 /* object.c */
00598 void rb_obj_copy_ivar(VALUE dest, VALUE obj);
00599 VALUE rb_obj_equal(VALUE obj1, VALUE obj2);
00600 VALUE rb_class_search_ancestor(VALUE klass, VALUE super);
00601 
00602 struct RBasicRaw {
00603     VALUE flags;
00604     VALUE klass;
00605 };
00606 
00607 #define RBASIC_CLEAR_CLASS(obj)        (((struct RBasicRaw *)((VALUE)(obj)))->klass = 0)
00608 #define RBASIC_SET_CLASS_RAW(obj, cls) (((struct RBasicRaw *)((VALUE)(obj)))->klass = (cls))
00609 #define RBASIC_SET_CLASS(obj, cls)     do { \
00610     VALUE _obj_ = (obj); \
00611     RB_OBJ_WRITE(_obj_, &((struct RBasicRaw *)(_obj_))->klass, cls); \
00612 } while (0)
00613 
00614 /* parse.y */
00615 VALUE rb_parser_get_yydebug(VALUE);
00616 VALUE rb_parser_set_yydebug(VALUE, VALUE);
00617 int rb_is_const_name(VALUE name);
00618 int rb_is_class_name(VALUE name);
00619 int rb_is_global_name(VALUE name);
00620 int rb_is_instance_name(VALUE name);
00621 int rb_is_attrset_name(VALUE name);
00622 int rb_is_local_name(VALUE name);
00623 int rb_is_method_name(VALUE name);
00624 int rb_is_junk_name(VALUE name);
00625 void rb_gc_mark_parser(void);
00626 void rb_gc_mark_symbols(int full_mark);
00627 
00628 /* proc.c */
00629 VALUE rb_proc_location(VALUE self);
00630 st_index_t rb_hash_proc(st_index_t hash, VALUE proc);
00631 int rb_block_arity(void);
00632 
00633 /* process.c */
00634 #define RB_MAX_GROUPS (65536)
00635 
00636 struct rb_execarg {
00637     int use_shell;
00638     union {
00639         struct {
00640             VALUE shell_script;
00641         } sh;
00642         struct {
00643             VALUE command_name;
00644             VALUE command_abspath; /* full path string or nil */
00645             VALUE argv_str;
00646             VALUE argv_buf;
00647         } cmd;
00648     } invoke;
00649     VALUE redirect_fds;
00650     VALUE envp_str;
00651     VALUE envp_buf;
00652     VALUE dup2_tmpbuf;
00653     unsigned pgroup_given : 1;
00654     unsigned umask_given : 1;
00655     unsigned unsetenv_others_given : 1;
00656     unsigned unsetenv_others_do : 1;
00657     unsigned close_others_given : 1;
00658     unsigned close_others_do : 1;
00659     unsigned chdir_given : 1;
00660     unsigned new_pgroup_given : 1;
00661     unsigned new_pgroup_flag : 1;
00662     unsigned uid_given : 1;
00663     unsigned gid_given : 1;
00664     rb_pid_t pgroup_pgid; /* asis(-1), new pgroup(0), specified pgroup (0<V). */
00665     VALUE rlimit_limits; /* Qfalse or [[rtype, softlim, hardlim], ...] */
00666     mode_t umask_mask;
00667     rb_uid_t uid;
00668     rb_gid_t gid;
00669     VALUE fd_dup2;
00670     VALUE fd_close;
00671     VALUE fd_open;
00672     VALUE fd_dup2_child;
00673     int close_others_maxhint;
00674     VALUE env_modification; /* Qfalse or [[k1,v1], ...] */
00675     VALUE chdir_dir;
00676 };
00677 
00678 /* argv_str contains extra two elements.
00679  * The beginning one is for /bin/sh used by exec_with_sh.
00680  * The last one for terminating NULL used by execve.
00681  * See rb_exec_fillarg() in process.c. */
00682 #define ARGVSTR2ARGC(argv_str) (RSTRING_LEN(argv_str) / sizeof(char *) - 2)
00683 #define ARGVSTR2ARGV(argv_str) ((char **)RSTRING_PTR(argv_str) + 1)
00684 
00685 rb_pid_t rb_fork_ruby(int *status);
00686 void rb_last_status_clear(void);
00687 
00688 /* rational.c */
00689 VALUE rb_lcm(VALUE x, VALUE y);
00690 VALUE rb_rational_reciprocal(VALUE x);
00691 
00692 /* re.c */
00693 VALUE rb_reg_compile(VALUE str, int options, const char *sourcefile, int sourceline);
00694 VALUE rb_reg_check_preprocess(VALUE);
00695 
00696 /* signal.c */
00697 int rb_get_next_signal(void);
00698 int rb_sigaltstack_size(void);
00699 
00700 /* strftime.c */
00701 #ifdef RUBY_ENCODING_H
00702 size_t rb_strftime_timespec(char *s, size_t maxsize, const char *format, rb_encoding *enc,
00703         const struct vtm *vtm, struct timespec *ts, int gmt);
00704 size_t rb_strftime(char *s, size_t maxsize, const char *format, rb_encoding *enc,
00705             const struct vtm *vtm, VALUE timev, int gmt);
00706 #endif
00707 
00708 /* string.c */
00709 VALUE rb_fstring(VALUE);
00710 int rb_str_buf_cat_escaped_char(VALUE result, unsigned int c, int unicode_p);
00711 int rb_str_symname_p(VALUE);
00712 VALUE rb_str_quote_unprintable(VALUE);
00713 VALUE rb_id_quote_unprintable(ID);
00714 #define QUOTE(str) rb_str_quote_unprintable(str)
00715 #define QUOTE_ID(id) rb_id_quote_unprintable(id)
00716 void rb_str_fill_terminator(VALUE str, const int termlen);
00717 VALUE rb_str_locktmp_ensure(VALUE str, VALUE (*func)(VALUE), VALUE arg);
00718 #ifdef RUBY_ENCODING_H
00719 VALUE rb_external_str_with_enc(VALUE str, rb_encoding *eenc);
00720 #endif
00721 #define STR_NOEMBED FL_USER1
00722 #define STR_SHARED  FL_USER2 /* = ELTS_SHARED */
00723 #define STR_ASSOC   FL_USER3
00724 #define STR_SHARED_P(s) FL_ALL((s), STR_NOEMBED|ELTS_SHARED)
00725 #define STR_ASSOC_P(s)  FL_ALL((s), STR_NOEMBED|STR_ASSOC)
00726 #define STR_NOCAPA  (STR_NOEMBED|ELTS_SHARED|STR_ASSOC)
00727 #define STR_NOCAPA_P(s) (FL_TEST((s),STR_NOEMBED) && FL_ANY((s),ELTS_SHARED|STR_ASSOC))
00728 #define STR_EMBED_P(str) (!FL_TEST((str), STR_NOEMBED))
00729 #define is_ascii_string(str) (rb_enc_str_coderange(str) == ENC_CODERANGE_7BIT)
00730 #define is_broken_string(str) (rb_enc_str_coderange(str) == ENC_CODERANGE_BROKEN)
00731 
00732 /* struct.c */
00733 VALUE rb_struct_init_copy(VALUE copy, VALUE s);
00734 
00735 /* time.c */
00736 struct timeval rb_time_timeval(VALUE);
00737 
00738 /* thread.c */
00739 VALUE rb_obj_is_mutex(VALUE obj);
00740 VALUE rb_suppress_tracing(VALUE (*func)(VALUE), VALUE arg);
00741 void rb_thread_execute_interrupts(VALUE th);
00742 void rb_clear_trace_func(void);
00743 VALUE rb_get_coverages(void);
00744 VALUE rb_thread_shield_new(void);
00745 VALUE rb_thread_shield_wait(VALUE self);
00746 VALUE rb_thread_shield_release(VALUE self);
00747 VALUE rb_thread_shield_destroy(VALUE self);
00748 void rb_mutex_allow_trap(VALUE self, int val);
00749 VALUE rb_uninterruptible(VALUE (*b_proc)(ANYARGS), VALUE data);
00750 VALUE rb_mutex_owned_p(VALUE self);
00751 void ruby_kill(rb_pid_t pid, int sig);
00752 
00753 /* thread_pthread.c, thread_win32.c */
00754 void Init_native_thread(void);
00755 
00756 /* vm_insnhelper.h */
00757 rb_serial_t rb_next_class_serial(void);
00758 
00759 /* vm.c */
00760 VALUE rb_obj_is_thread(VALUE obj);
00761 void rb_vm_mark(void *ptr);
00762 void Init_BareVM(void);
00763 VALUE rb_vm_top_self(void);
00764 void rb_thread_recycle_stack_release(VALUE *);
00765 void rb_vm_change_state(void);
00766 void rb_vm_inc_const_missing_count(void);
00767 void rb_thread_mark(void *th);
00768 const void **rb_vm_get_insns_address_table(void);
00769 VALUE rb_sourcefilename(void);
00770 void rb_vm_pop_cfunc_frame(void);
00771 
00772 /* vm_dump.c */
00773 void rb_vm_bugreport(void);
00774 void rb_print_backtrace(void);
00775 
00776 /* vm_eval.c */
00777 void Init_vm_eval(void);
00778 VALUE rb_current_realfilepath(void);
00779 VALUE rb_check_block_call(VALUE, ID, int, const VALUE *, rb_block_call_func_t, VALUE);
00780 typedef void rb_check_funcall_hook(int, VALUE, ID, int, const VALUE *, VALUE);
00781 VALUE rb_check_funcall_with_hook(VALUE recv, ID mid, int argc, const VALUE *argv,
00782                                  rb_check_funcall_hook *hook, VALUE arg);
00783 VALUE rb_catch_protect(VALUE t, rb_block_call_func *func, VALUE data, int *stateptr);
00784 
00785 /* vm_insnhelper.c */
00786 VALUE rb_equal_opt(VALUE obj1, VALUE obj2);
00787 int rb_get_kwargs(VALUE keyword_hash, const ID *table, int required, int optional, VALUE *);
00788 VALUE rb_extract_keywords(VALUE *orighash);
00789 
00790 /* vm_method.c */
00791 void Init_eval_method(void);
00792 int rb_method_defined_by(VALUE obj, ID mid, VALUE (*cfunc)(ANYARGS));
00793 
00794 /* miniprelude.c, prelude.c */
00795 void Init_prelude(void);
00796 
00797 /* vm_backtrace.c */
00798 void Init_vm_backtrace(void);
00799 VALUE rb_vm_thread_backtrace(int argc, VALUE *argv, VALUE thval);
00800 VALUE rb_vm_thread_backtrace_locations(int argc, VALUE *argv, VALUE thval);
00801 
00802 VALUE rb_make_backtrace(void);
00803 void rb_backtrace_print_as_bugreport(void);
00804 int rb_backtrace_p(VALUE obj);
00805 VALUE rb_backtrace_to_str_ary(VALUE obj);
00806 VALUE rb_backtrace_to_location_ary(VALUE obj);
00807 void rb_backtrace_print_to(VALUE output);
00808 VALUE rb_vm_backtrace_object(void);
00809 
00810 RUBY_SYMBOL_EXPORT_BEGIN
00811 const char *rb_objspace_data_type_name(VALUE obj);
00812 
00813 /* Temporary.  This API will be removed (renamed). */
00814 VALUE rb_thread_io_blocking_region(rb_blocking_function_t *func, void *data1, int fd);
00815 
00816 /* bignum.c */
00817 VALUE rb_big_mul_normal(VALUE x, VALUE y);
00818 VALUE rb_big_mul_balance(VALUE x, VALUE y);
00819 VALUE rb_big_mul_karatsuba(VALUE x, VALUE y);
00820 VALUE rb_big_mul_toom3(VALUE x, VALUE y);
00821 VALUE rb_big_sq_fast(VALUE x);
00822 VALUE rb_big_divrem_normal(VALUE x, VALUE y);
00823 VALUE rb_big2str_poweroftwo(VALUE x, int base);
00824 VALUE rb_big2str_generic(VALUE x, int base);
00825 VALUE rb_str2big_poweroftwo(VALUE arg, int base, int badcheck);
00826 VALUE rb_str2big_normal(VALUE arg, int base, int badcheck);
00827 VALUE rb_str2big_karatsuba(VALUE arg, int base, int badcheck);
00828 #if defined(HAVE_LIBGMP) && defined(HAVE_GMP_H)
00829 VALUE rb_big_mul_gmp(VALUE x, VALUE y);
00830 VALUE rb_big_divrem_gmp(VALUE x, VALUE y);
00831 VALUE rb_big2str_gmp(VALUE x, int base);
00832 VALUE rb_str2big_gmp(VALUE arg, int base, int badcheck);
00833 #endif
00834 
00835 /* error.c */
00836 int rb_bug_reporter_add(void (*func)(FILE *, void *), void *data);
00837 
00838 /* file.c */
00839 #ifdef __APPLE__
00840 VALUE rb_str_normalize_ospath(const char *ptr, long len);
00841 #endif
00842 
00843 /* io.c */
00844 void rb_maygvl_fd_fix_cloexec(int fd);
00845 
00846 /* numeric.c */
00847 VALUE rb_int_positive_pow(long x, unsigned long y);
00848 
00849 /* process.c */
00850 int rb_exec_async_signal_safe(const struct rb_execarg *e, char *errmsg, size_t errmsg_buflen);
00851 rb_pid_t rb_fork_async_signal_safe(int *status, int (*chfunc)(void*, char *, size_t), void *charg, VALUE fds, char *errmsg, size_t errmsg_buflen);
00852 VALUE rb_execarg_new(int argc, VALUE *argv, int accept_shell);
00853 struct rb_execarg *rb_execarg_get(VALUE execarg_obj); /* dangerous.  needs GC guard. */
00854 VALUE rb_execarg_init(int argc, VALUE *argv, int accept_shell, VALUE execarg_obj);
00855 int rb_execarg_addopt(VALUE execarg_obj, VALUE key, VALUE val);
00856 void rb_execarg_fixup(VALUE execarg_obj);
00857 int rb_execarg_run_options(const struct rb_execarg *e, struct rb_execarg *s, char* errmsg, size_t errmsg_buflen);
00858 VALUE rb_execarg_extract_options(VALUE execarg_obj, VALUE opthash);
00859 void rb_execarg_setenv(VALUE execarg_obj, VALUE env);
00860 
00861 /* rational.c */
00862 VALUE rb_gcd_normal(VALUE self, VALUE other);
00863 #if defined(HAVE_LIBGMP) && defined(HAVE_GMP_H)
00864 VALUE rb_gcd_gmp(VALUE x, VALUE y);
00865 #endif
00866 
00867 /* util.c */
00868 extern const signed char ruby_digit36_to_number_table[];
00869 
00870 /* variable.c */
00871 void rb_gc_mark_global_tbl(void);
00872 void rb_mark_generic_ivar(VALUE);
00873 void rb_mark_generic_ivar_tbl(void);
00874 
00875 int rb_st_insert_id_and_value(VALUE obj, st_table *tbl, ID key, VALUE value);
00876 st_table *rb_st_copy(VALUE obj, struct st_table *orig_tbl);
00877 
00878 /* gc.c */
00879 size_t rb_obj_memsize_of(VALUE);
00880 #define RB_OBJ_GC_FLAGS_MAX 5
00881 size_t rb_obj_gc_flags(VALUE, ID[], size_t);
00882 
00883 RUBY_SYMBOL_EXPORT_END
00884 
00885 #if defined(__cplusplus)
00886 #if 0
00887 { /* satisfy cc-mode */
00888 #endif
00889 }  /* extern "C" { */
00890 #endif
00891 
00892 #endif /* RUBY_INTERNAL_H */
00893 

Generated on 19 Jul 2016 for Ruby by  doxygen 1.4.7