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/jit.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"
33#include "internal/vm.h"
37#include "probes_helper.h"
40#include "ractor_core.h"
43NORETURN(
static void rb_raise_jump(
VALUE,
VALUE));
53ID ruby_static_id_signo, ruby_static_id_status;
54extern ID ruby_static_id_cause;
55#define id_cause ruby_static_id_cause
57#define exception_error GET_VM()->special_exceptions[ruby_error_reenter]
59#include "eval_error.c"
62#define CLASS_OR_MODULE_P(obj) \
63 (!SPECIAL_CONST_P(obj) && \
64 (BUILTIN_TYPE(obj) == T_CLASS || BUILTIN_TYPE(obj) == T_MODULE))
69 enum ruby_tag_type state;
78#if defined(__linux__) && defined(PR_SET_THP_DISABLE)
79 prctl(PR_SET_THP_DISABLE, 1, 0, 0, 0);
82 rb_w32_init_long_paths();
85 rb_vm_encoded_insn_data_table_init();
91 EC_PUSH_TAG(GET_EC());
92 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
95 GET_VM()->running = 1;
109 rb_ec_error_print(ec, ec->errinfo);
116ruby_options(
int argc,
char **argv)
119 enum ruby_tag_type state;
120 void *
volatile iseq = 0;
123 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
127 rb_ec_clear_current_thread_trace_func(ec);
128 int exitcode = error_handle(ec, ec->errinfo, state);
130 iseq = (
void *)
INT2FIX(exitcode);
139 enum ruby_tag_type state;
142 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
146 state = error_handle(ec, ec->errinfo, state);
154 enum ruby_tag_type state = TAG_NONE;
158 rb_ec_fiber_scheduler_finalize(ec);
161 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
162 rb_vm_trap_exit(rb_ec_vm_ptr(ec));
165 trap_errinfo = ec->errinfo;
169 rb_ec_exec_end_proc(ec);
170 if (!
NIL_P(trap_errinfo)) {
171 error_handle(ec, trap_errinfo, state);
172 ec->errinfo = trap_errinfo;
174 rb_ec_clear_all_trace_func(ec);
182 rb_objspace_call_finalizer();
196 return rb_ec_cleanup(GET_EC(), (
enum ruby_tag_type)ex);
204 volatile int sysex = EXIT_SUCCESS;
205 volatile int signaled = 0;
208 volatile int step = 0;
212 rb_threadptr_interrupt(th);
213 rb_threadptr_check_signal(th);
216 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
217 RUBY_VM_CHECK_INTS(ec);
220 save_error = ec->errinfo;
221 if (THROW_DATA_P(ec->errinfo)) ec->errinfo =
Qnil;
228 VALUE err = ec->errinfo;
229 volatile int mode0 = 0, mode1 = 0;
230 if (err != save_error && !
NIL_P(err)) {
231 mode0 = exiting_split(err, &sysex, &signaled);
237 err = ATOMIC_VALUE_EXCHANGE(save_error,
Qnil);
239 if (!
NIL_P(err) && !THROW_DATA_P(err)) {
240 mode1 = exiting_split(err, (mode0 & EXITING_WITH_STATUS) ? NULL : &sysex, &signaled);
241 if (mode1 & EXITING_WITH_MESSAGE) {
243 rb_ec_error_print_detailed(ec, err, buf,
Qundef);
250 th->status = THREAD_KILLED;
252 rb_ractor_terminate_all();
255 if (!
NIL_P(buf = message)) {
258 else if (!NIL_OR_UNDEF_P(err = save_error) ||
259 (ex != TAG_NONE && !((mode0|mode1) & EXITING_WITH_STATUS))) {
260 sysex = error_handle(ec, err, ex);
276 rb_threadptr_unlock_all_locking_mutexes(th);
280 rb_thread_stop_timer_thread();
283 rb_jit_cont_finish();
298 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
299 rb_iseq_eval_main(iseq);
318 case Qtrue: s = EXIT_SUCCESS;
break;
319 case Qfalse: s = EXIT_FAILURE;
break;
324 if (status) *status = s;
329ruby_run_node(
void *n)
334 rb_ec_cleanup(ec, (
NIL_P(ec->errinfo) ? TAG_NONE : TAG_RAISE));
337 return rb_ec_cleanup(ec, rb_ec_exec_node(ec, n));
343 return rb_ec_exec_node(GET_EC(), n);
374 while (cref && CREF_NEXT(cref)) {
375 VALUE klass = CREF_CLASS(cref);
376 if (!CREF_PUSHED_BY_EVAL(cref) &&
380 cref = CREF_NEXT(cref);
408rb_mod_s_constants(
int argc,
VALUE *argv,
VALUE mod)
420 klass = CREF_CLASS(cref);
421 if (!CREF_PUSHED_BY_EVAL(cref) &&
428 cref = CREF_NEXT(cref);
451 rb_class_set_initialized(klass);
454 if (RCLASS_SINGLETON_P(klass)) {
455 klass = RCLASS_ATTACHED_OBJECT(klass);
459 rb_class_owner_check(klass);
463static VALUE get_errinfo(
void);
464#define get_ec_errinfo(ec) rb_ec_get_errinfo(ec)
472 CONST_ID(id_true_cause,
"true_cause");
474 cause = rb_attr_get(
rb_eFatal, id_true_cause);
483 if (!
NIL_P(cause) && cause != exc) {
500 if (INTERNAL_EXCEPTION_P(mesg)) EC_JUMP_TAG(ec, TAG_FATAL);
508 if (UNDEF_P(*cause)) {
514 *cause = get_ec_errinfo(ec);
524 if (!nocircular && !
NIL_P(*cause) && !UNDEF_P(*cause) && *cause != mesg) {
526 rb_exc_check_circular_cause(*cause);
531 rb_raise(rb_eArgError,
"circular causes");
533 if (THROW_DATA_P(c)) {
536 c = rb_attr_get(c, id_cause);
548 const char *file = rb_source_location_cstr(&line);
549 const char *
const volatile file0 = file;
551 if ((file && !
NIL_P(mesg)) || !UNDEF_P(cause)) {
552 volatile int state = 0;
555 if (EC_EXEC_TAG() == TAG_NONE && !(state = rb_ec_set_raised(ec))) {
556 VALUE bt = rb_get_backtrace(mesg);
557 if (!
NIL_P(bt) || UNDEF_P(cause)) {
562 if (!UNDEF_P(cause) && !THROW_DATA_P(cause)) {
563 exc_setup_cause(mesg, cause);
566 VALUE at = rb_ec_backtrace_object(ec);
568 set_backtrace(mesg, at);
570 rb_ec_reset_raised(ec);
574 if (state)
goto fatal;
583 enum ruby_tag_type state;
587 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
592 e = rb_sprintf(
"Exception '%"PRIsVALUE
"' at %s:%d - %"PRIsVALUE
"\n",
596 e = rb_sprintf(
"Exception '%"PRIsVALUE
"' at %s - %"PRIsVALUE
"\n",
600 e = rb_sprintf(
"Exception '%"PRIsVALUE
"' - %"PRIsVALUE
"\n",
606 if (state == TAG_FATAL && ec->errinfo == exception_error) {
610 rb_ec_reset_raised(ec);
611 EC_JUMP_TAG(ec, state);
615 if (rb_ec_set_raised(ec)) {
619 if (tag != TAG_FATAL) {
626 ec->errinfo = exception_error;
627 rb_ec_reset_raised(ec);
628 EC_JUMP_TAG(ec, TAG_FATAL);
635 if (UNDEF_P(cause)) {
636 cause = get_ec_errinfo(ec);
639 if (THROW_DATA_P(cause)) {
650 mesg = exc_setup_message(ec, mesg, &cause);
651 setup_exception(ec, tag, mesg, cause);
652 rb_ec_raised_clear(ec);
653 EC_JUMP_TAG(ec, tag);
656static VALUE make_exception(
int argc,
const VALUE *argv,
int isstr);
658NORETURN(
static void rb_exc_exception(
VALUE mesg,
enum ruby_tag_type tag,
VALUE cause));
661rb_exc_exception(
VALUE mesg,
enum ruby_tag_type tag,
VALUE cause)
664 mesg = make_exception(1, &mesg, FALSE);
666 rb_longjmp(GET_EC(), tag, mesg, cause);
679 rb_exc_exception(mesg, TAG_RAISE,
Qundef);
692 rb_exc_exception(mesg, TAG_FATAL,
Qnil);
702extract_raise_options(
int argc,
VALUE *argv,
VALUE *cause)
705 static ID keywords[1] = {0};
714 if (!
NIL_P(options)) {
737rb_exception_setup(
int argc,
VALUE *argv)
743 argc = extract_raise_options(argc, argv, &cause);
746 if (argc == 0 && !UNDEF_P(cause)) {
747 rb_raise(rb_eArgError,
"only cause is given with no arguments");
756 exception = rb_make_exception(argc, argv);
762 if (UNDEF_P(cause)) {
764 resolved_cause = rb_ec_get_errinfo(ec);
767 if (resolved_cause == exception) {
768 resolved_cause =
Qnil;
771 else if (
NIL_P(cause)) {
773 resolved_cause =
Qnil;
781 if (cause == exception) {
783 resolved_cause =
Qnil;
787 VALUE current_cause = cause;
788 while (!
NIL_P(current_cause)) {
790 if (current_cause == exception) {
791 rb_raise(rb_eArgError,
"circular causes");
793 if (THROW_DATA_P(current_cause)) {
796 current_cause = rb_attr_get(current_cause, id_cause);
798 resolved_cause = cause;
803 if (!UNDEF_P(resolved_cause)) {
814rb_f_raise(
int argc,
VALUE *argv)
817 argc = extract_raise_options(argc, argv, &cause);
824 if (!UNDEF_P(cause)) {
825 rb_raise(rb_eArgError,
"only cause is given with no arguments");
829 exception = get_errinfo();
830 if (!
NIL_P(exception)) {
836 rb_raise_jump(rb_make_exception(argc, argv), cause);
957 return rb_f_raise(c, v);
961make_exception(
int argc,
const VALUE *argv,
int isstr)
971 if (isstr &&!
NIL_P(exc)) {
982 rb_error_arity(argc, 0, 3);
994 set_backtrace(mesg, argv[2]);
1001rb_make_exception(
int argc,
const VALUE *argv)
1003 return make_exception(argc, argv, TRUE);
1014 VALUE klass = me->owner;
1015 VALUE self = cfp->self;
1016 ID mid = me->called_id;
1018 rb_vm_pop_frame(ec);
1021 rb_longjmp(ec, TAG_RAISE, mesg, cause);
1027 if (UNLIKELY(tag < TAG_RETURN || tag > TAG_FATAL)) {
1028 unknown_longjmp_status(tag);
1030 EC_JUMP_TAG(GET_EC(), tag);
1036 if (rb_vm_frame_block_handler(GET_EC()->cfp) == VM_BLOCK_HANDLER_NONE) {
1049 return rb_vm_cframe_keyword_p(GET_EC()->cfp);
1058 rb_vm_localjump_error(
"no block given",
Qnil, 0);
1067 va_start(ap, data2);
1078 enum ruby_tag_type state;
1082 volatile VALUE data2 = data2_arg;
1084 volatile VALUE e_info = ec->errinfo;
1087 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
1089 result = (*b_proc) (data1);
1093 if (state == TAG_RETRY) {
1101 rb_vm_rewind_cfp(ec, cfp);
1103 if (state == TAG_RAISE) {
1111 while ((eclass = va_arg(ap,
VALUE)) != 0) {
1122 result = (*r_proc) (data2, ec->errinfo);
1124 ec->errinfo = e_info;
1130 EC_JUMP_TAG(ec, state);
1147 volatile enum ruby_tag_type state;
1150 int *
volatile pstate = pstate_arg;
1153 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
1154 result = (*proc)(data);
1157 rb_vm_rewind_cfp(ec, cfp);
1161 if (pstate != NULL) *pstate = state;
1168 enum ruby_tag_type state;
1170 VALUE (*
volatile e_proc)(
VALUE) = e_proc_arg;
1171 volatile VALUE data2 = data2_arg;
1175 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
1176 result = (*b_proc) (data1);
1179 errinfo = ec->errinfo;
1184 ec->errinfo = errinfo;
1186 EC_JUMP_TAG(ec, state);
1193 return rb_ec_ensure(GET_EC(), b_proc, data1, e_proc, data2);
1202 return me->def->original_id;
1215 return me->called_id;
1223rb_frame_this_func(
void)
1225 return frame_func_id(GET_EC()->cfp);
1229rb_frame_callee(
void)
1231 return frame_called_id(GET_EC()->cfp);
1239 if ((
void *)(ec->vm_stack + ec->vm_stack_size) == (
void *)(prev_cfp)) {
1246prev_frame_callee(
void)
1249 if (!prev_cfp)
return 0;
1250 return frame_called_id(prev_cfp);
1254prev_frame_func(
void)
1257 if (!prev_cfp)
return 0;
1258 return frame_func_id(prev_cfp);
1268rb_frame_last_func(
void)
1274 while (!(mid = frame_func_id(cfp)) &&
1275 (cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp),
1276 !RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(ec, cfp)));
1293rb_mod_append_features(
VALUE module,
VALUE include)
1295 if (!CLASS_OR_MODULE_P(include)) {
1303static VALUE refinement_import_methods(
int argc,
VALUE *argv,
VALUE refinement);
1313rb_mod_include(
int argc,
VALUE *argv,
VALUE module)
1316 ID id_append_features, id_included;
1318 CONST_ID(id_append_features,
"append_features");
1322 rb_raise(
rb_eTypeError,
"Refinement#include has been removed");
1326 for (i = 0; i < argc; i++) {
1328 if (
FL_TEST(argv[i], RMODULE_IS_REFINEMENT)) {
1333 rb_funcallv_uncached(argv[argc], id_append_features, 1, &module);
1334 rb_funcallv_uncached(argv[argc], id_included, 1, &module);
1352rb_mod_prepend_features(
VALUE module,
VALUE prepend)
1354 if (!CLASS_OR_MODULE_P(prepend)) {
1370rb_mod_prepend(
int argc,
VALUE *argv,
VALUE module)
1373 ID id_prepend_features, id_prepended;
1376 rb_raise(
rb_eTypeError,
"Refinement#prepend has been removed");
1379 CONST_ID(id_prepend_features,
"prepend_features");
1380 CONST_ID(id_prepended,
"prepended");
1383 for (i = 0; i < argc; i++) {
1385 if (
FL_TEST(argv[i], RMODULE_IS_REFINEMENT)) {
1390 rb_funcallv_uncached(argv[argc], id_prepend_features, 1, &module);
1391 rb_funcallv_uncached(argv[argc], id_prepended, 1, &module);
1397ensure_class_or_module(
VALUE obj)
1401 "wrong argument type %"PRIsVALUE
" (expected Class or Module)",
1407hidden_identity_hash_new(
void)
1409 VALUE hash = rb_ident_hash_new();
1411 RBASIC_CLEAR_CLASS(hash);
1416refinement_superclass(
VALUE superclass)
1420 return rb_include_class_new(RCLASS_ORIGIN(superclass),
rb_cBasicObject);
1433 VALUE iclass, c, superclass = klass;
1435 ensure_class_or_module(klass);
1437 if (
NIL_P(CREF_REFINEMENTS(cref))) {
1438 CREF_REFINEMENTS_SET(cref, hidden_identity_hash_new());
1441 if (CREF_OMOD_SHARED(cref)) {
1442 CREF_REFINEMENTS_SET(cref, rb_hash_dup(CREF_REFINEMENTS(cref)));
1443 CREF_OMOD_SHARED_UNSET(cref);
1445 if (!
NIL_P(c = rb_hash_lookup(CREF_REFINEMENTS(cref), klass))) {
1448 if (
RBASIC(c)->klass == module) {
1456 superclass = refinement_superclass(superclass);
1457 c = iclass = rb_include_class_new(module, superclass);
1458 RCLASS_SET_REFINED_CLASS(c, klass);
1460 RCLASS_WRITE_M_TBL(c, RCLASS_M_TBL(module));
1462 rb_class_subclass_add(klass, iclass);
1464 rb_hash_aset(CREF_REFINEMENTS(cref), klass, iclass);
1472 rb_using_refinement(cref, klass, module);
1485 VALUE super, module, refinements;
1489 rb_using_module_recursive(cref, super);
1497 module = RBASIC(klass)->klass;
1501 rb_raise(
rb_eTypeError,
"wrong argument type %s (expected Module)",
1505 CONST_ID(id_refinements,
"__refinements__");
1506 refinements = rb_attr_get(module, id_refinements);
1507 if (
NIL_P(refinements))
return;
1518 rb_using_module_recursive(cref, module);
1519 rb_clear_all_refinement_method_cache();
1536rb_refinement_module_get_refined_class(
VALUE module)
1538 ID id_refined_class;
1540 CONST_ID(id_refined_class,
"__refined_class__");
1541 return rb_attr_get(module, id_refined_class);
1545add_activated_refinement(
VALUE activated_refinements,
1548 VALUE iclass, c, superclass = klass;
1550 if (!
NIL_P(c = rb_hash_lookup(activated_refinements, klass))) {
1553 if (
RBASIC(c)->klass == refinement) {
1560 superclass = refinement_superclass(superclass);
1561 c = iclass = rb_include_class_new(refinement, superclass);
1562 RCLASS_SET_REFINED_CLASS(c, klass);
1563 rb_class_subclass_add(klass, iclass);
1565 while (refinement && refinement != klass) {
1566 c = rb_class_set_super(c, rb_include_class_new(refinement,
RCLASS_SUPER(c)));
1567 RCLASS_SET_REFINED_CLASS(c, klass);
1568 rb_class_subclass_add(klass, c);
1571 rb_hash_aset(activated_refinements, klass, iclass);
1578 ID id_refinements, id_activated_refinements,
1579 id_refined_class, id_defined_at;
1580 VALUE refinements, activated_refinements;
1582 CONST_ID(id_refinements,
"__refinements__");
1583 refinements = rb_attr_get(module, id_refinements);
1584 if (
NIL_P(refinements)) {
1585 refinements = hidden_identity_hash_new();
1588 CONST_ID(id_activated_refinements,
"__activated_refinements__");
1589 activated_refinements = rb_attr_get(module, id_activated_refinements);
1590 if (
NIL_P(activated_refinements)) {
1591 activated_refinements = hidden_identity_hash_new();
1593 activated_refinements);
1595 refinement = rb_hash_lookup(refinements, klass);
1596 if (
NIL_P(refinement)) {
1597 VALUE superclass = refinement_superclass(klass);
1599 rb_class_set_super(refinement, superclass);
1601 FL_SET(refinement, RMODULE_IS_REFINEMENT);
1602 CONST_ID(id_refined_class,
"__refined_class__");
1604 CONST_ID(id_defined_at,
"__defined_at__");
1606 rb_hash_aset(refinements, klass, refinement);
1607 add_activated_refinement(activated_refinements, klass, refinement);
1610 data->refinement = refinement;
1611 data->refinements = activated_refinements;
1628 VALUE block_handler = rb_vm_frame_block_handler(th->ec->cfp);
1631 if (block_handler == VM_BLOCK_HANDLER_NONE) {
1632 rb_raise(rb_eArgError,
"no block given");
1634 if (vm_block_handler_type(block_handler) != block_handler_type_iseq) {
1635 rb_raise(rb_eArgError,
"can't pass a Proc as a block to Module#refine");
1638 ensure_class_or_module(klass);
1642 rb_class_owner_check(module);
1643 rb_class_owner_check(klass);
1645 rb_refinement_setup(&data, module, klass);
1647 rb_yield_refine_block(data.refinement, data.refinements);
1648 return data.refinement;
1652ignored_block(
VALUE module,
const char *klass)
1654 const char *anon =
"";
1656 if (!
RTEST(rb_search_class_path(module))) {
1657 anon =
", maybe for Module.new";
1659 rb_warn(
"%s""using doesn't call the given block""%s.", klass, anon);
1666check_not_refined_proc_scope(
const char *using_name)
1669 for (cref = rb_vm_cref(); cref; cref = CREF_NEXT(cref)) {
1670 if (CREF_REFINED_PROC(cref)) {
1672 "%s is not permitted in a proc with refinements", using_name);
1690 if (prev_frame_func()) {
1692 "Module#using is not permitted in methods");
1694 if (prev_cfp && prev_cfp->self != self) {
1698 ignored_block(module,
"Module#");
1700 check_not_refined_proc_scope(
"Module#using");
1701 rb_using_module(rb_vm_cref_replace_with_duplicated_cref(), module);
1727mod_refinements(
VALUE self)
1732 CONST_ID(id_refinements,
"__refinements__");
1733 refinements = rb_attr_get(self, id_refinements);
1734 if (
NIL_P(refinements)) {
1737 return rb_hash_values(refinements);
1744 CONST_ID(id_defined_at,
"__defined_at__");
1778rb_mod_s_used_modules(
VALUE _)
1784 if (!
NIL_P(CREF_REFINEMENTS(cref))) {
1787 cref = CREF_NEXT(cref);
1790 return rb_funcall(ary, rb_intern(
"uniq"), 0);
1829rb_mod_s_used_refinements(
VALUE _)
1835 if (!
NIL_P(CREF_REFINEMENTS(cref))) {
1838 cref = CREF_NEXT(cref);
1853static enum rb_id_table_iterator_result
1854refinement_import_methods_i(
ID key,
VALUE value,
void *data)
1859 if (me->def->type != VM_METHOD_TYPE_ISEQ) {
1860 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));
1862 rb_cref_t *new_cref = rb_vm_cref_dup_without_refinements(me->def->body.iseq.
cref);
1863 CREF_REFINEMENTS_SET(new_cref, CREF_REFINEMENTS(arg->cref));
1864 rb_add_method_iseq(arg->refinement, key, me->def->body.iseq.
iseqptr, new_cref, METHOD_ENTRY_VISI(me));
1865 return ID_TABLE_CONTINUE;
1873refinement_import_methods(
int argc,
VALUE *argv,
VALUE refinement)
1879 for (i = 0; i < argc; i++) {
1882 rb_warn(
"%"PRIsVALUE
" has ancestors, but Refinement#import_methods doesn't import their methods",
rb_class_path(argv[i]));
1885 arg.cref = rb_vm_cref_replace_with_duplicated_cref();
1886 arg.refinement = refinement;
1887 for (i = 0; i < argc; i++) {
1888 arg.module = argv[i];
1889 struct rb_id_table *m_tbl = RCLASS_M_TBL(argv[i]);
1890 if (!m_tbl)
continue;
1891 rb_id_table_foreach(m_tbl, refinement_import_methods_i, &arg);
1903rb_obj_call_init_kw(
VALUE obj,
int argc,
const VALUE *argv,
int kw_splat)
1905 PASS_PASSED_BLOCK_HANDLER();
1975rb_obj_extend(
int argc,
VALUE *argv,
VALUE obj)
1978 ID id_extend_object, id_extended;
1980 CONST_ID(id_extend_object,
"extend_object");
1984 for (i = 0; i < argc; i++) {
1986 if (
FL_TEST(argv[i], RMODULE_IS_REFINEMENT)) {
1987 rb_raise(
rb_eTypeError,
"Cannot extend object with refinement");
1991 rb_funcallv_uncached(argv[argc], id_extend_object, 1, &obj);
1992 rb_funcallv_uncached(argv[argc], id_extended, 1, &obj);
1998rb_top_main_class(
const char *method)
2000 VALUE klass = GET_THREAD()->top_wrapper;
2003 rb_warning(
"main.%s in the wrapped load is effective only in wrapper module", method);
2017top_include(
int argc,
VALUE *argv,
VALUE self)
2019 return rb_mod_include(argc, argv, rb_top_main_class(
"include"));
2033 const rb_cref_t *cref = CREF_NEXT(rb_vm_cref());
2037 if ((th->top_wrapper ? CREF_NEXT(cref) : cref) ||
2038 (prev_cfp && rb_vm_frame_method_entry(prev_cfp))) {
2042 ignored_block(module,
"main.");
2044 check_not_refined_proc_scope(
"main.using");
2045 rb_using_module(rb_vm_cref_replace_with_duplicated_cref(), module);
2055 while (RUBY_VM_VALID_CONTROL_FRAME_P(cfp, end_cfp)) {
2056 if (VM_FRAME_RUBYFRAME_P(cfp)) {
2057 if (ISEQ_BODY(CFP_ISEQ(cfp))->
type == ISEQ_TYPE_RESCUE) {
2058 return &cfp->ep[VM_ENV_INDEX_LAST_LVAR];
2060 else if (ISEQ_BODY(CFP_ISEQ(cfp))->
type == ISEQ_TYPE_ENSURE &&
2061 !THROW_DATA_P(cfp->ep[VM_ENV_INDEX_LAST_LVAR]) &&
2062 !
FIXNUM_P(cfp->ep[VM_ENV_INDEX_LAST_LVAR])) {
2063 return &cfp->ep[VM_ENV_INDEX_LAST_LVAR];
2066 cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
2074 const VALUE *ptr = errinfo_place(ec);
2086 return get_ec_errinfo(GET_EC());
2092 return get_errinfo();
2098 return GET_EC()->errinfo;
2107 GET_EC()->errinfo = err;
2113 VALUE err = get_errinfo();
2115 return rb_get_backtrace(err);
2125 VALUE err = get_errinfo();
2127 rb_raise(rb_eArgError,
"$! not set");
2129 set_backtrace(err, val);
2145 ID fname = prev_frame_func();
2167 ID fname = prev_frame_callee();
2188f_current_dirname(
VALUE _)
2190 VALUE base = rb_current_realfilepath();
2194 base = rb_file_dirname(base);
2211f_global_variables(
VALUE _)
2267 rb_gvar_ractor_local(
"$@");
2268 rb_gvar_ractor_local(
"$!");
2270 rb_gvar_box_dynamic(
"$@");
2271 rb_gvar_box_dynamic(
"$!");
2292 rb_mod_s_used_modules, 0);
2294 rb_mod_s_used_refinements, 0);
2311 "include", top_include, -1);
2313 "using", top_using, 1);
2320 rb_vm_register_special_exception(ruby_error_reenter,
rb_eFatal,
"exception reentered");
2321 rb_vm_register_special_exception(ruby_error_stackfatal,
rb_eFatal,
"machine stack overflow in critical region");
#define RUBY_ASSERT(...)
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 Qundef
Old name of RUBY_Qundef.
#define INT2FIX
Old name of RB_INT2FIX.
#define OBJ_FROZEN
Old name of RB_OBJ_FROZEN.
#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.
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.
void rb_exc_raise(VALUE mesg)
Raises an exception in the current thread.
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_arg)(VALUE, VALUE), VALUE data2_arg, va_list args)
Identical to rb_rescue2(), except it takes va_list instead of variadic number of arguments.
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.
void rb_error_frozen_object(VALUE frozen_obj)
Identical to rb_error_frozen(), except it takes arbitrary Ruby object instead of C's string.
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_cObject
Object class.
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.
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.
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.
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_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_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.
VALUE type(ANYARGS)
ANYARGS-ed function type.
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.
static bool RB_TYPE_P(VALUE obj, enum ruby_value_type t)
Queries if the given object is of given type.