14 #include "ruby/internal/config.h"
16 #ifdef HAVE_SYS_PRCTL_H
17 #include <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"
42 NORETURN(
static void rb_raise_jump(
VALUE,
VALUE));
52 ID ruby_static_id_signo, ruby_static_id_status;
53 extern 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"
59 #include "eval_jump.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;
77 #if defined(__linux__) && defined(PR_SET_THP_DISABLE)
78 prctl(PR_SET_THP_DISABLE, 1, 0, 0, 0);
81 rb_vm_encoded_insn_data_table_init();
84 EC_PUSH_TAG(GET_EC());
85 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
88 GET_VM()->running = 1;
102 rb_ec_error_print(ec, ec->errinfo);
112 enum ruby_tag_type state;
113 void *
volatile iseq = 0;
116 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
120 rb_ec_clear_current_thread_trace_func(ec);
121 int exitcode = error_handle(ec, ec->errinfo, state);
123 iseq = (
void *)
INT2FIX(exitcode);
132 enum ruby_tag_type state;
135 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
139 state = error_handle(ec, ec->errinfo, 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();
178 return rb_ec_cleanup(GET_EC(), (
enum ruby_tag_type)ex);
186 volatile int sysex = EXIT_SUCCESS;
187 volatile int signaled = 0;
190 volatile int step = 0;
194 rb_threadptr_interrupt(th);
195 rb_threadptr_check_signal(th);
198 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
199 RUBY_VM_CHECK_INTS(ec);
202 save_error = ec->errinfo;
203 if (THROW_DATA_P(ec->errinfo)) ec->errinfo =
Qnil;
210 VALUE err = ec->errinfo;
211 volatile int mode0 = 0, mode1 = 0;
212 if (err != save_error && !
NIL_P(err)) {
213 mode0 = exiting_split(err, &sysex, &signaled);
219 err = ATOMIC_VALUE_EXCHANGE(save_error,
Qnil);
221 if (!
NIL_P(err) && !THROW_DATA_P(err)) {
222 mode1 = exiting_split(err, (mode0 & EXITING_WITH_STATUS) ? NULL : &sysex, &signaled);
223 if (mode1 & EXITING_WITH_MESSAGE) {
225 rb_ec_error_print_detailed(ec, err, buf,
Qundef);
232 th->status = THREAD_KILLED;
234 rb_ractor_terminate_all();
237 if (!
NIL_P(buf = message)) {
240 else if (!NIL_OR_UNDEF_P(err = save_error) ||
241 (ex != TAG_NONE && !((mode0|mode1) & EXITING_WITH_STATUS))) {
242 sysex = error_handle(ec, err, ex);
258 rb_threadptr_unlock_all_locking_mutexes(th);
262 rb_thread_stop_timer_thread();
265 rb_jit_cont_finish();
280 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
281 rb_iseq_eval_main(iseq);
300 case Qtrue: s = EXIT_SUCCESS;
break;
301 case Qfalse: s = EXIT_FAILURE;
break;
306 if (status) *status = s;
316 rb_ec_cleanup(ec, (
NIL_P(ec->errinfo) ? TAG_NONE : TAG_RAISE));
319 return rb_ec_cleanup(ec, rb_ec_exec_node(ec, n));
325 return rb_ec_exec_node(GET_EC(), n);
349 while (cref && CREF_NEXT(cref)) {
350 VALUE klass = CREF_CLASS(cref);
351 if (!CREF_PUSHED_BY_EVAL(cref) &&
355 cref = CREF_NEXT(cref);
383 rb_mod_s_constants(
int argc,
VALUE *argv,
VALUE mod)
395 klass = CREF_CLASS(cref);
396 if (!CREF_PUSHED_BY_EVAL(cref) &&
403 cref = CREF_NEXT(cref);
425 rb_module_set_initialized(klass);
430 if (RCLASS_SINGLETON_P(klass)) {
432 klass = RCLASS_ATTACHED_OBJECT(klass);
466 static VALUE get_errinfo(
void);
467 #define get_ec_errinfo(ec) rb_ec_get_errinfo(ec)
475 CONST_ID(id_true_cause,
"true_cause");
486 if (!
NIL_P(cause) && cause != exc) {
503 if (INTERNAL_EXCEPTION_P(mesg)) EC_JUMP_TAG(ec, TAG_FATAL);
511 if (UNDEF_P(*cause)) {
517 *cause = get_ec_errinfo(ec);
527 if (!nocircular && !
NIL_P(*cause) && !UNDEF_P(*cause) && *cause != mesg) {
529 rb_exc_check_circular_cause(*cause);
547 const char *file = rb_source_location_cstr(&line);
548 const char *
const volatile file0 = file;
550 if ((file && !
NIL_P(mesg)) || !UNDEF_P(cause)) {
551 volatile int state = 0;
554 if (EC_EXEC_TAG() == TAG_NONE && !(state = rb_ec_set_raised(ec))) {
555 VALUE bt = rb_get_backtrace(mesg);
556 if (!
NIL_P(bt) || UNDEF_P(cause)) {
561 if (!UNDEF_P(cause) && !THROW_DATA_P(cause)) {
562 exc_setup_cause(mesg, cause);
565 VALUE at = rb_ec_backtrace_object(ec);
567 set_backtrace(mesg, at);
569 rb_ec_reset_raised(ec);
573 if (state)
goto fatal;
582 enum ruby_tag_type state;
586 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
591 e =
rb_sprintf(
"Exception '%"PRIsVALUE
"' at %s:%d - %"PRIsVALUE
"\n",
595 e =
rb_sprintf(
"Exception '%"PRIsVALUE
"' at %s - %"PRIsVALUE
"\n",
599 e =
rb_sprintf(
"Exception '%"PRIsVALUE
"' - %"PRIsVALUE
"\n",
605 if (state == TAG_FATAL && ec->errinfo == exception_error) {
609 rb_ec_reset_raised(ec);
610 EC_JUMP_TAG(ec, state);
614 if (rb_ec_set_raised(ec)) {
618 if (tag != TAG_FATAL) {
625 ec->errinfo = exception_error;
626 rb_ec_reset_raised(ec);
627 EC_JUMP_TAG(ec, TAG_FATAL);
634 if (UNDEF_P(cause)) {
635 cause = get_ec_errinfo(ec);
638 if (THROW_DATA_P(cause)) {
649 mesg = exc_setup_message(ec, mesg, &cause);
650 setup_exception(ec, tag, mesg, cause);
651 rb_ec_raised_clear(ec);
652 EC_JUMP_TAG(ec, tag);
655 static VALUE make_exception(
int argc,
const VALUE *argv,
int isstr);
657 NORETURN(
static void rb_exc_exception(
VALUE mesg,
enum ruby_tag_type tag,
VALUE cause));
660 rb_exc_exception(
VALUE mesg,
enum ruby_tag_type tag,
VALUE cause)
663 mesg = make_exception(1, &mesg, FALSE);
665 rb_longjmp(GET_EC(), tag, mesg, cause);
678 rb_exc_exception(mesg, TAG_RAISE,
Qundef);
691 rb_exc_exception(mesg, TAG_FATAL,
Qnil);
700 enum {raise_opt_cause, raise_max_opt};
703 extract_raise_opts(
int argc,
VALUE *argv,
VALUE *opts)
719 for (i = 0; i < raise_max_opt; ++i) {
726 rb_f_raise(
int argc,
VALUE *argv)
729 VALUE opts[raise_max_opt], *
const cause = &opts[raise_opt_cause];
731 argc = extract_raise_opts(argc, argv, opts);
733 if (!UNDEF_P(*cause)) {
839 return rb_f_raise(c, v);
843 make_exception(
int argc,
const VALUE *argv,
int isstr)
853 if (isstr &&!
NIL_P(exc)) {
864 rb_error_arity(argc, 0, 3);
876 set_backtrace(mesg, argv[2]);
885 return make_exception(argc, argv, TRUE);
896 VALUE klass = me->owner;
897 VALUE self = cfp->self;
898 ID mid = me->called_id;
903 rb_longjmp(ec, TAG_RAISE, mesg, cause);
909 if (UNLIKELY(tag < TAG_RETURN || tag > TAG_FATAL)) {
910 unknown_longjmp_status(tag);
912 EC_JUMP_TAG(GET_EC(), tag);
918 if (rb_vm_frame_block_handler(GET_EC()->cfp) == VM_BLOCK_HANDLER_NONE) {
931 return rb_vm_cframe_keyword_p(GET_EC()->cfp);
940 rb_vm_localjump_error(
"no block given",
Qnil, 0);
960 enum ruby_tag_type state;
964 volatile VALUE e_info = ec->errinfo;
967 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
969 result = (*b_proc) (data1);
973 if (state == TAG_RETRY) {
981 rb_vm_rewind_cfp(ec, cfp);
983 if (state == TAG_RAISE) {
991 while ((eclass = va_arg(ap,
VALUE)) != 0) {
1002 result = (*r_proc) (data2, ec->errinfo);
1004 ec->errinfo = e_info;
1010 EC_JUMP_TAG(ec, state);
1027 volatile enum ruby_tag_type state;
1032 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
1033 result = (*proc)(data);
1036 rb_vm_rewind_cfp(ec, cfp);
1040 if (pstate != NULL) *pstate = state;
1047 enum ruby_tag_type state;
1052 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
1053 result = (*b_proc) (data1);
1056 errinfo = ec->errinfo;
1061 ec->errinfo = errinfo;
1063 EC_JUMP_TAG(ec, state);
1073 return me->def->original_id;
1086 return me->called_id;
1096 return frame_func_id(GET_EC()->cfp);
1102 return frame_called_id(GET_EC()->cfp);
1110 if ((
void *)(ec->vm_stack + ec->vm_stack_size) == (
void *)(prev_cfp)) {
1117 prev_frame_callee(
void)
1120 if (!prev_cfp)
return 0;
1121 return frame_called_id(prev_cfp);
1125 prev_frame_func(
void)
1128 if (!prev_cfp)
return 0;
1129 return frame_func_id(prev_cfp);
1145 while (!(mid = frame_func_id(cfp)) &&
1146 (cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp),
1147 !RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(ec, cfp)));
1164 rb_mod_append_features(
VALUE module,
VALUE include)
1166 if (!CLASS_OR_MODULE_P(include)) {
1182 rb_mod_include(
int argc,
VALUE *argv,
VALUE module)
1185 ID id_append_features, id_included;
1187 CONST_ID(id_append_features,
"append_features");
1195 for (i = 0; i < argc; i++) {
1197 if (
FL_TEST(argv[i], RMODULE_IS_REFINEMENT)) {
1202 rb_funcall(argv[argc], id_append_features, 1, module);
1203 rb_funcall(argv[argc], id_included, 1, module);
1221 rb_mod_prepend_features(
VALUE module,
VALUE prepend)
1223 if (!CLASS_OR_MODULE_P(prepend)) {
1239 rb_mod_prepend(
int argc,
VALUE *argv,
VALUE module)
1242 ID id_prepend_features, id_prepended;
1248 CONST_ID(id_prepend_features,
"prepend_features");
1249 CONST_ID(id_prepended,
"prepended");
1252 for (i = 0; i < argc; i++) {
1254 if (
FL_TEST(argv[i], RMODULE_IS_REFINEMENT)) {
1259 rb_funcall(argv[argc], id_prepend_features, 1, module);
1260 rb_funcall(argv[argc], id_prepended, 1, module);
1266 ensure_class_or_module(
VALUE obj)
1270 "wrong argument type %"PRIsVALUE
" (expected Class or Module)",
1276 hidden_identity_hash_new(
void)
1278 VALUE hash = rb_ident_hash_new();
1280 RBASIC_CLEAR_CLASS(hash);
1285 refinement_superclass(
VALUE superclass)
1289 return rb_include_class_new(RCLASS_ORIGIN(superclass),
rb_cBasicObject);
1302 VALUE iclass, c, superclass = klass;
1304 ensure_class_or_module(klass);
1306 if (
NIL_P(CREF_REFINEMENTS(cref))) {
1307 CREF_REFINEMENTS_SET(cref, hidden_identity_hash_new());
1310 if (CREF_OMOD_SHARED(cref)) {
1311 CREF_REFINEMENTS_SET(cref,
rb_hash_dup(CREF_REFINEMENTS(cref)));
1312 CREF_OMOD_SHARED_UNSET(cref);
1317 if (
RBASIC(c)->klass == module) {
1325 superclass = refinement_superclass(superclass);
1326 c = iclass = rb_include_class_new(module, superclass);
1329 RCLASS_M_TBL(c) = RCLASS_M_TBL(module);
1339 rb_using_refinement(cref, klass, module);
1347 VALUE super, module, refinements;
1351 using_module_recursive(cref, super);
1359 module =
RBASIC(klass)->klass;
1367 CONST_ID(id_refinements,
"__refinements__");
1368 refinements =
rb_attr_get(module, id_refinements);
1369 if (
NIL_P(refinements))
return;
1380 using_module_recursive(cref, module);
1381 rb_clear_all_refinement_method_cache();
1398 rb_refinement_module_get_refined_class(
VALUE module)
1400 ID id_refined_class;
1402 CONST_ID(id_refined_class,
"__refined_class__");
1407 add_activated_refinement(
VALUE activated_refinements,
1410 VALUE iclass, c, superclass = klass;
1415 if (
RBASIC(c)->klass == refinement) {
1422 superclass = refinement_superclass(superclass);
1423 c = iclass = rb_include_class_new(refinement, superclass);
1426 while (refinement && refinement != klass) {
1427 c = RCLASS_SET_SUPER(c, rb_include_class_new(refinement,
RCLASS_SUPER(c)));
1447 ID id_refinements, id_activated_refinements,
1448 id_refined_class, id_defined_at;
1449 VALUE refinements, activated_refinements;
1451 VALUE block_handler = rb_vm_frame_block_handler(th->ec->cfp);
1453 if (block_handler == VM_BLOCK_HANDLER_NONE) {
1456 if (vm_block_handler_type(block_handler) != block_handler_type_iseq) {
1460 ensure_class_or_module(klass);
1461 CONST_ID(id_refinements,
"__refinements__");
1462 refinements =
rb_attr_get(module, id_refinements);
1463 if (
NIL_P(refinements)) {
1464 refinements = hidden_identity_hash_new();
1467 CONST_ID(id_activated_refinements,
"__activated_refinements__");
1468 activated_refinements =
rb_attr_get(module, id_activated_refinements);
1469 if (
NIL_P(activated_refinements)) {
1470 activated_refinements = hidden_identity_hash_new();
1472 activated_refinements);
1475 if (
NIL_P(refinement)) {
1476 VALUE superclass = refinement_superclass(klass);
1478 RCLASS_SET_SUPER(refinement, superclass);
1480 FL_SET(refinement, RMODULE_IS_REFINEMENT);
1481 CONST_ID(id_refined_class,
"__refined_class__");
1483 CONST_ID(id_defined_at,
"__defined_at__");
1486 add_activated_refinement(activated_refinements, klass, refinement);
1488 rb_yield_refine_block(refinement, activated_refinements);
1493 ignored_block(
VALUE module,
const char *klass)
1495 const char *anon =
"";
1497 if (!
RTEST(rb_search_class_path(module))) {
1498 anon =
", maybe for Module.new";
1500 rb_warn(
"%s""using doesn't call the given block""%s.", klass, anon);
1516 if (prev_frame_func()) {
1518 "Module#using is not permitted in methods");
1520 if (prev_cfp && prev_cfp->self !=
self) {
1524 ignored_block(module,
"Module#");
1526 rb_using_module(rb_vm_cref_replace_with_duplicated_cref(), module);
1552 mod_refinements(
VALUE self)
1557 CONST_ID(id_refinements,
"__refinements__");
1559 if (
NIL_P(refinements)) {
1562 return rb_hash_values(refinements);
1569 CONST_ID(id_defined_at,
"__defined_at__");
1603 rb_mod_s_used_modules(
VALUE _)
1609 if (!
NIL_P(CREF_REFINEMENTS(cref))) {
1612 cref = CREF_NEXT(cref);
1654 rb_mod_s_used_refinements(
VALUE _)
1660 if (!
NIL_P(CREF_REFINEMENTS(cref))) {
1663 cref = CREF_NEXT(cref);
1678 static enum rb_id_table_iterator_result
1679 refinement_import_methods_i(
ID key,
VALUE value,
void *data)
1684 if (me->def->type != VM_METHOD_TYPE_ISEQ) {
1687 rb_cref_t *new_cref = rb_vm_cref_dup_without_refinements(me->def->body.iseq.
cref);
1688 CREF_REFINEMENTS_SET(new_cref, CREF_REFINEMENTS(arg->cref));
1689 rb_add_method_iseq(arg->refinement, key, me->def->body.iseq.
iseqptr, new_cref, METHOD_ENTRY_VISI(me));
1690 return ID_TABLE_CONTINUE;
1698 refinement_import_methods(
int argc,
VALUE *argv,
VALUE refinement)
1704 for (i = 0; i < argc; i++) {
1707 rb_warn(
"%"PRIsVALUE
" has ancestors, but Refinement#import_methods doesn't import their methods",
rb_class_path(argv[i]));
1710 arg.cref = rb_vm_cref_replace_with_duplicated_cref();
1711 arg.refinement = refinement;
1712 for (i = 0; i < argc; i++) {
1713 arg.module = argv[i];
1714 struct rb_id_table *m_tbl = RCLASS_M_TBL(argv[i]);
1715 if (!m_tbl)
continue;
1716 rb_id_table_foreach(m_tbl, refinement_import_methods_i, &arg);
1730 PASS_PASSED_BLOCK_HANDLER();
1800 rb_obj_extend(
int argc,
VALUE *argv,
VALUE obj)
1803 ID id_extend_object, id_extended;
1805 CONST_ID(id_extend_object,
"extend_object");
1809 for (i = 0; i < argc; i++) {
1811 if (
FL_TEST(argv[i], RMODULE_IS_REFINEMENT)) {
1816 rb_funcall(argv[argc], id_extend_object, 1, obj);
1823 rb_top_main_class(
const char *method)
1825 VALUE klass = GET_THREAD()->top_wrapper;
1827 if (!klass)
return rb_cObject;
1828 rb_warning(
"main.%s in the wrapped load is effective only in wrapper module", method);
1842 top_include(
int argc,
VALUE *argv,
VALUE self)
1844 return rb_mod_include(argc, argv, rb_top_main_class(
"include"));
1858 const rb_cref_t *cref = CREF_NEXT(rb_vm_cref());
1862 if ((th->top_wrapper ? CREF_NEXT(cref) : cref) ||
1863 (prev_cfp && rb_vm_frame_method_entry(prev_cfp))) {
1867 ignored_block(module,
"main.");
1869 rb_using_module(rb_vm_cref_replace_with_duplicated_cref(), module);
1873 static const VALUE *
1879 while (RUBY_VM_VALID_CONTROL_FRAME_P(cfp, end_cfp)) {
1880 if (VM_FRAME_RUBYFRAME_P(cfp)) {
1881 if (ISEQ_BODY(cfp->iseq)->type == ISEQ_TYPE_RESCUE) {
1882 return &cfp->ep[VM_ENV_INDEX_LAST_LVAR];
1884 else if (ISEQ_BODY(cfp->iseq)->type == ISEQ_TYPE_ENSURE &&
1885 !THROW_DATA_P(cfp->ep[VM_ENV_INDEX_LAST_LVAR]) &&
1886 !
FIXNUM_P(cfp->ep[VM_ENV_INDEX_LAST_LVAR])) {
1887 return &cfp->ep[VM_ENV_INDEX_LAST_LVAR];
1890 cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
1898 const VALUE *
ptr = errinfo_place(ec);
1910 return get_ec_errinfo(GET_EC());
1916 return get_errinfo();
1922 return GET_EC()->errinfo;
1931 GET_EC()->errinfo = err;
1937 VALUE err = get_errinfo();
1939 return rb_get_backtrace(err);
1949 VALUE err = get_errinfo();
1953 set_backtrace(err, val);
1967 rb_f_method_name(
VALUE _)
1969 ID fname = prev_frame_func();
1989 rb_f_callee_name(
VALUE _)
1991 ID fname = prev_frame_callee();
2012 f_current_dirname(
VALUE _)
2014 VALUE base = rb_current_realfilepath();
2035 f_global_variables(
VALUE _)
2091 rb_gvar_ractor_local(
"$@");
2092 rb_gvar_ractor_local(
"$!");
2113 rb_mod_s_used_modules, 0);
2115 rb_mod_s_used_refinements, 0);
2132 "include", top_include, -1);
2134 "using", top_using, 1);
2141 rb_vm_register_special_exception(ruby_error_reenter,
rb_eFatal,
"exception reentered");
2142 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_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.
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.
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.
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.
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 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.
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.
VALUE rb_eSystemExit
SystemExit exception.
VALUE rb_eStandardError
StandardError exception.
void rb_set_errinfo(VALUE err)
Sets the current exception ($!) to the given value.
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_eArgError
ArgumentError exception.
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.
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_str_new(const char *ptr, long len)
Allocates an instance of rb_cString.
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.
void * rb_mod_const_at(VALUE, void *)
This API is mysterious.
VALUE rb_mod_constants(int argc, const VALUE *argv, VALUE recv)
Resembles Module#constants.
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.
void * rb_mod_const_of(VALUE, void *)
This is a variant of rb_mod_const_at().
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.
char * ptr
Pointer to the underlying memory region, of at least capa bytes.
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.
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.
int * rb_errno_ptr(void)
The location of errno
const char * rb_obj_classname(VALUE obj)
Queries the name of the class of the passed object.
int rb_errno(void)
Identical to system errno.
void rb_errno_set(int err)
Set the errno.
#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.