Ruby  2.0.0p247(2013-06-27revision41674)
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 
00182 /* object.c */
00183 VALUE rb_obj_equal(VALUE obj1, VALUE obj2);
00184 
00185 /* parse.y */
00186 VALUE rb_parser_get_yydebug(VALUE);
00187 VALUE rb_parser_set_yydebug(VALUE, VALUE);
00188 int rb_is_const_name(VALUE name);
00189 int rb_is_class_name(VALUE name);
00190 int rb_is_global_name(VALUE name);
00191 int rb_is_instance_name(VALUE name);
00192 int rb_is_attrset_name(VALUE name);
00193 int rb_is_local_name(VALUE name);
00194 int rb_is_method_name(VALUE name);
00195 int rb_is_junk_name(VALUE name);
00196 void rb_gc_mark_parser(void);
00197 void rb_gc_mark_symbols(void);
00198 
00199 /* proc.c */
00200 VALUE rb_proc_location(VALUE self);
00201 st_index_t rb_hash_proc(st_index_t hash, VALUE proc);
00202 
00203 /* process.c */
00204 #define RB_MAX_GROUPS (65536)
00205 
00206 struct rb_execarg {
00207     int use_shell;
00208     union {
00209         struct {
00210             VALUE shell_script;
00211         } sh;
00212         struct {
00213             VALUE command_name;
00214             VALUE command_abspath; /* full path string or nil */
00215             VALUE argv_str;
00216             VALUE argv_buf;
00217         } cmd;
00218     } invoke;
00219     VALUE redirect_fds;
00220     VALUE envp_str;
00221     VALUE envp_buf;
00222     VALUE dup2_tmpbuf;
00223     unsigned pgroup_given : 1;
00224     unsigned umask_given : 1;
00225     unsigned unsetenv_others_given : 1;
00226     unsigned unsetenv_others_do : 1;
00227     unsigned close_others_given : 1;
00228     unsigned close_others_do : 1;
00229     unsigned chdir_given : 1;
00230     unsigned new_pgroup_given : 1;
00231     unsigned new_pgroup_flag : 1;
00232     unsigned uid_given : 1;
00233     unsigned gid_given : 1;
00234     rb_pid_t pgroup_pgid; /* asis(-1), new pgroup(0), specified pgroup (0<V). */
00235     VALUE rlimit_limits; /* Qfalse or [[rtype, softlim, hardlim], ...] */
00236     mode_t umask_mask;
00237     rb_uid_t uid;
00238     rb_gid_t gid;
00239     VALUE fd_dup2;
00240     VALUE fd_close;
00241     VALUE fd_open;
00242     VALUE fd_dup2_child;
00243     int close_others_maxhint;
00244     VALUE env_modification; /* Qfalse or [[k1,v1], ...] */
00245     VALUE chdir_dir;
00246 };
00247 
00248 /* argv_str contains extra two elements.
00249  * The beginning one is for /bin/sh used by exec_with_sh.
00250  * The last one for terminating NULL used by execve.
00251  * See rb_exec_fillarg() in process.c. */
00252 #define ARGVSTR2ARGC(argv_str) (RSTRING_LEN(argv_str) / sizeof(char *) - 2)
00253 #define ARGVSTR2ARGV(argv_str) ((char **)RSTRING_PTR(argv_str) + 1)
00254 
00255 rb_pid_t rb_fork_ruby(int *status);
00256 void rb_last_status_clear(void);
00257 
00258 /* rational.c */
00259 VALUE rb_lcm(VALUE x, VALUE y);
00260 VALUE rb_rational_reciprocal(VALUE x);
00261 
00262 /* re.c */
00263 VALUE rb_reg_compile(VALUE str, int options, const char *sourcefile, int sourceline);
00264 VALUE rb_reg_check_preprocess(VALUE);
00265 
00266 /* signal.c */
00267 int rb_get_next_signal(void);
00268 int rb_sigaltstack_size(void);
00269 
00270 /* strftime.c */
00271 #ifdef RUBY_ENCODING_H
00272 size_t rb_strftime_timespec(char *s, size_t maxsize, const char *format, rb_encoding *enc,
00273         const struct vtm *vtm, struct timespec *ts, int gmt);
00274 size_t rb_strftime(char *s, size_t maxsize, const char *format, rb_encoding *enc,
00275             const struct vtm *vtm, VALUE timev, int gmt);
00276 #endif
00277 
00278 /* string.c */
00279 int rb_str_buf_cat_escaped_char(VALUE result, unsigned int c, int unicode_p);
00280 int rb_str_symname_p(VALUE);
00281 VALUE rb_str_quote_unprintable(VALUE);
00282 VALUE rb_id_quote_unprintable(ID);
00283 #define QUOTE(str) rb_str_quote_unprintable(str)
00284 #define QUOTE_ID(id) rb_id_quote_unprintable(id)
00285 
00286 /* struct.c */
00287 VALUE rb_struct_init_copy(VALUE copy, VALUE s);
00288 
00289 /* time.c */
00290 struct timeval rb_time_timeval(VALUE);
00291 
00292 /* thread.c */
00293 VALUE rb_obj_is_mutex(VALUE obj);
00294 VALUE rb_suppress_tracing(VALUE (*func)(VALUE), VALUE arg);
00295 void rb_thread_execute_interrupts(VALUE th);
00296 void rb_clear_trace_func(void);
00297 VALUE rb_get_coverages(void);
00298 VALUE rb_thread_shield_new(void);
00299 VALUE rb_thread_shield_wait(VALUE self);
00300 VALUE rb_thread_shield_release(VALUE self);
00301 VALUE rb_thread_shield_destroy(VALUE self);
00302 void rb_mutex_allow_trap(VALUE self, int val);
00303 VALUE rb_uninterruptible(VALUE (*b_proc)(ANYARGS), VALUE data);
00304 VALUE rb_mutex_owned_p(VALUE self);
00305 
00306 /* thread_pthread.c, thread_win32.c */
00307 void Init_native_thread(void);
00308 
00309 /* vm.c */
00310 VALUE rb_obj_is_thread(VALUE obj);
00311 void rb_vm_mark(void *ptr);
00312 void Init_BareVM(void);
00313 VALUE rb_vm_top_self(void);
00314 void rb_thread_recycle_stack_release(VALUE *);
00315 void rb_vm_change_state(void);
00316 void rb_vm_inc_const_missing_count(void);
00317 void rb_thread_mark(void *th);
00318 const void **rb_vm_get_insns_address_table(void);
00319 VALUE rb_sourcefilename(void);
00320 
00321 /* vm_dump.c */
00322 void rb_vm_bugreport(void);
00323 
00324 /* vm_eval.c */
00325 void Init_vm_eval(void);
00326 VALUE rb_current_realfilepath(void);
00327 VALUE rb_check_block_call(VALUE, ID, int, VALUE *, VALUE (*)(ANYARGS), VALUE);
00328 typedef void rb_check_funcall_hook(int, VALUE, ID, int, VALUE *, VALUE);
00329 VALUE rb_check_funcall_with_hook(VALUE recv, ID mid, int argc, VALUE *argv,
00330                                  rb_check_funcall_hook *hook, VALUE arg);
00331 
00332 /* vm_method.c */
00333 void Init_eval_method(void);
00334 int rb_method_defined_by(VALUE obj, ID mid, VALUE (*cfunc)(ANYARGS));
00335 
00336 /* miniprelude.c, prelude.c */
00337 void Init_prelude(void);
00338 
00339 /* vm_backtrace.c */
00340 void Init_vm_backtrace(void);
00341 VALUE vm_thread_backtrace(int argc, VALUE *argv, VALUE thval);
00342 VALUE vm_thread_backtrace_locations(int argc, VALUE *argv, VALUE thval);
00343 
00344 VALUE rb_make_backtrace(void);
00345 void rb_backtrace_print_as_bugreport(void);
00346 int rb_backtrace_p(VALUE obj);
00347 VALUE rb_backtrace_to_str_ary(VALUE obj);
00348 VALUE rb_vm_backtrace_object();
00349 
00350 #if defined __GNUC__ && __GNUC__ >= 4
00351 #pragma GCC visibility push(default)
00352 #endif
00353 const char *rb_objspace_data_type_name(VALUE obj);
00354 
00355 /* Temporary.  This API will be removed (renamed). */
00356 VALUE rb_thread_io_blocking_region(rb_blocking_function_t *func, void *data1, int fd);
00357 
00358 /* io.c */
00359 void rb_maygvl_fd_fix_cloexec(int fd);
00360 
00361 /* process.c */
00362 int rb_exec_async_signal_safe(const struct rb_execarg *e, char *errmsg, size_t errmsg_buflen);
00363 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);
00364 VALUE rb_execarg_new(int argc, VALUE *argv, int accept_shell);
00365 struct rb_execarg *rb_execarg_get(VALUE execarg_obj); /* dangerous.  needs GC guard. */
00366 VALUE rb_execarg_init(int argc, VALUE *argv, int accept_shell, VALUE execarg_obj);
00367 int rb_execarg_addopt(VALUE execarg_obj, VALUE key, VALUE val);
00368 void rb_execarg_fixup(VALUE execarg_obj);
00369 int rb_execarg_run_options(const struct rb_execarg *e, struct rb_execarg *s, char* errmsg, size_t errmsg_buflen);
00370 VALUE rb_execarg_extract_options(VALUE execarg_obj, VALUE opthash);
00371 void rb_execarg_setenv(VALUE execarg_obj, VALUE env);
00372 
00373 /* variable.c */
00374 void rb_gc_mark_global_tbl(void);
00375 void rb_mark_generic_ivar(VALUE);
00376 void rb_mark_generic_ivar_tbl(void);
00377 
00378 #if defined __GNUC__ && __GNUC__ >= 4
00379 #pragma GCC visibility pop
00380 #endif
00381 
00382 #if defined(__cplusplus)
00383 #if 0
00384 { /* satisfy cc-mode */
00385 #endif
00386 }  /* extern "C" { */
00387 #endif
00388 
00389 #endif /* RUBY_INTERNAL_H */
00390