Ruby  2.0.0p481(2014-05-08revision45883)
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 #define MUL_OVERFLOW_SIGNED_INTEGER_P(a, b, min, max) ( \
00023     (a) == 0 ? 0 : \
00024     (a) == -1 ? (b) < -(max) : \
00025     (a) > 0 ? \
00026       ((b) > 0 ? (max) / (a) < (b) : (min) / (a) > (b)) : \
00027       ((b) > 0 ? (min) / (a) < (b) : (max) / (a) > (b)))
00028 #define MUL_OVERFLOW_FIXNUM_P(a, b) MUL_OVERFLOW_SIGNED_INTEGER_P(a, b, FIXNUM_MIN, FIXNUM_MAX)
00029 #define MUL_OVERFLOW_LONG_P(a, b) MUL_OVERFLOW_SIGNED_INTEGER_P(a, b, LONG_MIN, LONG_MAX)
00030 
00031 struct rb_deprecated_classext_struct {
00032     char conflict[sizeof(VALUE) * 3];
00033 };
00034 
00035 struct rb_classext_struct {
00036     VALUE super;
00037     struct st_table *iv_tbl;
00038     struct st_table *const_tbl;
00039     VALUE origin;
00040     VALUE refined_class;
00041     rb_alloc_func_t allocator;
00042 };
00043 
00044 #undef RCLASS_SUPER
00045 #define RCLASS_EXT(c) (RCLASS(c)->ptr)
00046 #define RCLASS_SUPER(c) (RCLASS_EXT(c)->super)
00047 #define RCLASS_IV_TBL(c) (RCLASS_EXT(c)->iv_tbl)
00048 #define RCLASS_CONST_TBL(c) (RCLASS_EXT(c)->const_tbl)
00049 #define RCLASS_M_TBL(c) (RCLASS(c)->m_tbl)
00050 #define RCLASS_IV_INDEX_TBL(c) (RCLASS(c)->iv_index_tbl)
00051 #define RCLASS_ORIGIN(c) (RCLASS_EXT(c)->origin)
00052 #define RCLASS_REFINED_CLASS(c) (RCLASS_EXT(c)->refined_class)
00053 
00054 struct vtm; /* defined by timev.h */
00055 
00056 /* array.c */
00057 VALUE rb_ary_last(int, VALUE *, VALUE);
00058 void rb_ary_set_len(VALUE, long);
00059 VALUE rb_ary_cat(VALUE, const VALUE *, long);
00060 void rb_ary_delete_same(VALUE, VALUE);
00061 
00062 /* bignum.c */
00063 VALUE rb_big_fdiv(VALUE x, VALUE y);
00064 VALUE rb_big_uminus(VALUE x);
00065 VALUE rb_integer_float_cmp(VALUE x, VALUE y);
00066 VALUE rb_integer_float_eq(VALUE x, VALUE y);
00067 
00068 /* class.c */
00069 VALUE rb_obj_methods(int argc, VALUE *argv, VALUE obj);
00070 VALUE rb_obj_protected_methods(int argc, VALUE *argv, VALUE obj);
00071 VALUE rb_obj_private_methods(int argc, VALUE *argv, VALUE obj);
00072 VALUE rb_obj_public_methods(int argc, VALUE *argv, VALUE obj);
00073 int rb_obj_basic_to_s_p(VALUE);
00074 VALUE rb_special_singleton_class(VALUE);
00075 VALUE rb_singleton_class_clone_and_attach(VALUE obj, VALUE attach);
00076 void Init_class_hierarchy(void);
00077 
00078 /* compar.c */
00079 VALUE rb_invcmp(VALUE, VALUE);
00080 
00081 /* compile.c */
00082 int rb_dvar_defined(ID);
00083 int rb_local_defined(ID);
00084 int rb_parse_in_eval(void);
00085 int rb_parse_in_main(void);
00086 const char * rb_insns_name(int i);
00087 VALUE rb_insns_name_array(void);
00088 
00089 /* cont.c */
00090 VALUE rb_obj_is_fiber(VALUE);
00091 void rb_fiber_reset_root_local_storage(VALUE);
00092 
00093 /* debug.c */
00094 PRINTF_ARGS(void ruby_debug_printf(const char*, ...), 1, 2);
00095 
00096 /* dmyext.c */
00097 void Init_ext(void);
00098 
00099 /* encoding.c */
00100 ID rb_id_encoding(void);
00101 
00102 /* encoding.c */
00103 void rb_gc_mark_encodings(void);
00104 
00105 /* error.c */
00106 NORETURN(PRINTF_ARGS(void rb_compile_bug(const char*, int, const char*, ...), 3, 4));
00107 VALUE rb_check_backtrace(VALUE);
00108 NORETURN(void rb_async_bug_errno(const char *,int));
00109 const char *rb_builtin_type_name(int t);
00110 const char *rb_builtin_class_name(VALUE x);
00111 
00112 /* eval.c */
00113 VALUE rb_refinement_module_get_refined_class(VALUE module);
00114 
00115 /* eval_error.c */
00116 void ruby_error_print(void);
00117 VALUE rb_get_backtrace(VALUE info);
00118 
00119 /* eval_jump.c */
00120 void rb_call_end_proc(VALUE data);
00121 void rb_mark_end_proc(void);
00122 
00123 /* file.c */
00124 VALUE rb_home_dir(const char *user, VALUE result);
00125 VALUE rb_realpath_internal(VALUE basedir, VALUE path, int strict);
00126 void rb_file_const(const char*, VALUE);
00127 int rb_file_load_ok(const char *);
00128 VALUE rb_file_expand_path_fast(VALUE, VALUE);
00129 VALUE rb_file_expand_path_internal(VALUE, VALUE, int, int, VALUE);
00130 VALUE rb_get_path_check_to_string(VALUE, int);
00131 VALUE rb_get_path_check_convert(VALUE, VALUE, int);
00132 void Init_File(void);
00133 
00134 #ifdef _WIN32
00135 /* file.c, win32/file.c */
00136 void rb_w32_init_file(void);
00137 #endif
00138 
00139 /* gc.c */
00140 void Init_heap(void);
00141 void *ruby_mimmalloc(size_t size);
00142 
00143 /* inits.c */
00144 void rb_call_inits(void);
00145 
00146 /* io.c */
00147 const char *ruby_get_inplace_mode(void);
00148 void ruby_set_inplace_mode(const char *);
00149 ssize_t rb_io_bufread(VALUE io, void *buf, size_t size);
00150 void rb_stdio_set_default_encoding(void);
00151 void rb_write_error_str(VALUE mesg);
00152 
00153 /* iseq.c */
00154 VALUE rb_iseq_clone(VALUE iseqval, VALUE newcbase);
00155 
00156 /* load.c */
00157 VALUE rb_get_load_path(void);
00158 VALUE rb_get_expanded_load_path(void);
00159 NORETURN(void rb_load_fail(VALUE, const char*));
00160 
00161 /* math.c */
00162 VALUE rb_math_atan2(VALUE, VALUE);
00163 VALUE rb_math_cos(VALUE);
00164 VALUE rb_math_cosh(VALUE);
00165 VALUE rb_math_exp(VALUE);
00166 VALUE rb_math_hypot(VALUE, VALUE);
00167 VALUE rb_math_log(int argc, VALUE *argv);
00168 VALUE rb_math_sin(VALUE);
00169 VALUE rb_math_sinh(VALUE);
00170 VALUE rb_math_sqrt(VALUE);
00171 
00172 /* newline.c */
00173 void Init_newline(void);
00174 
00175 /* numeric.c */
00176 int rb_num_to_uint(VALUE val, unsigned int *ret);
00177 VALUE num_interval_step_size(VALUE from, VALUE to, VALUE step, int excl);
00178 int ruby_float_step(VALUE from, VALUE to, VALUE step, int excl);
00179 double ruby_float_mod(double x, double y);
00180 int rb_num_negative_p(VALUE);
00181 VALUE rb_int_succ(VALUE num);
00182 VALUE rb_int_pred(VALUE num);
00183 
00184 /* object.c */
00185 VALUE rb_obj_equal(VALUE obj1, VALUE obj2);
00186 
00187 /* parse.y */
00188 VALUE rb_parser_get_yydebug(VALUE);
00189 VALUE rb_parser_set_yydebug(VALUE, VALUE);
00190 int rb_is_const_name(VALUE name);
00191 int rb_is_class_name(VALUE name);
00192 int rb_is_global_name(VALUE name);
00193 int rb_is_instance_name(VALUE name);
00194 int rb_is_attrset_name(VALUE name);
00195 int rb_is_local_name(VALUE name);
00196 int rb_is_method_name(VALUE name);
00197 int rb_is_junk_name(VALUE name);
00198 void rb_gc_mark_parser(void);
00199 void rb_gc_mark_symbols(void);
00200 
00201 /* proc.c */
00202 VALUE rb_proc_location(VALUE self);
00203 st_index_t rb_hash_proc(st_index_t hash, VALUE proc);
00204 
00205 /* process.c */
00206 #define RB_MAX_GROUPS (65536)
00207 
00208 struct rb_execarg {
00209     int use_shell;
00210     union {
00211         struct {
00212             VALUE shell_script;
00213         } sh;
00214         struct {
00215             VALUE command_name;
00216             VALUE command_abspath; /* full path string or nil */
00217             VALUE argv_str;
00218             VALUE argv_buf;
00219         } cmd;
00220     } invoke;
00221     VALUE redirect_fds;
00222     VALUE envp_str;
00223     VALUE envp_buf;
00224     VALUE dup2_tmpbuf;
00225     unsigned pgroup_given : 1;
00226     unsigned umask_given : 1;
00227     unsigned unsetenv_others_given : 1;
00228     unsigned unsetenv_others_do : 1;
00229     unsigned close_others_given : 1;
00230     unsigned close_others_do : 1;
00231     unsigned chdir_given : 1;
00232     unsigned new_pgroup_given : 1;
00233     unsigned new_pgroup_flag : 1;
00234     unsigned uid_given : 1;
00235     unsigned gid_given : 1;
00236     rb_pid_t pgroup_pgid; /* asis(-1), new pgroup(0), specified pgroup (0<V). */
00237     VALUE rlimit_limits; /* Qfalse or [[rtype, softlim, hardlim], ...] */
00238     mode_t umask_mask;
00239     rb_uid_t uid;
00240     rb_gid_t gid;
00241     VALUE fd_dup2;
00242     VALUE fd_close;
00243     VALUE fd_open;
00244     VALUE fd_dup2_child;
00245     int close_others_maxhint;
00246     VALUE env_modification; /* Qfalse or [[k1,v1], ...] */
00247     VALUE chdir_dir;
00248 };
00249 
00250 /* argv_str contains extra two elements.
00251  * The beginning one is for /bin/sh used by exec_with_sh.
00252  * The last one for terminating NULL used by execve.
00253  * See rb_exec_fillarg() in process.c. */
00254 #define ARGVSTR2ARGC(argv_str) (RSTRING_LEN(argv_str) / sizeof(char *) - 2)
00255 #define ARGVSTR2ARGV(argv_str) ((char **)RSTRING_PTR(argv_str) + 1)
00256 
00257 rb_pid_t rb_fork_ruby(int *status);
00258 void rb_last_status_clear(void);
00259 
00260 /* rational.c */
00261 VALUE rb_lcm(VALUE x, VALUE y);
00262 VALUE rb_rational_reciprocal(VALUE x);
00263 
00264 /* re.c */
00265 VALUE rb_reg_compile(VALUE str, int options, const char *sourcefile, int sourceline);
00266 VALUE rb_reg_check_preprocess(VALUE);
00267 
00268 /* signal.c */
00269 int rb_get_next_signal(void);
00270 int rb_sigaltstack_size(void);
00271 
00272 /* strftime.c */
00273 #ifdef RUBY_ENCODING_H
00274 size_t rb_strftime_timespec(char *s, size_t maxsize, const char *format, rb_encoding *enc,
00275         const struct vtm *vtm, struct timespec *ts, int gmt);
00276 size_t rb_strftime(char *s, size_t maxsize, const char *format, rb_encoding *enc,
00277             const struct vtm *vtm, VALUE timev, int gmt);
00278 #endif
00279 
00280 /* string.c */
00281 int rb_str_buf_cat_escaped_char(VALUE result, unsigned int c, int unicode_p);
00282 int rb_str_symname_p(VALUE);
00283 VALUE rb_str_quote_unprintable(VALUE);
00284 VALUE rb_id_quote_unprintable(ID);
00285 #define QUOTE(str) rb_str_quote_unprintable(str)
00286 #define QUOTE_ID(id) rb_id_quote_unprintable(id)
00287 VALUE rb_str_locktmp_ensure(VALUE str, VALUE (*func)(VALUE), VALUE arg);
00288 
00289 /* struct.c */
00290 VALUE rb_struct_init_copy(VALUE copy, VALUE s);
00291 
00292 /* time.c */
00293 struct timeval rb_time_timeval(VALUE);
00294 
00295 /* thread.c */
00296 VALUE rb_obj_is_mutex(VALUE obj);
00297 VALUE rb_suppress_tracing(VALUE (*func)(VALUE), VALUE arg);
00298 void rb_thread_execute_interrupts(VALUE th);
00299 void rb_clear_trace_func(void);
00300 VALUE rb_get_coverages(void);
00301 VALUE rb_thread_shield_new(void);
00302 VALUE rb_thread_shield_wait(VALUE self);
00303 VALUE rb_thread_shield_release(VALUE self);
00304 VALUE rb_thread_shield_destroy(VALUE self);
00305 void rb_mutex_allow_trap(VALUE self, int val);
00306 VALUE rb_uninterruptible(VALUE (*b_proc)(ANYARGS), VALUE data);
00307 VALUE rb_mutex_owned_p(VALUE self);
00308 
00309 /* thread_pthread.c, thread_win32.c */
00310 void Init_native_thread(void);
00311 
00312 /* vm.c */
00313 VALUE rb_obj_is_thread(VALUE obj);
00314 void rb_vm_mark(void *ptr);
00315 void Init_BareVM(void);
00316 VALUE rb_vm_top_self(void);
00317 void rb_thread_recycle_stack_release(VALUE *);
00318 void rb_vm_change_state(void);
00319 void rb_vm_inc_const_missing_count(void);
00320 void rb_thread_mark(void *th);
00321 const void **rb_vm_get_insns_address_table(void);
00322 VALUE rb_sourcefilename(void);
00323 
00324 /* vm_dump.c */
00325 void rb_vm_bugreport(void);
00326 
00327 /* vm_eval.c */
00328 void Init_vm_eval(void);
00329 VALUE rb_current_realfilepath(void);
00330 VALUE rb_check_block_call(VALUE, ID, int, VALUE *, VALUE (*)(ANYARGS), VALUE);
00331 typedef void rb_check_funcall_hook(int, VALUE, ID, int, VALUE *, VALUE);
00332 VALUE rb_check_funcall_with_hook(VALUE recv, ID mid, int argc, VALUE *argv,
00333                                  rb_check_funcall_hook *hook, VALUE arg);
00334 
00335 /* vm_method.c */
00336 void Init_eval_method(void);
00337 int rb_method_defined_by(VALUE obj, ID mid, VALUE (*cfunc)(ANYARGS));
00338 
00339 /* miniprelude.c, prelude.c */
00340 void Init_prelude(void);
00341 
00342 /* vm_backtrace.c */
00343 void Init_vm_backtrace(void);
00344 VALUE vm_thread_backtrace(int argc, VALUE *argv, VALUE thval);
00345 VALUE vm_thread_backtrace_locations(int argc, VALUE *argv, VALUE thval);
00346 
00347 VALUE rb_make_backtrace(void);
00348 void rb_backtrace_print_as_bugreport(void);
00349 int rb_backtrace_p(VALUE obj);
00350 VALUE rb_backtrace_to_str_ary(VALUE obj);
00351 VALUE rb_vm_backtrace_object();
00352 
00353 #if defined __GNUC__ && __GNUC__ >= 4
00354 #pragma GCC visibility push(default)
00355 #endif
00356 const char *rb_objspace_data_type_name(VALUE obj);
00357 
00358 /* Temporary.  This API will be removed (renamed). */
00359 VALUE rb_thread_io_blocking_region(rb_blocking_function_t *func, void *data1, int fd);
00360 
00361 /* io.c */
00362 void rb_maygvl_fd_fix_cloexec(int fd);
00363 
00364 /* process.c */
00365 int rb_exec_async_signal_safe(const struct rb_execarg *e, char *errmsg, size_t errmsg_buflen);
00366 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);
00367 VALUE rb_execarg_new(int argc, VALUE *argv, int accept_shell);
00368 struct rb_execarg *rb_execarg_get(VALUE execarg_obj); /* dangerous.  needs GC guard. */
00369 VALUE rb_execarg_init(int argc, VALUE *argv, int accept_shell, VALUE execarg_obj);
00370 int rb_execarg_addopt(VALUE execarg_obj, VALUE key, VALUE val);
00371 void rb_execarg_fixup(VALUE execarg_obj);
00372 int rb_execarg_run_options(const struct rb_execarg *e, struct rb_execarg *s, char* errmsg, size_t errmsg_buflen);
00373 VALUE rb_execarg_extract_options(VALUE execarg_obj, VALUE opthash);
00374 void rb_execarg_setenv(VALUE execarg_obj, VALUE env);
00375 
00376 /* variable.c */
00377 void rb_gc_mark_global_tbl(void);
00378 void rb_mark_generic_ivar(VALUE);
00379 void rb_mark_generic_ivar_tbl(void);
00380 
00381 #if defined __GNUC__ && __GNUC__ >= 4
00382 #pragma GCC visibility pop
00383 #endif
00384 
00385 #if defined(__cplusplus)
00386 #if 0
00387 { /* satisfy cc-mode */
00388 #endif
00389 }  /* extern "C" { */
00390 #endif
00391 
00392 #endif /* RUBY_INTERNAL_H */
00393