14#include "ruby/internal/config.h"
16#ifdef HAVE_SYS_PRCTL_H
20#include "eval_intern.h"
23#include "internal/class.h"
24#include "internal/error.h"
25#include "internal/eval.h"
26#include "internal/hash.h"
27#include "internal/inits.h"
28#include "internal/io.h"
29#include "internal/object.h"
30#include "internal/thread.h"
31#include "internal/variable.h"
36#include "probes_helper.h"
39#include "ractor_core.h"
41NORETURN(
static void rb_raise_jump(VALUE, VALUE));
51ID ruby_static_id_signo, ruby_static_id_status;
52extern ID ruby_static_id_cause;
53#define id_cause ruby_static_id_cause
55#define exception_error GET_VM()->special_exceptions[ruby_error_reenter]
57#include "eval_error.c"
60#define CLASS_OR_MODULE_P(obj) \
61 (!SPECIAL_CONST_P(obj) && \
62 (BUILTIN_TYPE(obj) == T_CLASS || BUILTIN_TYPE(obj) == T_MODULE))
67 enum ruby_tag_type state;
78#if defined(__linux__) && defined(PR_SET_THP_DISABLE)
79 prctl(PR_SET_THP_DISABLE, 1, 0, 0, 0);
83 rb_vm_encoded_insn_data_table_init();
86 EC_PUSH_TAG(GET_EC());
87 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
90 GET_VM()->running = 1;
103 error_print(GET_EC());
112 enum ruby_tag_type state;
113 void *
volatile iseq = 0;
117 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
121 rb_ec_clear_current_thread_trace_func(ec);
122 state = error_handle(ec, state);
132 enum ruby_tag_type state;
135 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
139 state = error_handle(ec, state);
148 rb_ec_fiber_scheduler_finalize(ec);
151 if (EC_EXEC_TAG() == TAG_NONE) {
152 rb_vm_trap_exit(rb_ec_vm_ptr(ec));
155 rb_ec_exec_end_proc(ec);
156 rb_ec_clear_all_trace_func(ec);
164 rb_objspace_call_finalizer(rb_ec_vm_ptr(ec)->objspace);
178 return rb_ec_cleanup(GET_EC(), ex);
189 volatile int sysex = EXIT_SUCCESS;
190 volatile int step = 0;
191 volatile int ex = ex0;
193 rb_threadptr_interrupt(th);
194 rb_threadptr_check_signal(th);
197 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
198 SAVE_ROOT_JMPBUF(th, { RUBY_VM_CHECK_INTS(ec); });
201 errs[1] = ec->errinfo;
202 if (THROW_DATA_P(ec->errinfo)) ec->errinfo =
Qnil;
205 SAVE_ROOT_JMPBUF(th, rb_ec_teardown(ec));
209 th->status = THREAD_KILLED;
211 errs[0] = ec->errinfo;
212 SAVE_ROOT_JMPBUF(th, rb_ractor_terminate_all());
220 if (ex == 0) ex = state;
222 ec->errinfo = errs[1];
223 sysex = error_handle(ec, ex);
226 for (nerr = 0; nerr < numberof(errs); ++nerr) {
227 VALUE err = ATOMIC_VALUE_EXCHANGE(errs[nerr],
Qnil);
230 if (!
RTEST(err))
continue;
233 if (THROW_DATA_P(err))
continue;
235 if (rb_obj_is_kind_of(err, rb_eSystemExit)) {
236 sysex = sysexit_status(err);
239 else if (rb_obj_is_kind_of(err, rb_eSignal)) {
244 else if (rb_obj_is_kind_of(err, rb_eSystemCallError) &&
249 else if (sysex == EXIT_SUCCESS) {
250 sysex = EXIT_FAILURE;
259 rb_threadptr_unlock_all_locking_mutexes(th);
263 rb_thread_stop_timer_thread();
278 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
280 SAVE_ROOT_JMPBUF(th, {
281 rb_iseq_eval_main(iseq);
301 case Qtrue: s = EXIT_SUCCESS;
break;
302 case Qfalse: s = EXIT_FAILURE;
break;
307 if (status) *status = s;
317 rb_ec_cleanup(ec, 0);
321 return rb_ec_cleanup(ec, rb_ec_exec_node(ec, n));
328 return rb_ec_exec_node(GET_EC(), n);
347rb_mod_nesting(VALUE
_)
352 while (cref && CREF_NEXT(cref)) {
353 VALUE klass = CREF_CLASS(cref);
354 if (!CREF_PUSHED_BY_EVAL(cref) &&
358 cref = CREF_NEXT(cref);
386rb_mod_s_constants(
int argc, VALUE *argv, VALUE mod)
393 if (argc > 0 || mod != rb_cModule) {
398 klass = CREF_CLASS(cref);
399 if (!CREF_PUSHED_BY_EVAL(cref) &&
406 cref = CREF_NEXT(cref);
428 rb_module_set_initialized(klass);
464 rb_frozen_error_raise(klass,
"can't modify frozen %s: %"PRIsVALUE, desc, klass);
469static VALUE get_errinfo(
void);
470#define get_ec_errinfo(ec) rb_ec_get_errinfo(ec)
473exc_setup_cause(VALUE exc, VALUE cause)
478 CONST_ID(id_true_cause,
"true_cause");
489 if (!
NIL_P(cause) && cause != exc) {
506 if (INTERNAL_EXCEPTION_P(mesg)) EC_JUMP_TAG(ec, TAG_FATAL);
510 mesg = rb_exc_new(rb_eRuntimeError, 0, 0);
520 *cause = get_ec_errinfo(ec);
526 else if (!
NIL_P(*cause) && !rb_obj_is_kind_of(*cause, rb_eException)) {
527 rb_raise(rb_eTypeError,
"exception object expected");
530 if (!nocircular && !
NIL_P(*cause) && *cause !=
Qundef && *cause != mesg) {
534 rb_raise(rb_eArgError,
"circular causes");
546 const char *file = rb_source_location_cstr(&line);
547 const char *
const volatile file0 = file;
550 volatile int state = 0;
553 if (EC_EXEC_TAG() == TAG_NONE && !(state = rb_ec_set_raised(ec))) {
554 VALUE bt = rb_get_backtrace(mesg);
557 mesg = rb_obj_dup(mesg);
560 if (cause !=
Qundef && !THROW_DATA_P(cause)) {
561 exc_setup_cause(mesg, cause);
564 VALUE at = rb_ec_backtrace_object(ec);
566 set_backtrace(mesg, at);
568 rb_ec_reset_raised(ec);
572 if (state)
goto fatal;
580 !rb_obj_is_kind_of(e, rb_eSystemExit)) {
581 enum ruby_tag_type state;
585 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
590 e =
rb_sprintf(
"Exception `%"PRIsVALUE
"' at %s:%d - %"PRIsVALUE
"\n",
591 rb_obj_class(mesg), file, line, e);
594 e =
rb_sprintf(
"Exception `%"PRIsVALUE
"' at %s - %"PRIsVALUE
"\n",
595 rb_obj_class(mesg), file, e);
598 e =
rb_sprintf(
"Exception `%"PRIsVALUE
"' - %"PRIsVALUE
"\n",
599 rb_obj_class(mesg), e);
604 if (state == TAG_FATAL && ec->errinfo == exception_error) {
608 rb_ec_reset_raised(ec);
609 EC_JUMP_TAG(ec, state);
613 if (rb_ec_set_raised(ec)) {
617 if (tag != TAG_FATAL) {
624 ec->errinfo = exception_error;
625 rb_ec_reset_raised(ec);
626 EC_JUMP_TAG(ec, TAG_FATAL);
634 cause = get_ec_errinfo(ec);
644 mesg = exc_setup_message(ec, mesg, &cause);
645 setup_exception(ec, tag, mesg, cause);
646 rb_ec_raised_clear(ec);
647 EC_JUMP_TAG(ec, tag);
650static VALUE make_exception(
int argc,
const VALUE *argv,
int isstr);
652NORETURN(
static void rb_exc_exception(VALUE mesg,
int tag, VALUE cause));
655rb_exc_exception(VALUE mesg,
int tag, VALUE cause)
658 mesg = make_exception(1, &mesg, FALSE);
660 rb_longjmp(GET_EC(), tag, mesg, cause);
673 rb_exc_exception(mesg, TAG_RAISE,
Qundef);
686 rb_exc_exception(mesg, TAG_FATAL,
Qnil);
695enum {raise_opt_cause, raise_max_opt};
698extract_raise_opts(
int argc,
const VALUE *argv, VALUE *opts)
702 VALUE opt = argv[argc-1];
713 for (i = 0; i < raise_max_opt; ++i) {
720rb_f_raise(
int argc, VALUE *argv)
723 VALUE opts[raise_max_opt], *
const cause = &opts[raise_opt_cause];
725 argc = extract_raise_opts(argc, argv, opts);
728 rb_raise(rb_eArgError,
"only cause is given with no arguments");
771f_raise(
int c, VALUE *v, VALUE
_)
773 return rb_f_raise(c, v);
777make_exception(
int argc,
const VALUE *argv,
int isstr)
787 if (isstr &&!
NIL_P(exc)) {
798 rb_error_arity(argc, 0, 3);
804 rb_raise(rb_eTypeError,
"exception class/object expected");
806 if (!rb_obj_is_kind_of(mesg, rb_eException)) {
807 rb_raise(rb_eTypeError,
"exception object expected");
810 set_backtrace(mesg, argv[2]);
819 return make_exception(argc, argv, TRUE);
825rb_raise_jump(VALUE mesg, VALUE cause)
830 VALUE klass = me->owner;
831 VALUE
self = cfp->self;
832 ID mid = me->called_id;
837 rb_longjmp(ec, TAG_RAISE, mesg, cause);
843 if (UNLIKELY(tag < TAG_RETURN || tag > TAG_FATAL)) {
844 unknown_longjmp_status(tag);
846 EC_JUMP_TAG(GET_EC(), tag);
852 if (rb_vm_frame_block_handler(GET_EC()->cfp) == VM_BLOCK_HANDLER_NONE) {
865 return rb_vm_cframe_keyword_p(GET_EC()->cfp);
874 rb_vm_localjump_error(
"no block given",
Qnil, 0);
880 VALUE (* r_proc) (VALUE, VALUE), VALUE data2, ...)
884 VALUE ret =
rb_vrescue2(b_proc, data1, r_proc, data2, ap);
891 VALUE (* r_proc) (VALUE, VALUE), VALUE data2,
894 enum ruby_tag_type state;
897 volatile VALUE result =
Qfalse;
898 volatile VALUE e_info = ec->errinfo;
901 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
903 result = (*b_proc) (data1);
907 if (state == TAG_RETRY) {
915 rb_vm_rewind_cfp(ec, cfp);
917 if (state == TAG_RAISE) {
925 while ((eclass = va_arg(ap, VALUE)) != 0) {
926 if (rb_obj_is_kind_of(ec->errinfo, eclass)) {
936 result = (*r_proc) (data2, ec->errinfo);
938 ec->errinfo = e_info;
944 EC_JUMP_TAG(ec, state);
951 VALUE (* r_proc)(VALUE, VALUE), VALUE data2)
953 return rb_rescue2(b_proc, data1, r_proc, data2, rb_eStandardError,
958rb_protect(VALUE (* proc) (VALUE), VALUE data,
int *pstate)
960 volatile VALUE result =
Qnil;
961 volatile enum ruby_tag_type state;
966 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
967 SAVE_ROOT_JMPBUF(rb_ec_thread_ptr(ec), result = (*proc) (data));
970 rb_vm_rewind_cfp(ec, cfp);
974 if (pstate != NULL) *pstate = state;
979rb_ensure(VALUE (*b_proc)(VALUE), VALUE data1, VALUE (*e_proc)(VALUE), VALUE data2)
982 volatile VALUE result =
Qnil;
986 ensure_list.entry.marker = 0;
987 ensure_list.entry.e_proc = e_proc;
988 ensure_list.entry.data2 = data2;
989 ensure_list.next = ec->ensure_list;
990 ec->ensure_list = &ensure_list;
992 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
993 result = (*b_proc) (data1);
996 errinfo = ec->errinfo;
1000 ec->ensure_list=ensure_list.next;
1001 (*ensure_list.entry.e_proc)(ensure_list.entry.data2);
1002 ec->errinfo = errinfo;
1004 EC_JUMP_TAG(ec, state);
1014 return me->def->original_id;
1027 return me->called_id;
1037 return frame_func_id(GET_EC()->cfp);
1043 return frame_called_id(GET_EC()->cfp);
1051 if ((
void *)(ec->vm_stack + ec->vm_stack_size) == (
void *)(prev_cfp)) {
1058prev_frame_callee(
void)
1061 if (!prev_cfp)
return 0;
1062 return frame_called_id(prev_cfp);
1066prev_frame_func(
void)
1069 if (!prev_cfp)
return 0;
1070 return frame_func_id(prev_cfp);
1086 while (!(mid = frame_func_id(cfp)) &&
1087 (cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp),
1088 !RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(ec, cfp)));
1105rb_mod_append_features(VALUE module, VALUE include)
1107 if (!CLASS_OR_MODULE_P(include)) {
1123rb_mod_include(
int argc, VALUE *argv, VALUE module)
1126 ID id_append_features, id_included;
1128 CONST_ID(id_append_features,
"append_features");
1131 if (
FL_TEST(module, RMODULE_IS_REFINEMENT)) {
1132 rb_warn_deprecated_to_remove_at(3.2,
"Refinement#include", NULL);
1136 for (i = 0; i < argc; i++)
1139 rb_funcall(argv[argc], id_append_features, 1, module);
1140 rb_funcall(argv[argc], id_included, 1, module);
1158rb_mod_prepend_features(VALUE module, VALUE prepend)
1160 if (!CLASS_OR_MODULE_P(prepend)) {
1176rb_mod_prepend(
int argc, VALUE *argv, VALUE module)
1179 ID id_prepend_features, id_prepended;
1181 if (
FL_TEST(module, RMODULE_IS_REFINEMENT)) {
1182 rb_warn_deprecated_to_remove_at(3.2,
"Refinement#prepend", NULL);
1185 CONST_ID(id_prepend_features,
"prepend_features");
1186 CONST_ID(id_prepended,
"prepended");
1189 for (i = 0; i < argc; i++)
1192 rb_funcall(argv[argc], id_prepend_features, 1, module);
1193 rb_funcall(argv[argc], id_prepended, 1, module);
1199ensure_class_or_module(VALUE obj)
1203 "wrong argument type %"PRIsVALUE
" (expected Class or Module)",
1209hidden_identity_hash_new(
void)
1211 VALUE hash = rb_ident_hash_new();
1213 RBASIC_CLEAR_CLASS(hash);
1218refinement_superclass(VALUE superclass)
1222 return rb_include_class_new(RCLASS_ORIGIN(superclass), rb_cBasicObject);
1233rb_using_refinement(
rb_cref_t *cref, VALUE klass, VALUE module)
1235 VALUE iclass, c, superclass = klass;
1237 ensure_class_or_module(klass);
1239 if (
NIL_P(CREF_REFINEMENTS(cref))) {
1240 CREF_REFINEMENTS_SET(cref, hidden_identity_hash_new());
1243 if (CREF_OMOD_SHARED(cref)) {
1244 CREF_REFINEMENTS_SET(cref,
rb_hash_dup(CREF_REFINEMENTS(cref)));
1245 CREF_OMOD_SHARED_UNSET(cref);
1250 if (
RBASIC(c)->klass == module) {
1258 FL_SET(module, RMODULE_IS_OVERLAID);
1259 superclass = refinement_superclass(superclass);
1260 c = iclass = rb_include_class_new(module, superclass);
1263 RCLASS_M_TBL(c) = RCLASS_M_TBL(module);
1266 while (module && module != klass) {
1267 FL_SET(module, RMODULE_IS_OVERLAID);
1268 c = RCLASS_SET_SUPER(c, rb_include_class_new(module,
RCLASS_SUPER(c)));
1276using_refinement(VALUE klass, VALUE module, VALUE arg)
1280 rb_using_refinement(cref, klass, module);
1285using_module_recursive(
const rb_cref_t *cref, VALUE klass)
1288 VALUE super, module, refinements;
1292 using_module_recursive(cref, super);
1300 module =
RBASIC(klass)->klass;
1304 rb_raise(rb_eTypeError,
"wrong argument type %s (expected Module)",
1308 CONST_ID(id_refinements,
"__refinements__");
1309 refinements =
rb_attr_get(module, id_refinements);
1310 if (
NIL_P(refinements))
return;
1318rb_using_module(
const rb_cref_t *cref, VALUE module)
1321 using_module_recursive(cref, module);
1322 rb_clear_method_cache_all();
1327rb_refinement_module_get_refined_class(VALUE module)
1329 ID id_refined_class;
1331 CONST_ID(id_refined_class,
"__refined_class__");
1336add_activated_refinement(VALUE activated_refinements,
1337 VALUE klass, VALUE refinement)
1339 VALUE iclass, c, superclass = klass;
1344 if (
RBASIC(c)->klass == refinement) {
1351 FL_SET(refinement, RMODULE_IS_OVERLAID);
1352 superclass = refinement_superclass(superclass);
1353 c = iclass = rb_include_class_new(refinement, superclass);
1356 while (refinement && refinement != klass) {
1357 FL_SET(refinement, RMODULE_IS_OVERLAID);
1358 c = RCLASS_SET_SUPER(c, rb_include_class_new(refinement,
RCLASS_SUPER(c)));
1375rb_mod_refine(VALUE module, VALUE klass)
1378 ID id_refinements, id_activated_refinements,
1379 id_refined_class, id_defined_at;
1380 VALUE refinements, activated_refinements;
1382 VALUE block_handler = rb_vm_frame_block_handler(th->ec->cfp);
1384 if (block_handler == VM_BLOCK_HANDLER_NONE) {
1385 rb_raise(rb_eArgError,
"no block given");
1387 if (vm_block_handler_type(block_handler) != block_handler_type_iseq) {
1388 rb_raise(rb_eArgError,
"can't pass a Proc as a block to Module#refine");
1391 ensure_class_or_module(klass);
1392 CONST_ID(id_refinements,
"__refinements__");
1393 refinements =
rb_attr_get(module, id_refinements);
1394 if (
NIL_P(refinements)) {
1395 refinements = hidden_identity_hash_new();
1398 CONST_ID(id_activated_refinements,
"__activated_refinements__");
1399 activated_refinements =
rb_attr_get(module, id_activated_refinements);
1400 if (
NIL_P(activated_refinements)) {
1401 activated_refinements = hidden_identity_hash_new();
1403 activated_refinements);
1406 if (
NIL_P(refinement)) {
1407 VALUE superclass = refinement_superclass(klass);
1408 refinement = rb_refinement_new();
1409 RCLASS_SET_SUPER(refinement, superclass);
1410 FL_SET(refinement, RMODULE_IS_REFINEMENT);
1411 CONST_ID(id_refined_class,
"__refined_class__");
1413 CONST_ID(id_defined_at,
"__defined_at__");
1416 add_activated_refinement(activated_refinements, klass, refinement);
1418 rb_yield_refine_block(refinement, activated_refinements);
1423ignored_block(VALUE module,
const char *klass)
1425 const char *anon =
"";
1427 if (!
RTEST(rb_search_class_path(module))) {
1428 anon =
", maybe for Module.new";
1430 rb_warn(
"%s""using doesn't call the given block""%s.", klass, anon);
1442mod_using(VALUE
self, VALUE module)
1446 if (prev_frame_func()) {
1448 "Module#using is not permitted in methods");
1450 if (prev_cfp && prev_cfp->self !=
self) {
1451 rb_raise(rb_eRuntimeError,
"Module#using is not called on self");
1454 ignored_block(module,
"Module#");
1456 rb_using_module(rb_vm_cref_replace_with_duplicated_cref(), module);
1461used_modules_i(VALUE
_, VALUE mod, VALUE ary)
1464 CONST_ID(id_defined_at,
"__defined_at__");
1498rb_mod_s_used_modules(VALUE
_)
1504 if (!
NIL_P(CREF_REFINEMENTS(cref))) {
1507 cref = CREF_NEXT(cref);
1522static enum rb_id_table_iterator_result
1523refinement_import_methods_i(ID key, VALUE value,
void *data)
1528 if (me->def->type != VM_METHOD_TYPE_ISEQ) {
1529 rb_raise(rb_eArgError,
"Can't import method which is not defined with Ruby code: %"PRIsVALUE
"#%"PRIsVALUE,
rb_class_path(arg->module),
rb_id2str(key));
1531 rb_cref_t *new_cref = rb_vm_cref_dup_without_refinements(me->def->body.iseq.
cref);
1532 CREF_REFINEMENTS_SET(new_cref, CREF_REFINEMENTS(arg->cref));
1533 rb_add_method_iseq(arg->refinement, key, me->def->body.iseq.
iseqptr, new_cref, METHOD_ENTRY_VISI(me));
1534 return ID_TABLE_CONTINUE;
1542refinement_import_methods(
int argc, VALUE *argv, VALUE refinement)
1548 for (i = 0; i < argc; i++) {
1551 rb_warn(
"%"PRIsVALUE
" has ancestors, but Refinement#import_methods doesn't import their methods",
rb_class_path(argv[i]));
1554 arg.cref = rb_vm_cref_replace_with_duplicated_cref();
1555 arg.refinement = refinement;
1556 for (i = 0; i < argc; i++) {
1557 arg.module = argv[i];
1558 struct rb_id_table *m_tbl = RCLASS_M_TBL(argv[i]);
1559 if (!m_tbl)
continue;
1560 rb_id_table_foreach(m_tbl, refinement_import_methods_i, &arg);
1574 PASS_PASSED_BLOCK_HANDLER();
1612rb_mod_extend_object(VALUE mod, VALUE obj)
1644rb_obj_extend(
int argc, VALUE *argv, VALUE obj)
1647 ID id_extend_object, id_extended;
1649 CONST_ID(id_extend_object,
"extend_object");
1653 for (i = 0; i < argc; i++)
1656 rb_funcall(argv[argc], id_extend_object, 1, obj);
1672top_include(
int argc, VALUE *argv, VALUE
self)
1676 if (th->top_wrapper) {
1677 rb_warning(
"main.include in the wrapped load is effective only in wrapper module");
1678 return rb_mod_include(argc, argv, th->top_wrapper);
1680 return rb_mod_include(argc, argv, rb_cObject);
1692top_using(VALUE
self, VALUE module)
1697 if (CREF_NEXT(cref) || (prev_cfp && rb_vm_frame_method_entry(prev_cfp))) {
1698 rb_raise(rb_eRuntimeError,
"main.using is permitted only at toplevel");
1701 ignored_block(module,
"main.");
1703 rb_using_module(rb_vm_cref_replace_with_duplicated_cref(), module);
1713 while (RUBY_VM_VALID_CONTROL_FRAME_P(cfp, end_cfp)) {
1714 if (VM_FRAME_RUBYFRAME_P(cfp)) {
1715 if (cfp->iseq->body->type == ISEQ_TYPE_RESCUE) {
1716 return &cfp->ep[VM_ENV_INDEX_LAST_LVAR];
1718 else if (cfp->iseq->body->type == ISEQ_TYPE_ENSURE &&
1719 !THROW_DATA_P(cfp->ep[VM_ENV_INDEX_LAST_LVAR]) &&
1720 !
FIXNUM_P(cfp->ep[VM_ENV_INDEX_LAST_LVAR])) {
1721 return &cfp->ep[VM_ENV_INDEX_LAST_LVAR];
1724 cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
1732 const VALUE *ptr = errinfo_place(ec);
1744 return get_ec_errinfo(GET_EC());
1748errinfo_getter(ID
id, VALUE *
_)
1750 return get_errinfo();
1756 return GET_EC()->errinfo;
1762 if (!
NIL_P(err) && !rb_obj_is_kind_of(err, rb_eException)) {
1763 rb_raise(rb_eTypeError,
"assigning non-exception to $!");
1765 GET_EC()->errinfo = err;
1769errat_getter(ID
id, VALUE *
_)
1771 VALUE err = get_errinfo();
1773 return rb_get_backtrace(err);
1781errat_setter(VALUE val, ID
id, VALUE *var)
1783 VALUE err = get_errinfo();
1785 rb_raise(rb_eArgError,
"$! not set");
1787 set_backtrace(err, val);
1801rb_f_method_name(VALUE
_)
1803 ID fname = prev_frame_func();
1823rb_f_callee_name(VALUE
_)
1825 ID fname = prev_frame_callee();
1846f_current_dirname(VALUE
_)
1848 VALUE base = rb_current_realfilepath();
1869f_global_variables(VALUE
_)
1898f_trace_var(
int c,
const VALUE *a, VALUE
_)
1914f_untrace_var(
int c,
const VALUE *a, VALUE
_)
1925 rb_gvar_ractor_local(
"$@");
1926 rb_gvar_ractor_local(
"$!");
1946 rb_mod_s_used_modules, 0);
1959 "include", top_include, -1);
1961 "using", top_using, 1);
1968 rb_vm_register_special_exception(ruby_error_reenter, rb_eFatal,
"exception reentered");
1969 rb_vm_register_special_exception(ruby_error_stackfatal, rb_eFatal,
"machine stack overflow in critical region");
#define rb_define_singleton_method(klass, mid, func, arity)
Defines klass.mid.
#define rb_define_private_method(klass, mid, func, arity)
Defines klass#mid and makes it private.
#define RUBY_EVENT_RAISE
Encountered a raise statement.
#define RUBY_EVENT_C_RETURN
Return from a method, written in C.
void rb_include_module(VALUE klass, VALUE module)
Includes a module to a class.
void rb_extend_object(VALUE obj, VALUE module)
Extend the object with the module.
void rb_prepend_module(VALUE klass, VALUE module)
Identical to rb_include_module(), except it "prepends" the passed module to the klass,...
void rb_class_modify_check(VALUE klass)
Asserts that klass is not a frozen class.
void rb_need_block(void)
Declares that the current method needs a block.
ID rb_frame_last_func(void)
Returns the ID of the last method in the call stack.
void rb_undef_method(VALUE klass, const char *name)
Defines an undef of a method.
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a method.
int rb_keyword_given_p(void)
Determines if the current method is given a keyword argument.
int rb_block_given_p(void)
Determines if the current method is given a block.
int rb_get_kwargs(VALUE keyword_hash, const ID *table, int required, int optional, VALUE *values)
Keyword argument deconstructor.
void rb_define_global_function(const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a global function.
#define FL_SINGLETON
Old name of RUBY_FL_SINGLETON.
#define Qundef
Old name of RUBY_Qundef.
#define INT2FIX
Old name of RB_INT2FIX.
#define OBJ_FROZEN
Old name of RB_OBJ_FROZEN.
#define UNREACHABLE
Old name of RBIMPL_UNREACHABLE.
#define ID2SYM
Old name of RB_ID2SYM.
#define SPECIAL_CONST_P
Old name of RB_SPECIAL_CONST_P.
#define OBJ_FREEZE
Old name of RB_OBJ_FREEZE.
#define UNREACHABLE_RETURN
Old name of RBIMPL_UNREACHABLE_RETURN.
#define FIX2INT
Old name of RB_FIX2INT.
#define T_MODULE
Old name of RUBY_T_MODULE.
#define T_ICLASS
Old name of RUBY_T_ICLASS.
#define T_HASH
Old name of RUBY_T_HASH.
#define FL_SET
Old name of RB_FL_SET.
#define rb_exc_new3
Old name of rb_exc_new_str.
#define Qtrue
Old name of RUBY_Qtrue.
#define NUM2INT
Old name of RB_NUM2INT.
#define Qnil
Old name of RUBY_Qnil.
#define Qfalse
Old name of RUBY_Qfalse.
#define T_OBJECT
Old name of RUBY_T_OBJECT.
#define NIL_P
Old name of RB_NIL_P.
#define T_CLASS
Old name of RUBY_T_CLASS.
#define BUILTIN_TYPE
Old name of RB_BUILTIN_TYPE.
#define FL_TEST
Old name of RB_FL_TEST.
#define FIXNUM_P
Old name of RB_FIXNUM_P.
#define CONST_ID
Old name of RUBY_CONST_ID.
void ruby_stop(int ex)
Calls ruby_cleanup() and exits the process.
int ruby_exec_node(void *n)
Identical to ruby_run_node(), except it returns an opaque execution status.
int ruby_setup(void)
Initializes the VM and builtin libraries.
void ruby_finalize(void)
Runs the VM finalization processes.
void ruby_init_stack(volatile VALUE *addr)
Set stack bottom of Ruby implementation.
int ruby_cleanup(int ex)
Destructs the VM.
void * ruby_process_options(int argc, char **argv)
Identical to ruby_options(), except it raises ruby-level exceptions on failure.
void ruby_prog_init(void)
Defines built-in variables.
void ruby_sig_finalize(void)
Clear signal handlers.
#define ruby_debug
This variable controls whether the interpreter is in debug mode.
VALUE rb_eLocalJumpError
LocalJumpError exception.
void rb_raise(VALUE exc, const char *fmt,...)
Exception entry point.
VALUE rb_rescue2(VALUE(*b_proc)(VALUE), VALUE data1, VALUE(*r_proc)(VALUE, VALUE), VALUE data2,...)
An equivalent of rescue clause.
void rb_exc_raise(VALUE mesg)
Raises an exception in the current thread.
void rb_set_errinfo(VALUE err)
Sets the current exception ($!) to the given value.
VALUE rb_vrescue2(VALUE(*b_proc)(VALUE), VALUE data1, VALUE(*r_proc)(VALUE, VALUE), VALUE data2, va_list args)
Identical to rb_rescue2(), except it takes va_list instead of variadic number of arguments.
void rb_exc_fatal(VALUE mesg)
Raises a fatal error in the current thread.
void rb_warn(const char *fmt,...)
Identical to rb_warning(), except it reports always regardless of runtime -W flag.
VALUE rb_rescue(VALUE(*b_proc)(VALUE), VALUE data1, VALUE(*r_proc)(VALUE, VALUE), VALUE data2)
Identical to rb_rescue2(), except it does not take a list of exception classes.
VALUE rb_ensure(VALUE(*b_proc)(VALUE), VALUE data1, VALUE(*e_proc)(VALUE), VALUE data2)
An equivalent to ensure clause.
VALUE rb_errinfo(void)
This is the same as $! in Ruby.
VALUE rb_eSysStackError
SystemStackError exception.
VALUE rb_eThreadError
ThreadError exception.
void rb_warning(const char *fmt,...)
Issues a warning.
static VALUE rb_class_of(VALUE obj)
Object to class mapping function.
#define RB_OBJ_WRITE(old, slot, young)
Declaration of a "back" pointer.
int ruby_run_node(void *n)
Runs the given compiled source and exits this process.
void ruby_init(void)
Calls ruby_setup() and check error.
void * ruby_options(int argc, char **argv)
Processes command line arguments and compiles the Ruby source to execute.
int ruby_executable_node(void *n, int *status)
Checks the return value of ruby_options().
VALUE rb_funcall(VALUE recv, ID mid, int n,...)
Calls a method.
VALUE rb_funcallv_kw(VALUE recv, ID mid, int argc, const VALUE *argv, int kw_splat)
Identical to rb_funcallv(), except you can specify how to handle the last element of the given array.
VALUE rb_ary_new(void)
Allocates a new, empty array.
VALUE rb_ary_push(VALUE ary, VALUE elem)
Special case of rb_ary_cat() that it adds only one element.
#define UNLIMITED_ARGUMENTS
This macro is used in conjunction with rb_check_arity().
static int rb_check_arity(int argc, int min, int max)
Ensures that the passed integer is in the passed range.
ID rb_frame_callee(void)
Identical to rb_frame_this_func(), except it returns the named used to call the method.
ID rb_frame_this_func(void)
Queries the name of the Ruby level method that is calling this function.
void rb_obj_call_init(VALUE obj, int argc, const VALUE *argv)
Calls initialize method of the passed object with the passed arguments.
void rb_interrupt(void)
Raises an instance of rb_eInterrupt.
VALUE rb_make_exception(int argc, const VALUE *argv)
Constructs an exception object from the list of arguments, in a manner similar to Ruby's raise.
void rb_jump_tag(int state)
This function is to re-throw global escapes.
void rb_obj_call_init_kw(VALUE, int, const VALUE *, int)
Identical to rb_obj_call_init(), except you can specify how to handle the last element of the given a...
VALUE rb_file_dirname(VALUE fname)
Strips a file path's last component (and trailing separators if any).
void rb_hash_foreach(VALUE hash, int(*func)(VALUE key, VALUE val, VALUE arg), VALUE arg)
Iterates over a hash.
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val)
Inserts or replaces ("upsert"s) the objects into the given hash table.
VALUE rb_hash_lookup(VALUE hash, VALUE key)
Identical to rb_hash_aref(), except it always returns RUBY_Qnil for misshits.
VALUE rb_hash_dup(VALUE hash)
Duplicates a hash.
VALUE rb_protect(VALUE(*func)(VALUE args), VALUE args, int *state)
Protects a function call from potential global escapes from the function.
void ruby_default_signal(int sig)
Pretends as if there was no custom signal handler.
#define rb_exc_new_cstr(exc, str)
Identical to rb_exc_new(), except it assumes the passed pointer is a pointer to a C string.
VALUE rb_check_string_type(VALUE obj)
Try converting an object to its stringised representation using its to_str method,...
VALUE rb_obj_as_string(VALUE obj)
Try converting an object to its stringised representation using its to_s method, if any.
VALUE rb_f_untrace_var(int argc, const VALUE *argv)
Deletes the passed tracer from the passed global variable, or if omitted, deletes everything.
VALUE rb_const_list(void *)
This is another mysterious API that comes with no documents at all.
VALUE rb_attr_get(VALUE obj, ID name)
Identical to rb_ivar_get()
VALUE rb_ivar_set(VALUE obj, ID name, VALUE val)
Identical to rb_iv_set(), except it accepts the name as an ID instead of a C string.
VALUE rb_f_trace_var(int argc, const VALUE *argv)
Traces a global variable.
VALUE rb_mod_constants(int argc, const VALUE *argv, VALUE recv)
Resembles Module#constants.
VALUE rb_ivar_get(VALUE obj, ID name)
Identical to rb_iv_get(), except it accepts the name as an ID instead of a C string.
void * rb_mod_const_of(VALUE, void *)
This is a variant of rb_mod_const_at().
void * rb_mod_const_at(VALUE, void *)
This API is mysterious.
VALUE rb_ivar_defined(VALUE obj, ID name)
Queries if the instance variable is defined at the object.
VALUE rb_f_global_variables(void)
Queries the list of global variables.
VALUE rb_class_path(VALUE mod)
Identical to rb_mod_name(), except it returns #<Class: ...> style inspection for anonymous modules.
VALUE rb_check_funcall(VALUE recv, ID mid, int argc, const VALUE *argv)
Identical to rb_funcallv(), except it returns RUBY_Qundef instead of raising rb_eNoMethodError.
static ID rb_intern_const(const char *str)
This is a "tiny optimisation" over rb_intern().
ID rb_intern(const char *name)
Finds or creates a symbol of the given name.
VALUE rb_id2str(ID id)
Identical to rb_id2name(), except it returns a Ruby's String instead of C's.
void rb_define_virtual_variable(const char *name, rb_gvar_getter_t *getter, rb_gvar_setter_t *setter)
Defines a global variable that is purely function-backended.
int ruby_vm_destruct(ruby_vm_t *vm)
Destructs the passed VM.
VALUE rb_sprintf(const char *fmt,...)
Ruby's extended sprintf(3).
#define RBASIC(obj)
Convenient casting macro.
#define RCLASS_SUPER
Just another name of rb_class_get_superclass.
#define RHASH_EMPTY_P(h)
Checks if the hash is empty.
const char * rb_obj_classname(VALUE obj)
Queries the name of the class of the passed object.
#define RB_NO_KEYWORDS
Do not pass keywords.
VALUE rb_fiber_scheduler_set(VALUE scheduler)
Destructively assigns the passed scheduler to that of the current thread that is calling this functio...
#define RTEST
This is an old name of RB_TEST.
#define _(args)
This was a transition path from K&R to ANSI.
const rb_iseq_t * iseqptr
iseq pointer, should be separated from iseqval
rb_cref_t * cref
class reference, should be marked
uintptr_t VALUE
Type that represents a Ruby object.
static void Check_Type(VALUE v, enum ruby_value_type t)
Identical to RB_TYPE_P(), except it raises exceptions on predication failure.
static bool RB_TYPE_P(VALUE obj, enum ruby_value_type t)
Queries if the given object is of given type.