14#include "ruby/internal/config.h"
16#ifdef HAVE_SYS_PRCTL_H
20#include "eval_intern.h"
22#include "internal/class.h"
23#include "internal/cont.h"
24#include "internal/error.h"
25#include "internal/eval.h"
26#include "internal/gc.h"
27#include "internal/hash.h"
28#include "internal/inits.h"
29#include "internal/io.h"
30#include "internal/object.h"
31#include "internal/thread.h"
32#include "internal/variable.h"
37#include "probes_helper.h"
40#include "ractor_core.h"
42NORETURN(
static void rb_raise_jump(
VALUE,
VALUE));
52ID ruby_static_id_signo, ruby_static_id_status;
53extern ID ruby_static_id_cause;
54#define id_cause ruby_static_id_cause
56#define exception_error GET_VM()->special_exceptions[ruby_error_reenter]
58#include "eval_error.c"
61#define CLASS_OR_MODULE_P(obj) \
62 (!SPECIAL_CONST_P(obj) && \
63 (BUILTIN_TYPE(obj) == T_CLASS || BUILTIN_TYPE(obj) == T_MODULE))
68 enum ruby_tag_type state;
79#if defined(__linux__) && defined(PR_SET_THP_DISABLE)
80 prctl(PR_SET_THP_DISABLE, 1, 0, 0, 0);
84 rb_vm_encoded_insn_data_table_init();
87 EC_PUSH_TAG(GET_EC());
88 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
91 GET_VM()->running = 1;
105 rb_ec_error_print(ec, ec->errinfo);
112ruby_options(
int argc,
char **argv)
115 enum ruby_tag_type state;
116 void *
volatile iseq = 0;
120 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
124 rb_ec_clear_current_thread_trace_func(ec);
125 int exitcode = error_handle(ec, ec->errinfo, state);
127 iseq = (
void *)
INT2FIX(exitcode);
136 enum ruby_tag_type state;
139 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
143 state = error_handle(ec, ec->errinfo, state);
152 rb_ec_fiber_scheduler_finalize(ec);
155 if (EC_EXEC_TAG() == TAG_NONE) {
156 rb_vm_trap_exit(rb_ec_vm_ptr(ec));
159 rb_ec_exec_end_proc(ec);
160 rb_ec_clear_all_trace_func(ec);
168 rb_objspace_call_finalizer(rb_ec_vm_ptr(ec)->objspace);
182 return rb_ec_cleanup(GET_EC(), (
enum ruby_tag_type)ex);
190 volatile int sysex = EXIT_SUCCESS;
191 volatile int signaled = 0;
194 volatile int step = 0;
198 rb_threadptr_interrupt(th);
199 rb_threadptr_check_signal(th);
202 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
203 SAVE_ROOT_JMPBUF(th, { RUBY_VM_CHECK_INTS(ec); });
206 save_error = ec->errinfo;
207 if (THROW_DATA_P(ec->errinfo)) ec->errinfo =
Qnil;
212 SAVE_ROOT_JMPBUF(th, rb_ec_teardown(ec));
215 VALUE err = ec->errinfo;
216 volatile int mode0 = 0, mode1 = 0;
217 if (err != save_error && !
NIL_P(err)) {
218 mode0 = exiting_split(err, &sysex, &signaled);
224 err = ATOMIC_VALUE_EXCHANGE(save_error,
Qnil);
226 if (!
NIL_P(err) && !THROW_DATA_P(err)) {
227 mode1 = exiting_split(err, (mode0 & EXITING_WITH_STATUS) ? NULL : &sysex, &signaled);
228 if (mode1 & EXITING_WITH_MESSAGE) {
230 SAVE_ROOT_JMPBUF(th, rb_ec_error_print_detailed(ec, err, buf,
Qundef));
237 th->status = THREAD_KILLED;
239 SAVE_ROOT_JMPBUF(th, rb_ractor_terminate_all());
242 if (!
NIL_P(buf = message)) {
245 else if (!NIL_OR_UNDEF_P(err = save_error) ||
246 (ex != TAG_NONE && !((mode0|mode1) & EXITING_WITH_STATUS))) {
247 sysex = error_handle(ec, err, ex);
263 rb_threadptr_unlock_all_locking_mutexes(th);
267 rb_thread_stop_timer_thread();
270 rb_jit_cont_finish();
285 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
287 SAVE_ROOT_JMPBUF(th, {
288 rb_iseq_eval_main(iseq);
308 case Qtrue: s = EXIT_SUCCESS;
break;
309 case Qfalse: s = EXIT_FAILURE;
break;
314 if (status) *status = s;
319ruby_run_node(
void *n)
324 rb_ec_cleanup(ec, (
NIL_P(ec->errinfo) ? TAG_NONE : TAG_RAISE));
328 return rb_ec_cleanup(ec, rb_ec_exec_node(ec, n));
335 return rb_ec_exec_node(GET_EC(), n);
356 VALUE ary = rb_ary_new();
359 while (cref && CREF_NEXT(cref)) {
360 VALUE klass = CREF_CLASS(cref);
361 if (!CREF_PUSHED_BY_EVAL(cref) &&
363 rb_ary_push(ary, klass);
365 cref = CREF_NEXT(cref);
393rb_mod_s_constants(
int argc,
VALUE *argv,
VALUE mod)
405 klass = CREF_CLASS(cref);
406 if (!CREF_PUSHED_BY_EVAL(cref) &&
413 cref = CREF_NEXT(cref);
435 rb_module_set_initialized(klass);
442 klass = RCLASS_ATTACHED_OBJECT(klass);
476static VALUE get_errinfo(
void);
477#define get_ec_errinfo(ec) rb_ec_get_errinfo(ec)
485 CONST_ID(id_true_cause,
"true_cause");
487 cause = rb_attr_get(
rb_eFatal, id_true_cause);
496 if (!
NIL_P(cause) && cause != exc) {
513 if (INTERNAL_EXCEPTION_P(mesg)) EC_JUMP_TAG(ec, TAG_FATAL);
521 if (UNDEF_P(*cause)) {
527 *cause = get_ec_errinfo(ec);
537 if (!nocircular && !
NIL_P(*cause) && !UNDEF_P(*cause) && *cause != mesg) {
539 rb_exc_check_circular_cause(*cause);
542 while (!
NIL_P(c = rb_attr_get(c, id_cause))) {
544 rb_raise(rb_eArgError,
"circular causes");
557 const char *file = rb_source_location_cstr(&line);
558 const char *
const volatile file0 = file;
560 if ((file && !
NIL_P(mesg)) || !UNDEF_P(cause)) {
561 volatile int state = 0;
564 if (EC_EXEC_TAG() == TAG_NONE && !(state = rb_ec_set_raised(ec))) {
565 VALUE bt = rb_get_backtrace(mesg);
566 if (!
NIL_P(bt) || UNDEF_P(cause)) {
571 if (!UNDEF_P(cause) && !THROW_DATA_P(cause)) {
572 exc_setup_cause(mesg, cause);
575 VALUE at = rb_ec_backtrace_object(ec);
577 set_backtrace(mesg, at);
579 rb_ec_reset_raised(ec);
583 if (state)
goto fatal;
592 enum ruby_tag_type state;
596 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
598 e = rb_obj_as_string(mesg);
601 e = rb_sprintf(
"Exception `%"PRIsVALUE
"' at %s:%d - %"PRIsVALUE
"\n",
605 e = rb_sprintf(
"Exception `%"PRIsVALUE
"' at %s - %"PRIsVALUE
"\n",
609 e = rb_sprintf(
"Exception `%"PRIsVALUE
"' - %"PRIsVALUE
"\n",
615 if (state == TAG_FATAL && ec->errinfo == exception_error) {
619 rb_ec_reset_raised(ec);
620 EC_JUMP_TAG(ec, state);
624 if (rb_ec_set_raised(ec)) {
628 if (tag != TAG_FATAL) {
635 ec->errinfo = exception_error;
636 rb_ec_reset_raised(ec);
637 EC_JUMP_TAG(ec, TAG_FATAL);
644 if (UNDEF_P(cause)) {
645 cause = get_ec_errinfo(ec);
648 if (THROW_DATA_P(cause)) {
659 mesg = exc_setup_message(ec, mesg, &cause);
660 setup_exception(ec, tag, mesg, cause);
661 rb_ec_raised_clear(ec);
662 EC_JUMP_TAG(ec, tag);
665static VALUE make_exception(
int argc,
const VALUE *argv,
int isstr);
667NORETURN(
static void rb_exc_exception(
VALUE mesg,
int tag,
VALUE cause));
670rb_exc_exception(
VALUE mesg,
int tag,
VALUE cause)
673 mesg = make_exception(1, &mesg, FALSE);
675 rb_longjmp(GET_EC(), tag, mesg, cause);
688 rb_exc_exception(mesg, TAG_RAISE,
Qundef);
701 rb_exc_exception(mesg, TAG_FATAL,
Qnil);
710enum {raise_opt_cause, raise_max_opt};
713extract_raise_opts(
int argc,
VALUE *argv,
VALUE *opts)
729 for (i = 0; i < raise_max_opt; ++i) {
736rb_f_raise(
int argc,
VALUE *argv)
739 VALUE opts[raise_max_opt], *
const cause = &opts[raise_opt_cause];
741 argc = extract_raise_opts(argc, argv, opts);
743 if (!UNDEF_P(*cause)) {
744 rb_raise(rb_eArgError,
"only cause is given with no arguments");
752 rb_raise_jump(rb_make_exception(argc, argv), *cause);
789 return rb_f_raise(c, v);
793make_exception(
int argc,
const VALUE *argv,
int isstr)
803 if (isstr &&!
NIL_P(exc)) {
814 rb_error_arity(argc, 0, 3);
826 set_backtrace(mesg, argv[2]);
833rb_make_exception(
int argc,
const VALUE *argv)
835 return make_exception(argc, argv, TRUE);
846 VALUE klass = me->owner;
847 VALUE self = cfp->self;
848 ID mid = me->called_id;
853 rb_longjmp(ec, TAG_RAISE, mesg, cause);
859 if (UNLIKELY(tag < TAG_RETURN || tag > TAG_FATAL)) {
860 unknown_longjmp_status(tag);
862 EC_JUMP_TAG(GET_EC(), tag);
868 if (rb_vm_frame_block_handler(GET_EC()->cfp) == VM_BLOCK_HANDLER_NONE) {
881 return rb_vm_cframe_keyword_p(GET_EC()->cfp);
890 rb_vm_localjump_error(
"no block given",
Qnil, 0);
910 enum ruby_tag_type state;
914 volatile VALUE e_info = ec->errinfo;
917 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
919 result = (*b_proc) (data1);
923 if (state == TAG_RETRY) {
931 rb_vm_rewind_cfp(ec, cfp);
933 if (state == TAG_RAISE) {
941 while ((eclass = va_arg(ap,
VALUE)) != 0) {
952 result = (*r_proc) (data2, ec->errinfo);
954 ec->errinfo = e_info;
960 EC_JUMP_TAG(ec, state);
977 volatile enum ruby_tag_type state;
982 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
983 SAVE_ROOT_JMPBUF(rb_ec_thread_ptr(ec), result = (*proc) (data));
986 rb_vm_rewind_cfp(ec, cfp);
990 if (pstate != NULL) *pstate = state;
1002 ensure_list.entry.marker = 0;
1003 ensure_list.entry.e_proc = e_proc;
1004 ensure_list.entry.data2 = data2;
1005 ensure_list.next = ec->ensure_list;
1006 ec->ensure_list = &ensure_list;
1008 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
1009 result = (*b_proc) (data1);
1012 errinfo = ec->errinfo;
1016 ec->ensure_list=ensure_list.next;
1017 (*ensure_list.entry.e_proc)(ensure_list.entry.data2);
1018 ec->errinfo = errinfo;
1020 EC_JUMP_TAG(ec, state);
1030 return me->def->original_id;
1043 return me->called_id;
1051rb_frame_this_func(
void)
1053 return frame_func_id(GET_EC()->cfp);
1057rb_frame_callee(
void)
1059 return frame_called_id(GET_EC()->cfp);
1067 if ((
void *)(ec->vm_stack + ec->vm_stack_size) == (
void *)(prev_cfp)) {
1074prev_frame_callee(
void)
1077 if (!prev_cfp)
return 0;
1078 return frame_called_id(prev_cfp);
1082prev_frame_func(
void)
1085 if (!prev_cfp)
return 0;
1086 return frame_func_id(prev_cfp);
1096rb_frame_last_func(
void)
1102 while (!(mid = frame_func_id(cfp)) &&
1103 (cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp),
1104 !RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(ec, cfp)));
1121rb_mod_append_features(
VALUE module,
VALUE include)
1123 if (!CLASS_OR_MODULE_P(include)) {
1139rb_mod_include(
int argc,
VALUE *argv,
VALUE module)
1142 ID id_append_features, id_included;
1144 CONST_ID(id_append_features,
"append_features");
1148 rb_raise(
rb_eTypeError,
"Refinement#include has been removed");
1152 for (i = 0; i < argc; i++) {
1154 if (
FL_TEST(argv[i], RMODULE_IS_REFINEMENT)) {
1159 rb_funcall(argv[argc], id_append_features, 1, module);
1160 rb_funcall(argv[argc], id_included, 1, module);
1178rb_mod_prepend_features(
VALUE module,
VALUE prepend)
1180 if (!CLASS_OR_MODULE_P(prepend)) {
1196rb_mod_prepend(
int argc,
VALUE *argv,
VALUE module)
1199 ID id_prepend_features, id_prepended;
1202 rb_raise(
rb_eTypeError,
"Refinement#prepend has been removed");
1205 CONST_ID(id_prepend_features,
"prepend_features");
1206 CONST_ID(id_prepended,
"prepended");
1209 for (i = 0; i < argc; i++) {
1211 if (
FL_TEST(argv[i], RMODULE_IS_REFINEMENT)) {
1216 rb_funcall(argv[argc], id_prepend_features, 1, module);
1217 rb_funcall(argv[argc], id_prepended, 1, module);
1223ensure_class_or_module(
VALUE obj)
1227 "wrong argument type %"PRIsVALUE
" (expected Class or Module)",
1233hidden_identity_hash_new(
void)
1235 VALUE hash = rb_ident_hash_new();
1237 RBASIC_CLEAR_CLASS(hash);
1242refinement_superclass(
VALUE superclass)
1244 if (RB_TYPE_P(superclass,
T_MODULE)) {
1246 return rb_include_class_new(RCLASS_ORIGIN(superclass),
rb_cBasicObject);
1259 VALUE iclass, c, superclass = klass;
1261 ensure_class_or_module(klass);
1263 if (
NIL_P(CREF_REFINEMENTS(cref))) {
1264 CREF_REFINEMENTS_SET(cref, hidden_identity_hash_new());
1267 if (CREF_OMOD_SHARED(cref)) {
1268 CREF_REFINEMENTS_SET(cref, rb_hash_dup(CREF_REFINEMENTS(cref)));
1269 CREF_OMOD_SHARED_UNSET(cref);
1271 if (!
NIL_P(c = rb_hash_lookup(CREF_REFINEMENTS(cref), klass))) {
1273 while (c && RB_TYPE_P(c,
T_ICLASS)) {
1274 if (
RBASIC(c)->klass == module) {
1282 superclass = refinement_superclass(superclass);
1283 c = iclass = rb_include_class_new(module, superclass);
1286 RCLASS_M_TBL(c) = RCLASS_M_TBL(module);
1288 module = RCLASS_SUPER(module);
1289 while (module && module != klass) {
1290 c = RCLASS_SET_SUPER(c, rb_include_class_new(module,
RCLASS_SUPER(c)));
1292 module = RCLASS_SUPER(module);
1294 rb_hash_aset(CREF_REFINEMENTS(cref), klass, iclass);
1302 rb_using_refinement(cref, klass, module);
1310 VALUE super, module, refinements;
1314 using_module_recursive(cref, super);
1322 module = RBASIC(klass)->klass;
1326 rb_raise(
rb_eTypeError,
"wrong argument type %s (expected Module)",
1330 CONST_ID(id_refinements,
"__refinements__");
1331 refinements = rb_attr_get(module, id_refinements);
1332 if (
NIL_P(refinements))
return;
1343 using_module_recursive(cref, module);
1344 rb_clear_all_refinement_method_cache();
1361rb_refinement_module_get_refined_class(
VALUE module)
1363 ID id_refined_class;
1365 CONST_ID(id_refined_class,
"__refined_class__");
1366 return rb_attr_get(module, id_refined_class);
1378rb_refinement_refined_class(
VALUE module)
1380 rb_warn_deprecated_to_remove(
"3.4",
"Refinement#refined_class",
"Refinement#target");
1381 return rb_refinement_module_get_refined_class(module);
1385add_activated_refinement(
VALUE activated_refinements,
1388 VALUE iclass, c, superclass = klass;
1390 if (!
NIL_P(c = rb_hash_lookup(activated_refinements, klass))) {
1392 while (c && RB_TYPE_P(c,
T_ICLASS)) {
1393 if (
RBASIC(c)->klass == refinement) {
1400 superclass = refinement_superclass(superclass);
1401 c = iclass = rb_include_class_new(refinement, superclass);
1404 while (refinement && refinement != klass) {
1405 c = RCLASS_SET_SUPER(c, rb_include_class_new(refinement,
RCLASS_SUPER(c)));
1409 rb_hash_aset(activated_refinements, klass, iclass);
1425 ID id_refinements, id_activated_refinements,
1426 id_refined_class, id_defined_at;
1427 VALUE refinements, activated_refinements;
1429 VALUE block_handler = rb_vm_frame_block_handler(th->ec->cfp);
1431 if (block_handler == VM_BLOCK_HANDLER_NONE) {
1432 rb_raise(rb_eArgError,
"no block given");
1434 if (vm_block_handler_type(block_handler) != block_handler_type_iseq) {
1435 rb_raise(rb_eArgError,
"can't pass a Proc as a block to Module#refine");
1438 ensure_class_or_module(klass);
1439 CONST_ID(id_refinements,
"__refinements__");
1440 refinements = rb_attr_get(module, id_refinements);
1441 if (
NIL_P(refinements)) {
1442 refinements = hidden_identity_hash_new();
1445 CONST_ID(id_activated_refinements,
"__activated_refinements__");
1446 activated_refinements = rb_attr_get(module, id_activated_refinements);
1447 if (
NIL_P(activated_refinements)) {
1448 activated_refinements = hidden_identity_hash_new();
1450 activated_refinements);
1452 refinement = rb_hash_lookup(refinements, klass);
1453 if (
NIL_P(refinement)) {
1454 VALUE superclass = refinement_superclass(klass);
1456 RCLASS_SET_SUPER(refinement, superclass);
1458 FL_SET(refinement, RMODULE_IS_REFINEMENT);
1459 CONST_ID(id_refined_class,
"__refined_class__");
1461 CONST_ID(id_defined_at,
"__defined_at__");
1463 rb_hash_aset(refinements, klass, refinement);
1464 add_activated_refinement(activated_refinements, klass, refinement);
1466 rb_yield_refine_block(refinement, activated_refinements);
1471ignored_block(
VALUE module,
const char *klass)
1473 const char *anon =
"";
1475 if (!
RTEST(rb_search_class_path(module))) {
1476 anon =
", maybe for Module.new";
1478 rb_warn(
"%s""using doesn't call the given block""%s.", klass, anon);
1494 if (prev_frame_func()) {
1496 "Module#using is not permitted in methods");
1498 if (prev_cfp && prev_cfp->self != self) {
1502 ignored_block(module,
"Module#");
1504 rb_using_module(rb_vm_cref_replace_with_duplicated_cref(), module);
1530mod_refinements(
VALUE self)
1535 CONST_ID(id_refinements,
"__refinements__");
1536 refinements = rb_attr_get(self, id_refinements);
1537 if (
NIL_P(refinements)) {
1538 return rb_ary_new();
1540 return rb_hash_values(refinements);
1547 CONST_ID(id_defined_at,
"__defined_at__");
1549 rb_ary_push(ary, rb_attr_get(
rb_class_of(mod), id_defined_at));
1581rb_mod_s_used_modules(
VALUE _)
1584 VALUE ary = rb_ary_new();
1587 if (!
NIL_P(CREF_REFINEMENTS(cref))) {
1590 cref = CREF_NEXT(cref);
1593 return rb_funcall(ary, rb_intern(
"uniq"), 0);
1632rb_mod_s_used_refinements(
VALUE _)
1635 VALUE ary = rb_ary_new();
1638 if (!
NIL_P(CREF_REFINEMENTS(cref))) {
1641 cref = CREF_NEXT(cref);
1656static enum rb_id_table_iterator_result
1657refinement_import_methods_i(
ID key,
VALUE value,
void *data)
1662 if (me->def->type != VM_METHOD_TYPE_ISEQ) {
1663 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));
1665 rb_cref_t *new_cref = rb_vm_cref_dup_without_refinements(me->def->body.iseq.
cref);
1666 CREF_REFINEMENTS_SET(new_cref, CREF_REFINEMENTS(arg->cref));
1667 rb_add_method_iseq(arg->refinement, key, me->def->body.iseq.
iseqptr, new_cref, METHOD_ENTRY_VISI(me));
1668 return ID_TABLE_CONTINUE;
1676refinement_import_methods(
int argc,
VALUE *argv,
VALUE refinement)
1682 for (i = 0; i < argc; i++) {
1685 rb_warn(
"%"PRIsVALUE
" has ancestors, but Refinement#import_methods doesn't import their methods",
rb_class_path(argv[i]));
1688 arg.cref = rb_vm_cref_replace_with_duplicated_cref();
1689 arg.refinement = refinement;
1690 for (i = 0; i < argc; i++) {
1691 arg.module = argv[i];
1692 struct rb_id_table *m_tbl = RCLASS_M_TBL(argv[i]);
1693 if (!m_tbl)
continue;
1694 rb_id_table_foreach(m_tbl, refinement_import_methods_i, &arg);
1706rb_obj_call_init_kw(
VALUE obj,
int argc,
const VALUE *argv,
int kw_splat)
1708 PASS_PASSED_BLOCK_HANDLER();
1778rb_obj_extend(
int argc,
VALUE *argv,
VALUE obj)
1781 ID id_extend_object, id_extended;
1783 CONST_ID(id_extend_object,
"extend_object");
1787 for (i = 0; i < argc; i++) {
1789 if (
FL_TEST(argv[i], RMODULE_IS_REFINEMENT)) {
1790 rb_raise(
rb_eTypeError,
"Cannot extend object with refinement");
1794 rb_funcall(argv[argc], id_extend_object, 1, obj);
1801rb_top_main_class(
const char *method)
1803 VALUE klass = GET_THREAD()->top_wrapper;
1805 if (!klass)
return rb_cObject;
1806 rb_warning(
"main.%s in the wrapped load is effective only in wrapper module", method);
1820top_include(
int argc,
VALUE *argv,
VALUE self)
1822 return rb_mod_include(argc, argv, rb_top_main_class(
"include"));
1836 const rb_cref_t *cref = CREF_NEXT(rb_vm_cref());;
1840 if ((th->top_wrapper ? CREF_NEXT(cref) : cref) ||
1841 (prev_cfp && rb_vm_frame_method_entry(prev_cfp))) {
1845 ignored_block(module,
"main.");
1847 rb_using_module(rb_vm_cref_replace_with_duplicated_cref(), module);
1857 while (RUBY_VM_VALID_CONTROL_FRAME_P(cfp, end_cfp)) {
1858 if (VM_FRAME_RUBYFRAME_P(cfp)) {
1859 if (ISEQ_BODY(cfp->iseq)->type == ISEQ_TYPE_RESCUE) {
1860 return &cfp->ep[VM_ENV_INDEX_LAST_LVAR];
1862 else if (ISEQ_BODY(cfp->iseq)->type == ISEQ_TYPE_ENSURE &&
1863 !THROW_DATA_P(cfp->ep[VM_ENV_INDEX_LAST_LVAR]) &&
1864 !
FIXNUM_P(cfp->ep[VM_ENV_INDEX_LAST_LVAR])) {
1865 return &cfp->ep[VM_ENV_INDEX_LAST_LVAR];
1868 cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
1876 const VALUE *ptr = errinfo_place(ec);
1888 return get_ec_errinfo(GET_EC());
1894 return get_errinfo();
1900 return GET_EC()->errinfo;
1909 GET_EC()->errinfo = err;
1915 VALUE err = get_errinfo();
1917 return rb_get_backtrace(err);
1927 VALUE err = get_errinfo();
1929 rb_raise(rb_eArgError,
"$! not set");
1931 set_backtrace(err, val);
1947 ID fname = prev_frame_func();
1969 ID fname = prev_frame_callee();
1990f_current_dirname(
VALUE _)
1992 VALUE base = rb_current_realfilepath();
1996 base = rb_file_dirname(base);
2013f_global_variables(
VALUE _)
2067 rb_define_virtual_variable("$!", errinfo_getter, 0);
2069 rb_gvar_ractor_local(
"$@");
2070 rb_gvar_ractor_local("$!");
2091 rb_mod_s_used_modules, 0);
2093 rb_mod_s_used_refinements, 0);
2111 "include", top_include, -1);
2113 "using", top_using, 1);
2120 rb_vm_register_special_exception(ruby_error_reenter,
rb_eFatal,
"exception reentered");
2121 rb_vm_register_special_exception(ruby_error_stackfatal,
rb_eFatal,
"machine stack overflow in critical region");
#define RUBY_ASSERT(expr)
Asserts that the given expression is truthy if and only if RUBY_DEBUG is truthy.
#define rb_define_method(klass, mid, func, arity)
Defines klass#mid.
#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 rb_define_global_function(mid, func, arity)
Defines rb_mKernel #mid.
#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.
VALUE rb_refinement_new(void)
Creates a new, anonymous refinement.
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,...
VALUE rb_singleton_class(VALUE obj)
Finds or creates the singleton class of the passed object.
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.
void rb_undef_method(VALUE klass, const char *name)
Defines an undef of a method.
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Retrieves argument from argc and argv to given VALUE references according to the format string.
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.
#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 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 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.
VALUE rb_rescue2(VALUE(*b_proc)(VALUE), VALUE data1, VALUE(*r_proc)(VALUE, VALUE), VALUE data2,...)
An equivalent of rescue clause.
VALUE rb_eSystemExit
SystemExit exception.
VALUE rb_eStandardError
StandardError exception.
VALUE rb_eTypeError
TypeError exception.
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_frozen_error_raise(VALUE frozen_obj, const char *fmt,...)
Raises an instance of rb_eFrozenError.
VALUE rb_eFatal
fatal exception.
VALUE rb_eInterrupt
Interrupt exception.
void rb_exc_fatal(VALUE mesg)
Raises a fatal error in the current thread.
VALUE rb_eRuntimeError
RuntimeError exception.
void rb_warn(const char *fmt,...)
Identical to rb_warning(), except it reports unless $VERBOSE is nil.
VALUE rb_exc_new(VALUE etype, const char *ptr, long len)
Creates an instance of the passed exception class.
VALUE rb_eException
Mother of all exceptions.
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.
VALUE rb_cClass
Class class.
VALUE rb_mKernel
Kernel module.
VALUE rb_cRefinement
Refinement class.
static VALUE rb_class_of(VALUE obj)
Object to class mapping function.
VALUE rb_obj_class(VALUE obj)
Queries the class of an object.
VALUE rb_obj_dup(VALUE obj)
Duplicates the given object.
VALUE rb_cBasicObject
BasicObject class.
VALUE rb_cModule
Module class.
VALUE rb_obj_is_kind_of(VALUE obj, VALUE klass)
Queries if the given object is an instance (of possibly descendants) of the given class.
#define RB_OBJ_WRITE(old, slot, young)
Declaration of a "back" pointer.
void ruby_init(void)
Calls ruby_setup() and check error.
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.
#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.
void ruby_default_signal(int sig)
Pretends as if there was no custom signal handler.
#define rb_str_new(str, len)
Allocates an instance of rb_cString.
#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_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_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.
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().
int ruby_vm_destruct(ruby_vm_t *vm)
Destructs the passed VM.
void rb_hash_foreach(VALUE q, int_type *w, VALUE e)
Iteration over the given hash.
void rb_define_virtual_variable(const char *q, type *w, void_type *e)
Define a function-backended global variable.
#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.
static int * rb_orig_errno_ptr(void)
Not sure if it is necessary for extension libraries but this is where the "bare" errno is located.
#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.
rb_cref_t * cref
class reference, should be marked
const rb_iseq_t * iseqptr
iseq pointer, should be separated from iseqval
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
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.