14 #include "ruby/internal/config.h"
16 #ifdef HAVE_SYS_PRCTL_H
17 #include <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"
41 NORETURN(
static void rb_raise_jump(
VALUE,
VALUE));
51 ID ruby_static_id_signo, ruby_static_id_status;
52 extern 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"
58 #include "eval_jump.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;
236 sysex = sysexit_status(err);
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);
352 while (cref && CREF_NEXT(cref)) {
353 VALUE klass = CREF_CLASS(cref);
354 if (!CREF_PUSHED_BY_EVAL(cref) &&
358 cref = CREF_NEXT(cref);
386 rb_mod_s_constants(
int argc,
VALUE *argv,
VALUE mod)
398 klass = CREF_CLASS(cref);
399 if (!CREF_PUSHED_BY_EVAL(cref) &&
406 cref = CREF_NEXT(cref);
428 rb_module_set_initialized(klass);
469 static VALUE get_errinfo(
void);
470 #define get_ec_errinfo(ec) rb_ec_get_errinfo(ec)
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);
520 *cause = get_ec_errinfo(ec);
530 if (!nocircular && !
NIL_P(*cause) && *cause !=
Qundef && *cause != mesg) {
532 rb_exc_check_circular_cause(*cause);
550 const char *file = rb_source_location_cstr(&line);
551 const char *
const volatile file0 = file;
554 volatile int state = 0;
557 if (EC_EXEC_TAG() == TAG_NONE && !(state = rb_ec_set_raised(ec))) {
558 VALUE bt = rb_get_backtrace(mesg);
564 if (cause !=
Qundef && !THROW_DATA_P(cause)) {
565 exc_setup_cause(mesg, cause);
568 VALUE at = rb_ec_backtrace_object(ec);
570 set_backtrace(mesg, at);
572 rb_ec_reset_raised(ec);
576 if (state)
goto fatal;
585 enum ruby_tag_type state;
589 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
594 e =
rb_sprintf(
"Exception `%"PRIsVALUE
"' at %s:%d - %"PRIsVALUE
"\n",
598 e =
rb_sprintf(
"Exception `%"PRIsVALUE
"' at %s - %"PRIsVALUE
"\n",
602 e =
rb_sprintf(
"Exception `%"PRIsVALUE
"' - %"PRIsVALUE
"\n",
608 if (state == TAG_FATAL && ec->errinfo == exception_error) {
612 rb_ec_reset_raised(ec);
613 EC_JUMP_TAG(ec, state);
617 if (rb_ec_set_raised(ec)) {
621 if (tag != TAG_FATAL) {
628 ec->errinfo = exception_error;
629 rb_ec_reset_raised(ec);
630 EC_JUMP_TAG(ec, TAG_FATAL);
638 cause = get_ec_errinfo(ec);
648 mesg = exc_setup_message(ec, mesg, &cause);
649 setup_exception(ec, tag, mesg, cause);
650 rb_ec_raised_clear(ec);
651 EC_JUMP_TAG(ec, tag);
654 static VALUE make_exception(
int argc,
const VALUE *argv,
int isstr);
656 NORETURN(
static void rb_exc_exception(
VALUE mesg,
int tag,
VALUE cause));
659 rb_exc_exception(
VALUE mesg,
int tag,
VALUE cause)
662 mesg = make_exception(1, &mesg, FALSE);
664 rb_longjmp(GET_EC(), tag, mesg, cause);
677 rb_exc_exception(mesg, TAG_RAISE,
Qundef);
690 rb_exc_exception(mesg, TAG_FATAL,
Qnil);
699 enum {raise_opt_cause, raise_max_opt};
702 extract_raise_opts(
int argc,
const VALUE *argv,
VALUE *opts)
706 VALUE opt = argv[argc-1];
717 for (i = 0; i < raise_max_opt; ++i) {
724 rb_f_raise(
int argc,
VALUE *argv)
727 VALUE opts[raise_max_opt], *
const cause = &opts[raise_opt_cause];
729 argc = extract_raise_opts(argc, argv, opts);
777 return rb_f_raise(c, v);
781 make_exception(
int argc,
const VALUE *argv,
int isstr)
791 if (isstr &&!
NIL_P(exc)) {
802 rb_error_arity(argc, 0, 3);
814 set_backtrace(mesg, argv[2]);
823 return make_exception(argc, argv, TRUE);
834 VALUE klass = me->owner;
835 VALUE self = cfp->self;
836 ID mid = me->called_id;
841 rb_longjmp(ec, TAG_RAISE, mesg, cause);
847 if (UNLIKELY(tag < TAG_RETURN || tag > TAG_FATAL)) {
848 unknown_longjmp_status(tag);
850 EC_JUMP_TAG(GET_EC(), tag);
856 if (rb_vm_frame_block_handler(GET_EC()->cfp) == VM_BLOCK_HANDLER_NONE) {
869 return rb_vm_cframe_keyword_p(GET_EC()->cfp);
878 rb_vm_localjump_error(
"no block given",
Qnil, 0);
898 enum ruby_tag_type state;
902 volatile VALUE e_info = ec->errinfo;
905 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
907 result = (*b_proc) (data1);
911 if (state == TAG_RETRY) {
919 rb_vm_rewind_cfp(ec, cfp);
921 if (state == TAG_RAISE) {
929 while ((eclass = va_arg(ap,
VALUE)) != 0) {
940 result = (*r_proc) (data2, ec->errinfo);
942 ec->errinfo = e_info;
948 EC_JUMP_TAG(ec, state);
965 volatile enum ruby_tag_type state;
970 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
971 SAVE_ROOT_JMPBUF(rb_ec_thread_ptr(ec), result = (*proc) (data));
974 rb_vm_rewind_cfp(ec, cfp);
978 if (pstate != NULL) *pstate = state;
990 ensure_list.entry.marker = 0;
991 ensure_list.entry.e_proc = e_proc;
992 ensure_list.entry.data2 = data2;
993 ensure_list.next = ec->ensure_list;
994 ec->ensure_list = &ensure_list;
996 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
997 result = (*b_proc) (data1);
1000 errinfo = ec->errinfo;
1004 ec->ensure_list=ensure_list.next;
1005 (*ensure_list.entry.e_proc)(ensure_list.entry.data2);
1006 ec->errinfo = errinfo;
1008 EC_JUMP_TAG(ec, state);
1018 return me->def->original_id;
1031 return me->called_id;
1041 return frame_func_id(GET_EC()->cfp);
1047 return frame_called_id(GET_EC()->cfp);
1055 if ((
void *)(ec->vm_stack + ec->vm_stack_size) == (
void *)(prev_cfp)) {
1062 prev_frame_callee(
void)
1065 if (!prev_cfp)
return 0;
1066 return frame_called_id(prev_cfp);
1070 prev_frame_func(
void)
1073 if (!prev_cfp)
return 0;
1074 return frame_func_id(prev_cfp);
1090 while (!(mid = frame_func_id(cfp)) &&
1091 (cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp),
1092 !RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(ec, cfp)));
1109 rb_mod_append_features(
VALUE module,
VALUE include)
1111 if (!CLASS_OR_MODULE_P(include)) {
1127 rb_mod_include(
int argc,
VALUE *argv,
VALUE module)
1130 ID id_append_features, id_included;
1132 CONST_ID(id_append_features,
"append_features");
1135 if (
FL_TEST(module, RMODULE_IS_REFINEMENT)) {
1136 rb_warn_deprecated_to_remove_at(3.2,
"Refinement#include", NULL);
1140 for (i = 0; i < argc; i++)
1143 rb_funcall(argv[argc], id_append_features, 1, module);
1144 rb_funcall(argv[argc], id_included, 1, module);
1162 rb_mod_prepend_features(
VALUE module,
VALUE prepend)
1164 if (!CLASS_OR_MODULE_P(prepend)) {
1180 rb_mod_prepend(
int argc,
VALUE *argv,
VALUE module)
1183 ID id_prepend_features, id_prepended;
1185 if (
FL_TEST(module, RMODULE_IS_REFINEMENT)) {
1186 rb_warn_deprecated_to_remove_at(3.2,
"Refinement#prepend", NULL);
1189 CONST_ID(id_prepend_features,
"prepend_features");
1190 CONST_ID(id_prepended,
"prepended");
1193 for (i = 0; i < argc; i++)
1196 rb_funcall(argv[argc], id_prepend_features, 1, module);
1197 rb_funcall(argv[argc], id_prepended, 1, module);
1203 ensure_class_or_module(
VALUE obj)
1207 "wrong argument type %"PRIsVALUE
" (expected Class or Module)",
1213 hidden_identity_hash_new(
void)
1215 VALUE hash = rb_ident_hash_new();
1217 RBASIC_CLEAR_CLASS(hash);
1222 refinement_superclass(
VALUE superclass)
1226 return rb_include_class_new(RCLASS_ORIGIN(superclass),
rb_cBasicObject);
1239 VALUE iclass, c, superclass = klass;
1241 ensure_class_or_module(klass);
1243 if (
NIL_P(CREF_REFINEMENTS(cref))) {
1244 CREF_REFINEMENTS_SET(cref, hidden_identity_hash_new());
1247 if (CREF_OMOD_SHARED(cref)) {
1248 CREF_REFINEMENTS_SET(cref,
rb_hash_dup(CREF_REFINEMENTS(cref)));
1249 CREF_OMOD_SHARED_UNSET(cref);
1254 if (
RBASIC(c)->klass == module) {
1262 FL_SET(module, RMODULE_IS_OVERLAID);
1263 superclass = refinement_superclass(superclass);
1264 c = iclass = rb_include_class_new(module, superclass);
1267 RCLASS_M_TBL(c) = RCLASS_M_TBL(module);
1270 while (module && module != klass) {
1271 FL_SET(module, RMODULE_IS_OVERLAID);
1272 c = RCLASS_SET_SUPER(c, rb_include_class_new(module,
RCLASS_SUPER(c)));
1284 rb_using_refinement(cref, klass, module);
1292 VALUE super, module, refinements;
1296 using_module_recursive(cref, super);
1304 module =
RBASIC(klass)->klass;
1312 CONST_ID(id_refinements,
"__refinements__");
1313 refinements =
rb_attr_get(module, id_refinements);
1314 if (
NIL_P(refinements))
return;
1325 using_module_recursive(cref, module);
1326 rb_clear_method_cache_all();
1331 rb_refinement_module_get_refined_class(
VALUE module)
1333 ID id_refined_class;
1335 CONST_ID(id_refined_class,
"__refined_class__");
1340 add_activated_refinement(
VALUE activated_refinements,
1343 VALUE iclass, c, superclass = klass;
1348 if (
RBASIC(c)->klass == refinement) {
1355 FL_SET(refinement, RMODULE_IS_OVERLAID);
1356 superclass = refinement_superclass(superclass);
1357 c = iclass = rb_include_class_new(refinement, superclass);
1360 while (refinement && refinement != klass) {
1361 FL_SET(refinement, RMODULE_IS_OVERLAID);
1362 c = RCLASS_SET_SUPER(c, rb_include_class_new(refinement,
RCLASS_SUPER(c)));
1382 ID id_refinements, id_activated_refinements,
1383 id_refined_class, id_defined_at;
1384 VALUE refinements, activated_refinements;
1386 VALUE block_handler = rb_vm_frame_block_handler(th->ec->cfp);
1388 if (block_handler == VM_BLOCK_HANDLER_NONE) {
1391 if (vm_block_handler_type(block_handler) != block_handler_type_iseq) {
1395 ensure_class_or_module(klass);
1396 CONST_ID(id_refinements,
"__refinements__");
1397 refinements =
rb_attr_get(module, id_refinements);
1398 if (
NIL_P(refinements)) {
1399 refinements = hidden_identity_hash_new();
1402 CONST_ID(id_activated_refinements,
"__activated_refinements__");
1403 activated_refinements =
rb_attr_get(module, id_activated_refinements);
1404 if (
NIL_P(activated_refinements)) {
1405 activated_refinements = hidden_identity_hash_new();
1407 activated_refinements);
1410 if (
NIL_P(refinement)) {
1411 VALUE superclass = refinement_superclass(klass);
1413 RCLASS_SET_SUPER(refinement, superclass);
1414 FL_SET(refinement, RMODULE_IS_REFINEMENT);
1415 CONST_ID(id_refined_class,
"__refined_class__");
1417 CONST_ID(id_defined_at,
"__defined_at__");
1420 add_activated_refinement(activated_refinements, klass, refinement);
1422 rb_yield_refine_block(refinement, activated_refinements);
1427 ignored_block(
VALUE module,
const char *klass)
1429 const char *anon =
"";
1431 if (!
RTEST(rb_search_class_path(module))) {
1432 anon =
", maybe for Module.new";
1434 rb_warn(
"%s""using doesn't call the given block""%s.", klass, anon);
1450 if (prev_frame_func()) {
1452 "Module#using is not permitted in methods");
1454 if (prev_cfp && prev_cfp->self !=
self) {
1458 ignored_block(module,
"Module#");
1460 rb_using_module(rb_vm_cref_replace_with_duplicated_cref(), module);
1468 CONST_ID(id_defined_at,
"__defined_at__");
1502 rb_mod_s_used_modules(
VALUE _)
1508 if (!
NIL_P(CREF_REFINEMENTS(cref))) {
1511 cref = CREF_NEXT(cref);
1526 static enum rb_id_table_iterator_result
1527 refinement_import_methods_i(
ID key,
VALUE value,
void *data)
1532 if (me->def->type != VM_METHOD_TYPE_ISEQ) {
1535 rb_cref_t *new_cref = rb_vm_cref_dup_without_refinements(me->def->body.iseq.
cref);
1536 CREF_REFINEMENTS_SET(new_cref, CREF_REFINEMENTS(arg->cref));
1537 rb_add_method_iseq(arg->refinement, key, me->def->body.iseq.
iseqptr, new_cref, METHOD_ENTRY_VISI(me));
1538 return ID_TABLE_CONTINUE;
1546 refinement_import_methods(
int argc,
VALUE *argv,
VALUE refinement)
1552 for (i = 0; i < argc; i++) {
1555 rb_warn(
"%"PRIsVALUE
" has ancestors, but Refinement#import_methods doesn't import their methods",
rb_class_path(argv[i]));
1558 arg.cref = rb_vm_cref_replace_with_duplicated_cref();
1559 arg.refinement = refinement;
1560 for (i = 0; i < argc; i++) {
1561 arg.module = argv[i];
1562 struct rb_id_table *m_tbl = RCLASS_M_TBL(argv[i]);
1563 if (!m_tbl)
continue;
1564 rb_id_table_foreach(m_tbl, refinement_import_methods_i, &arg);
1578 PASS_PASSED_BLOCK_HANDLER();
1648 rb_obj_extend(
int argc,
VALUE *argv,
VALUE obj)
1651 ID id_extend_object, id_extended;
1653 CONST_ID(id_extend_object,
"extend_object");
1657 for (i = 0; i < argc; i++)
1660 rb_funcall(argv[argc], id_extend_object, 1, obj);
1676 top_include(
int argc,
VALUE *argv,
VALUE self)
1680 if (th->top_wrapper) {
1681 rb_warning(
"main.include in the wrapped load is effective only in wrapper module");
1682 return rb_mod_include(argc, argv, th->top_wrapper);
1684 return rb_mod_include(argc, argv, rb_cObject);
1701 if (CREF_NEXT(cref) || (prev_cfp && rb_vm_frame_method_entry(prev_cfp))) {
1705 ignored_block(module,
"main.");
1707 rb_using_module(rb_vm_cref_replace_with_duplicated_cref(), module);
1711 static const VALUE *
1717 while (RUBY_VM_VALID_CONTROL_FRAME_P(cfp, end_cfp)) {
1718 if (VM_FRAME_RUBYFRAME_P(cfp)) {
1719 if (cfp->iseq->body->type == ISEQ_TYPE_RESCUE) {
1720 return &cfp->ep[VM_ENV_INDEX_LAST_LVAR];
1722 else if (cfp->iseq->body->type == ISEQ_TYPE_ENSURE &&
1723 !THROW_DATA_P(cfp->ep[VM_ENV_INDEX_LAST_LVAR]) &&
1724 !
FIXNUM_P(cfp->ep[VM_ENV_INDEX_LAST_LVAR])) {
1725 return &cfp->ep[VM_ENV_INDEX_LAST_LVAR];
1728 cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
1736 const VALUE *ptr = errinfo_place(ec);
1748 return get_ec_errinfo(GET_EC());
1754 return get_errinfo();
1760 return GET_EC()->errinfo;
1769 GET_EC()->errinfo = err;
1775 VALUE err = get_errinfo();
1777 return rb_get_backtrace(err);
1787 VALUE err = get_errinfo();
1791 set_backtrace(err, val);
1805 rb_f_method_name(
VALUE _)
1807 ID fname = prev_frame_func();
1827 rb_f_callee_name(
VALUE _)
1829 ID fname = prev_frame_callee();
1850 f_current_dirname(
VALUE _)
1852 VALUE base = rb_current_realfilepath();
1873 f_global_variables(
VALUE _)
1929 rb_gvar_ractor_local(
"$@");
1930 rb_gvar_ractor_local(
"$!");
1950 rb_mod_s_used_modules, 0);
1963 "include", top_include, -1);
1965 "using", top_using, 1);
1972 rb_vm_register_special_exception(ruby_error_reenter,
rb_eFatal,
"exception reentered");
1973 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.
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.
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.
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 always regardless of runtime -W flag.
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.
VALUE rb_eSystemCallError
SystemCallError exception.
void rb_warning(const char *fmt,...)
Issues a warning.
VALUE rb_eSignal
SignalException exception.
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_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_get(VALUE obj, ID name)
Identical to rb_iv_get(), except it accepts the name as an ID instead of a C string.
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.
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.
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.