29 #define id_signo ruby_static_id_signo 30 #define id_status ruby_static_id_status 32 #define exception_error GET_VM()->special_exceptions[ruby_error_reenter] 37 #define CLASS_OR_MODULE_P(obj) \ 38 (!SPECIAL_CONST_P(obj) && \ 39 (BUILTIN_TYPE(obj) == T_CLASS || BUILTIN_TYPE(obj) == T_MODULE)) 100 void *
volatile iseq = 0;
109 state = error_handle(state);
117 ruby_finalize_0(
void)
129 ruby_finalize_1(
void)
164 volatile VALUE errs[2];
168 volatile int step = 0;
195 if (ex == 0) ex = state;
198 sysex = error_handle(ex);
201 for (nerr = 0; nerr <
numberof(errs); ++nerr) {
204 if (!
RTEST(err))
continue;
210 sysex = sysexit_status(err);
236 ruby_exec_internal(
void *n)
286 if (status) *status = s;
310 return ruby_exec_internal(n);
334 while (cref && CREF_NEXT(cref)) {
335 VALUE klass = CREF_CLASS(cref);
336 if (!CREF_PUSHED_BY_EVAL(cref) &&
340 cref = CREF_NEXT(cref);
380 klass = CREF_CLASS(cref);
381 if (!CREF_PUSHED_BY_EVAL(cref) &&
388 cref = CREF_NEXT(cref);
446 static VALUE get_errinfo(
void);
455 CONST_ID(id_true_cause,
"true_cause");
466 if (!
NIL_P(cause) && cause != exc) {
494 *cause = get_thread_errinfo(th);
504 const char *file = 0;
509 volatile int state = 0;
520 exc_setup_cause(mesg, cause);
525 set_backtrace(mesg, at);
530 if (state)
goto fatal;
589 cause = get_thread_errinfo(th);
599 mesg = exc_setup_message(th, mesg, &cause);
600 setup_exception(th, tag, mesg, cause);
605 static VALUE make_exception(
int argc,
const VALUE *argv,
int isstr);
618 mesg = make_exception(1, &mesg,
FALSE);
634 mesg = make_exception(1, &mesg,
FALSE);
652 extract_raise_opts(
int argc,
const VALUE *argv,
VALUE *opts)
656 VALUE opt = argv[argc-1];
698 rb_f_raise(
int argc,
VALUE *argv)
703 argc = extract_raise_opts(argc, argv, opts);
720 make_exception(
int argc,
const VALUE *argv,
int isstr)
761 set_backtrace(mesg, argv[2]);
790 return make_exception(argc, argv,
TRUE);
908 result = (*b_proc) (data1);
927 while ((eclass = va_arg(args,
VALUE)) != 0) {
939 result = (*r_proc) (data2, th->
ec.
errinfo);
1016 if (pstate !=
NULL) *pstate = state;
1049 result = (*b_proc) (data1);
1070 return me->
def->original_id;
1122 return frame_called_id(
GET_THREAD()->ec.cfp);
1137 prev_frame_callee(
void)
1140 if (!prev_cfp)
return 0;
1141 return frame_called_id(prev_cfp);
1145 prev_frame_func(
void)
1148 if (!prev_cfp)
return 0;
1149 return frame_func_id(prev_cfp);
1165 while (!(mid = frame_func_id(cfp)) &&
1184 rb_mod_append_features(
VALUE module,
VALUE include)
1202 rb_mod_include(
int argc,
VALUE *argv,
VALUE module)
1205 ID id_append_features, id_included;
1207 CONST_ID(id_append_features,
"append_features");
1211 for (i = 0; i <
argc; i++)
1214 rb_funcall(argv[argc], id_append_features, 1, module);
1215 rb_funcall(argv[argc], id_included, 1, module);
1233 rb_mod_prepend_features(
VALUE module,
VALUE prepend)
1251 rb_mod_prepend(
int argc,
VALUE *argv,
VALUE module)
1254 ID id_prepend_features, id_prepended;
1256 CONST_ID(id_prepend_features,
"prepend_features");
1257 CONST_ID(id_prepended,
"prepended");
1260 for (i = 0; i <
argc; i++)
1263 rb_funcall(argv[argc], id_prepend_features, 1, module);
1264 rb_funcall(argv[argc], id_prepended, 1, module);
1270 ensure_class_or_module(
VALUE obj)
1274 "wrong argument type %"PRIsVALUE" (expected Class or Module)",
1280 hidden_identity_hash_new(
void)
1295 VALUE iclass, c, superclass = klass;
1297 ensure_class_or_module(klass);
1299 if (
NIL_P(CREF_REFINEMENTS(cref))) {
1300 CREF_REFINEMENTS_SET(cref, hidden_identity_hash_new());
1303 if (CREF_OMOD_SHARED(cref)) {
1304 CREF_REFINEMENTS_SET(cref,
rb_hash_dup(CREF_REFINEMENTS(cref)));
1305 CREF_OMOD_SHARED_UNSET(cref);
1310 if (
RBASIC(c)->klass == module) {
1326 while (module && module != klass) {
1340 rb_using_refinement(cref, klass, module);
1348 VALUE super, module, refinements;
1352 using_module_recursive(cref, super);
1360 module =
RBASIC(klass)->klass;
1368 CONST_ID(id_refinements,
"__refinements__");
1369 refinements =
rb_attr_get(module, id_refinements);
1370 if (
NIL_P(refinements))
return;
1382 using_module_recursive(cref, module);
1390 ID id_refined_class;
1392 CONST_ID(id_refined_class,
"__refined_class__");
1397 add_activated_refinement(
VALUE activated_refinements,
1400 VALUE iclass, c, superclass = klass;
1405 if (
RBASIC(c)->klass == refinement) {
1416 while (refinement && refinement != klass) {
1438 ID id_refinements, id_activated_refinements,
1439 id_refined_class, id_defined_at;
1440 VALUE refinements, activated_refinements;
1451 ensure_class_or_module(klass);
1452 CONST_ID(id_refinements,
"__refinements__");
1453 refinements =
rb_attr_get(module, id_refinements);
1454 if (
NIL_P(refinements)) {
1455 refinements = hidden_identity_hash_new();
1458 CONST_ID(id_activated_refinements,
"__activated_refinements__");
1459 activated_refinements =
rb_attr_get(module, id_activated_refinements);
1460 if (
NIL_P(activated_refinements)) {
1461 activated_refinements = hidden_identity_hash_new();
1463 activated_refinements);
1466 if (
NIL_P(refinement)) {
1468 RCLASS_SET_SUPER(refinement, klass);
1470 CONST_ID(id_refined_class,
"__refined_class__");
1472 CONST_ID(id_defined_at,
"__defined_at__");
1475 add_activated_refinement(activated_refinements, klass, refinement);
1482 ignored_block(
VALUE module,
const char *klass)
1484 const char *anon =
"";
1487 anon =
", maybe for Module.new";
1489 rb_warn(
"%s""using doesn't call the given block""%s.", klass, anon);
1505 if (prev_frame_func()) {
1507 "Module#using is not permitted in methods");
1509 if (prev_cfp && prev_cfp->
self !=
self) {
1513 ignored_block(module,
"Module#");
1523 CONST_ID(id_defined_at,
"__defined_at__");
1557 rb_mod_s_used_modules(
void)
1563 if(!
NIL_P(CREF_REFINEMENTS(cref))) {
1566 cref = CREF_NEXT(cref);
1661 rb_obj_extend(
int argc,
VALUE *argv,
VALUE obj)
1664 ID id_extend_object, id_extended;
1666 CONST_ID(id_extend_object,
"extend_object");
1670 for (i = 0; i <
argc; i++)
1673 rb_funcall(argv[argc], id_extend_object, 1, obj);
1689 top_include(
int argc,
VALUE *argv,
VALUE self)
1694 rb_warning(
"main.include in the wrapped load is effective only in wrapper module");
1695 return rb_mod_include(argc, argv, th->
top_wrapper);
1697 return rb_mod_include(argc, argv,
rb_cObject);
1718 ignored_block(module,
"main.");
1724 static const VALUE *
1731 if (VM_FRAME_RUBYFRAME_P(cfp)) {
1749 const VALUE *ptr = errinfo_place(th);
1765 errinfo_getter(
ID id)
1767 return get_errinfo();
1819 set_backtrace(err, val);
1833 rb_f_method_name(
void)
1835 ID fname = prev_frame_func();
1855 rb_f_callee_name(
void)
1857 ID fname = prev_frame_callee();
1878 f_current_dirname(
void)
1912 rb_mod_s_used_modules, 0);
1924 "include", top_include, -1);
1926 "using", top_using, 1);
#define RBASIC_CLEAR_CLASS(obj)
int ruby_run_node(void *n)
Runs the given compiled source and exits this process.
void rb_threadptr_unlock_all_locking_mutexes(rb_thread_t *th)
#define RUBY_VM_CHECK_INTS(th)
int ruby_cleanup(volatile int ex)
Destructs the VM.
struct rb_ensure_entry entry
VALUE rb_protect(VALUE(*proc)(VALUE), VALUE data, int *pstate)
Protects a function call from potential global escapes from the function.
void rb_warn(const char *fmt,...)
#define RUBY_EVENT_C_RETURN
#define va_init_list(a, b)
#define INTERNAL_EXCEPTION_P(exc)
#define VM_ENV_INDEX_LAST_LVAR
void ruby_finalize(void)
Runs the VM finalization processes.
void rb_define_virtual_variable(const char *, VALUE(*)(ANYARGS), void(*)(ANYARGS))
VALUE rb_hash_dup(VALUE hash)
VALUE rb_threadptr_backtrace_object(rb_thread_t *th)
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
#define RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp)
int rb_block_given_p(void)
Determines if the current method is given a block.
VALUE rb_iseq_eval_main(const rb_iseq_t *iseq)
void rb_raise(VALUE exc, const char *fmt,...)
ID rb_frame_last_func(void)
Returns the ID of the last method in the call stack.
void rb_jump_tag(int tag)
Continues the exception caught by rb_protect() and rb_eval_string_protect().
void * ruby_options(int argc, char **argv)
Processes command line arguments and compiles the Ruby source to execute.
int rb_get_kwargs(VALUE keyword_hash, const ID *table, int required, int optional, VALUE *values)
VALUE rb_current_realfilepath(void)
void rb_exec_end_proc(void)
struct rb_method_definition_struct *const def
#define CLASS_OR_MODULE_P(obj)
const rb_callable_method_entry_t * rb_vm_frame_method_entry(const rb_control_frame_t *cfp)
VALUE rb_exc_new(VALUE etype, const char *ptr, long len)
void rb_define_private_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
#define rb_vm_register_special_exception(sp, e, m)
#define TH_JUMP_TAG(th, st)
int ruby_exec_node(void *n)
Runs the given compiled source.
VALUE rb_ary_push(VALUE ary, VALUE item)
#define VM_BLOCK_HANDLER_NONE
struct rb_iseq_constant_body * body
void rb_threadptr_setup_exception(rb_thread_t *th, VALUE mesg, VALUE cause)
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
rb_ensure_list_t * ensure_list
#define STACK_UPPER(x, a, b)
struct rb_vm_protect_tag * prev
VALUE rb_obj_dup(VALUE)
call-seq: obj.dup -> an_object
VALUE rb_ivar_get(VALUE, ID)
void Init_vm_objects(void)
VALUE rb_rescue(VALUE(*b_proc)(ANYARGS), VALUE data1, VALUE(*r_proc)(ANYARGS), VALUE data2)
An equivalent of rescue clause.
void rb_vm_localjump_error(const char *mesg, VALUE value, int reason)
void rb_include_module(VALUE klass, VALUE module)
VALUE rb_refinement_module_get_refined_class(VALUE module)
VALUE rb_hash_lookup(VALUE hash, VALUE key)
#define RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(th, cfp)
void rb_define_global_function(const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a global function.
VALUE rb_ensure(VALUE(*b_proc)(ANYARGS), VALUE data1, VALUE(*e_proc)(ANYARGS), VALUE data2)
An equivalent to ensure clause.
#define RUBY_DTRACE_HOOK(name, arg)
void rb_obj_call_init(VALUE obj, int argc, const VALUE *argv)
Calls #initialize method of obj with the given arguments.
#define ATOMIC_VALUE_EXCHANGE(var, val)
const char * rb_source_loc(int *pline)
void rb_undef_method(VALUE klass, const char *name)
VALUE rb_ivar_defined(VALUE, ID)
VALUE rb_rescue2(VALUE(*b_proc)(ANYARGS), VALUE data1, VALUE(*r_proc)(ANYARGS), VALUE data2,...)
An equivalent of rescue clause.
void rb_thread_terminate_all(void)
const char * rb_obj_classname(VALUE)
#define THROW_DATA_P(err)
void rb_hash_foreach(VALUE hash, int(*func)(ANYARGS), VALUE farg)
void rb_prepend_module(VALUE klass, VALUE module)
VALUE rb_singleton_class(VALUE obj)
Returns the singleton class of obj.
VALUE rb_obj_class(VALUE)
call-seq: obj.class -> class
#define RB_TYPE_P(obj, type)
VALUE rb_obj_is_kind_of(VALUE, VALUE)
call-seq: obj.is_a?(class) -> true or false obj.kind_of?(class) -> true or false
void * rb_mod_const_at(VALUE, void *)
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val)
int rb_threadptr_set_raised(rb_thread_t *th)
void ruby_init(void)
Calls ruby_setup() and check error.
RUBY_EXTERN VALUE rb_cObject
VALUE rb_obj_as_string(VALUE)
void rb_set_errinfo(VALUE err)
Sets the current exception ($!) to the given value.
#define OBJ_WB_UNPROTECT(x)
RUBY_EXTERN VALUE rb_mKernel
void rb_frozen_class_p(VALUE klass)
Asserts that klass is not a frozen class.
#define warn_print_str(x)
void rb_threadptr_check_signal(rb_thread_t *mth)
void rb_thread_stop_timer_thread(void)
char ary[RSTRING_EMBED_LEN_MAX+1]
RUBY_EXTERN VALUE rb_cModule
#define MEMCPY(p1, p2, type, n)
void ruby_stop(int ex)
Calls ruby_cleanup() and exits the process.
void rb_error_frozen(const char *what)
VALUE rb_yield_refine_block(VALUE refinement, VALUE refinements)
#define rb_thread_raised_clear(th)
#define RCLASS_REFINED_CLASS(c)
rb_cref_t * rb_vm_cref_replace_with_duplicated_cref(void)
void rb_vm_pop_frame(rb_thread_t *th)
void rb_need_block(void)
Declares that the current method needs a block.
VALUE rb_sprintf(const char *format,...)
VALUE rb_include_class_new(VALUE module, VALUE super)
void ruby_prog_init(void)
Defines built-in variables.
VALUE rb_file_dirname(VALUE fname)
void * rb_mod_const_of(VALUE, void *)
VALUE rb_ivar_set(VALUE, ID, VALUE)
VALUE rb_make_exception(int argc, const VALUE *argv)
Make an Exception object from the list of arguments in a manner similar to Kernel#raise.
void rb_clear_method_cache_by_class(VALUE)
void rb_exc_raise(VALUE mesg)
Raises an exception in the current thread.
struct rb_vm_protect_tag * protect_tag
VALUE rb_const_list(void *)
VALUE rb_vm_top_self(void)
#define SAVE_ROOT_JMPBUF(th, stmt)
VALUE rb_f_trace_var(int, const VALUE *)
#define EXEC_EVENT_HOOK(th_, flag_, self_, id_, called_id_, klass_, data_)
int ruby_vm_destruct(ruby_vm_t *vm)
int rb_threadptr_reset_raised(rb_thread_t *th)
VALUE rb_check_funcall(VALUE, ID, int, const VALUE *)
void ruby_init_stack(volatile VALUE *)
struct rb_ensure_list * next
RUBY_EXTERN VALUE rb_cClass
enum rb_iseq_constant_body::iseq_type type
#define RUBY_VM_END_CONTROL_FRAME(th)
VALUE rb_mod_constants(int, const VALUE *, VALUE)
enum rb_thread_status status
VALUE rb_vm_frame_block_handler(const rb_control_frame_t *cfp)
VALUE rb_f_untrace_var(int, const VALUE *)
VALUE rb_ident_hash_new(void)
VALUE rb_get_backtrace(VALUE exc)
#define UNLIMITED_ARGUMENTS
VALUE rb_module_new(void)
void * ruby_process_options(int, char **)
ID rb_frame_callee(void)
The name of the current method.
void rb_interrupt(void)
Raises an Interrupt exception.
void ruby_sig_finalize(void)
ID rb_frame_this_func(void)
The original name of the current method.
void rb_extend_object(VALUE obj, VALUE module)
Extend the object with the module.
VALUE rb_check_string_type(VALUE)
void rb_warning(const char *fmt,...)
VALUE rb_f_global_variables(void)
VALUE rb_errinfo(void)
The current exception in the current thread.
int rb_iterator_p(void)
Determines if the current method is an interator.
rb_execution_context_t ec
void rb_exc_fatal(VALUE mesg)
Raises a fatal error in the current thread.
void rb_vm_rewind_cfp(rb_thread_t *th, rb_control_frame_t *cfp)
#define CONST_ID(var, str)
void rb_gc_call_finalizer_at_exit(void)
#define rb_intern_const(str)
#define SPECIAL_CONST_P(x)
#define RUBY_VM_VALID_CONTROL_FRAME_P(cfp, ecfp)
void rb_clear_trace_func(void)
VALUE rb_exc_new_cstr(VALUE etype, const char *s)
void ruby_default_signal(int)
VALUE rb_search_class_path(VALUE)
void rb_threadptr_interrupt(rb_thread_t *th)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
#define unknown_longjmp_status(status)
rb_cref_t * rb_vm_cref(void)
NORETURN(void rb_raise_jump(VALUE, VALUE))
int ruby_executable_node(void *n, int *status)
Checks the return value of ruby_options().
VALUE rb_attr_get(VALUE, ID)
int ruby_setup(void)
Initializes the Ruby VM and builtin libraries.
#define PASS_PASSED_BLOCK_HANDLER()
void Init_eval_method(void)