Ruby
2.7.1p83(2020-03-31revisiona0c7c23c9cec0d0ffcba012279cd652d28ad5bf3)
|
Go to the documentation of this file.
23 #ifdef HAVE_SYS_PRCTL_H
24 #include <sys/prctl.h>
39 #define id_cause ruby_static_id_cause
41 #define exception_error GET_VM()->special_exceptions[ruby_error_reenter]
46 #define CLASS_OR_MODULE_P(obj) \
47 (!SPECIAL_CONST_P(obj) && \
48 (BUILTIN_TYPE(obj) == T_CLASS || BUILTIN_TYPE(obj) == T_MODULE))
69 #if defined(__linux__) && defined(PR_SET_THP_DISABLE)
70 prctl(PR_SET_THP_DISABLE, 1, 0, 0, 0);
119 void *
volatile iseq = 0;
128 state = error_handle(ec, state);
143 rb_ec_exec_end_proc(ec);
183 return rb_ec_cleanup(
GET_EC(), ex);
195 volatile int step = 0;
225 if (ex == 0) ex = state;
229 sysex = error_handle(ec, ex);
232 for (nerr = 0; nerr <
numberof(errs); ++nerr) {
241 sysex = sysexit_status(
err);
318 if (status) *status = s;
332 rb_ec_cleanup(ec, 0);
336 return rb_ec_cleanup(ec, rb_ec_exec_node(ec,
n));
344 return rb_ec_exec_node(
GET_EC(),
n);
368 while (cref && CREF_NEXT(cref)) {
370 if (!CREF_PUSHED_BY_EVAL(cref) &&
374 cref = CREF_NEXT(cref);
414 klass = CREF_CLASS(cref);
415 if (!CREF_PUSHED_BY_EVAL(cref) &&
422 cref = CREF_NEXT(cref);
480 static VALUE get_errinfo(
void);
481 #define get_ec_errinfo(ec) rb_ec_get_errinfo(ec)
489 CONST_ID(id_true_cause,
"true_cause");
500 if (!
NIL_P(cause) && cause !=
exc) {
541 if (!nocircular && !
NIL_P(*cause) && *cause !=
Qundef && *cause != mesg) {
558 const char *
const volatile file0 = file;
561 volatile int state = 0;
572 exc_setup_cause(mesg, cause);
577 set_backtrace(mesg, at);
583 if (state)
goto fatal;
652 mesg = exc_setup_message(ec, mesg, &cause);
653 setup_exception(ec, tag, mesg, cause);
671 mesg = make_exception(1, &mesg,
FALSE);
687 mesg = make_exception(1, &mesg,
FALSE);
824 set_backtrace(mesg,
argv[2]);
990 result = (*b_proc) (data1);
1019 result = (*r_proc) (data2, ec->
errinfo);
1096 if (pstate !=
NULL) *pstate = state;
1129 result = (*b_proc) (data1);
1217 prev_frame_callee(
void)
1220 if (!prev_cfp)
return 0;
1221 return frame_called_id(prev_cfp);
1225 prev_frame_func(
void)
1228 if (!prev_cfp)
return 0;
1229 return frame_func_id(prev_cfp);
1245 while (!(mid = frame_func_id(
cfp)) &&
1247 !RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(ec,
cfp)));
1264 rb_mod_append_features(
VALUE module,
VALUE include)
1285 ID id_append_features, id_included;
1287 CONST_ID(id_append_features,
"append_features");
1313 rb_mod_prepend_features(
VALUE module,
VALUE prepend)
1334 ID id_prepend_features, id_prepended;
1336 CONST_ID(id_prepend_features,
"prepend_features");
1337 CONST_ID(id_prepended,
"prepended");
1354 "wrong argument type %"PRIsVALUE" (expected Class or Module)",
1360 hidden_identity_hash_new(
void)
1369 refinement_superclass(
VALUE superclass)
1389 ensure_class_or_module(
klass);
1391 if (
NIL_P(CREF_REFINEMENTS(cref))) {
1392 CREF_REFINEMENTS_SET(cref, hidden_identity_hash_new());
1395 if (CREF_OMOD_SHARED(cref)) {
1396 CREF_REFINEMENTS_SET(cref,
rb_hash_dup(CREF_REFINEMENTS(cref)));
1397 CREF_OMOD_SHARED_UNSET(cref);
1411 superclass = refinement_superclass(superclass);
1419 while (module && module !=
klass) {
1433 rb_using_refinement(cref,
klass, module);
1441 VALUE super, module, refinements;
1445 using_module_recursive(cref, super);
1461 CONST_ID(id_refinements,
"__refinements__");
1462 refinements =
rb_attr_get(module, id_refinements);
1463 if (
NIL_P(refinements))
return;
1475 using_module_recursive(cref, module);
1481 rb_refinement_module_get_refined_class(
VALUE module)
1483 ID id_refined_class;
1485 CONST_ID(id_refined_class,
"__refined_class__");
1490 add_activated_refinement(
VALUE activated_refinements,
1506 superclass = refinement_superclass(superclass);
1510 while (refinement && refinement !=
klass) {
1532 ID id_refinements, id_activated_refinements,
1533 id_refined_class, id_defined_at;
1534 VALUE refinements, activated_refinements;
1545 ensure_class_or_module(
klass);
1549 CONST_ID(id_refinements,
"__refinements__");
1550 refinements =
rb_attr_get(module, id_refinements);
1551 if (
NIL_P(refinements)) {
1552 refinements = hidden_identity_hash_new();
1555 CONST_ID(id_activated_refinements,
"__activated_refinements__");
1556 activated_refinements =
rb_attr_get(module, id_activated_refinements);
1557 if (
NIL_P(activated_refinements)) {
1558 activated_refinements = hidden_identity_hash_new();
1560 activated_refinements);
1563 if (
NIL_P(refinement)) {
1564 VALUE superclass = refinement_superclass(
klass);
1566 RCLASS_SET_SUPER(refinement, superclass);
1568 CONST_ID(id_refined_class,
"__refined_class__");
1570 CONST_ID(id_defined_at,
"__defined_at__");
1573 add_activated_refinement(activated_refinements,
klass, refinement);
1580 ignored_block(
VALUE module,
const char *
klass)
1582 const char *anon =
"";
1585 anon =
", maybe for Module.new";
1587 rb_warn(
"%s""using doesn't call the given block""%s.",
klass, anon);
1603 if (prev_frame_func()) {
1605 "Module#using is not permitted in methods");
1607 if (prev_cfp && prev_cfp->
self !=
self) {
1611 ignored_block(module,
"Module#");
1621 CONST_ID(id_defined_at,
"__defined_at__");
1655 rb_mod_s_used_modules(
VALUE _)
1661 if (!
NIL_P(CREF_REFINEMENTS(cref))) {
1664 cref = CREF_NEXT(cref);
1769 ID id_extend_object, id_extended;
1771 CONST_ID(id_extend_object,
"extend_object");
1799 rb_warning(
"main.include in the wrapped load is effective only in wrapper module");
1823 ignored_block(module,
"main.");
1829 static const VALUE *
1836 if (VM_FRAME_RUBYFRAME_P(
cfp)) {
1854 const VALUE *
ptr = errinfo_place(ec);
1872 return get_errinfo();
1884 return GET_EC()->errinfo;
1923 set_backtrace(
err, val);
1937 rb_f_method_name(
VALUE _)
1939 ID fname = prev_frame_func();
1959 rb_f_callee_name(
VALUE _)
1961 ID fname = prev_frame_callee();
1982 f_current_dirname(
VALUE _)
2002 f_global_variables(
VALUE _)
2076 rb_mod_s_used_modules, 0);
2088 "include", top_include, -1);
2090 "using", top_using, 1);
struct rb_vm_protect_tag * protect_tag
void rb_prepend_module(VALUE klass, VALUE module)
#define ATOMIC_VALUE_EXCHANGE(var, val)
void ruby_stop(int ex)
Calls ruby_cleanup() and exits the process.
int rb_get_kwargs(VALUE keyword_hash, const ID *table, int required, int optional, VALUE *values)
void rb_threadptr_interrupt(rb_thread_t *th)
VALUE rb_check_funcall(VALUE, ID, int, const VALUE *)
VALUE rb_f_raise(int argc, VALUE *argv)
@ block_handler_type_iseq
#define STACK_UPPER(x, a, b)
void rb_include_module(VALUE klass, VALUE module)
VALUE rb_exc_new(VALUE etype, const char *ptr, long len)
void rb_objspace_call_finalizer(rb_objspace_t *objspace)
void * ruby_options(int argc, char **argv)
Processes command line arguments and compiles the Ruby source to execute.
#define rb_ec_raised_clear(ec)
void rb_class_modify_check(VALUE klass)
Asserts that klass is not a frozen class.
VALUE rb_ident_hash_new(void)
void rb_threadptr_unlock_all_locking_mutexes(rb_thread_t *th)
void rb_warn(const char *fmt,...)
int rb_block_given_p(void)
Determines if the current method is given a block.
int ruby_exec_node(void *n)
Runs the given compiled source.
void rb_warning(const char *fmt,...)
#define VM_ENV_INDEX_LAST_LVAR
#define RBASIC_CLEAR_CLASS(obj)
VALUE rb_funcallv_kw(VALUE, ID, int, const VALUE *, int)
int rb_vm_cframe_keyword_p(const rb_control_frame_t *cfp)
VALUE rb_search_class_path(VALUE)
VALUE rb_mod_constants(int, const VALUE *, VALUE)
int rb_empty_keyword_given_p(void)
VALUE rb_attr_get(VALUE, ID)
#define EXEC_EVENT_HOOK(ec_, flag_, self_, id_, called_id_, klass_, data_)
VALUE rb_obj_as_string(VALUE)
VALUE rb_module_new(void)
void rb_clear_method_cache_by_class(VALUE)
#define RB_TYPE_P(obj, type)
rb_cref_t * rb_vm_cref_replace_with_duplicated_cref(void)
#define rb_intern_const(str)
int ruby_run_node(void *n)
Runs the given compiled source and exits this process.
RUBY_EXTERN VALUE rb_cModule
void rb_obj_call_init_kw(VALUE obj, int argc, const VALUE *argv, int kw_splat)
void rb_need_block(void)
Declares that the current method needs a block.
struct rb_ensure_entry entry
#define CLASS_OR_MODULE_P(obj)
void rb_define_global_function(const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a global function.
rb_ensure_list_t * ensure_list
VALUE rb_ec_get_errinfo(const rb_execution_context_t *ec)
#define EC_JUMP_TAG(ec, st)
ID rb_frame_last_func(void)
Returns the ID of the last method in the call stack.
VALUE rb_check_string_type(VALUE)
#define THROW_DATA_P(err)
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
VALUE rb_make_exception(int argc, const VALUE *argv)
Make an Exception object from the list of arguments in a manner similar to Kernel#raise.
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
#define RUBY_VM_CHECK_INTS(ec)
void rb_vm_trap_exit(rb_vm_t *vm)
VALUE rb_hash_dup(VALUE hash)
RUBY_EXTERN VALUE rb_cClass
#define SPECIAL_CONST_P(x)
NORETURN(void rb_raise_jump(VALUE, VALUE))
void ruby_finalize(void)
Runs the VM finalization processes.
int ruby_setup(void)
Initializes the VM and builtin libraries.
int rb_vm_cframe_empty_keyword_p(const rb_control_frame_t *cfp)
rb_cref_t * rb_vm_cref(void)
rb_execution_context_t * ec
char ary[RSTRING_EMBED_LEN_MAX+1]
int ruby_cleanup(volatile int ex)
Destructs the VM.
void rb_undef_method(VALUE klass, const char *name)
VALUE rb_protect(VALUE(*proc)(VALUE), VALUE data, int *pstate)
Protects a function call from potential global escapes from the function.
#define VM_BLOCK_HANDLER_NONE
VALUE rb_f_global_variables(void)
#define rb_vm_register_special_exception(sp, e, m)
#define UNLIMITED_ARGUMENTS
void ruby_init(void)
Calls ruby_setup() and check error.
void rb_raise(VALUE exc, const char *fmt,...)
VALUE rb_ivar_get(VALUE, ID)
VALUE rb_obj_class(VALUE)
Equivalent to Object#class in Ruby.
VALUE rb_vm_frame_block_handler(const rb_control_frame_t *cfp)
void ruby_prog_init(void)
Defines built-in variables.
void rb_threadptr_check_signal(rb_thread_t *mth)
VALUE rb_yield_refine_block(VALUE refinement, VALUE refinements)
#define OBJ_WB_UNPROTECT(x)
void rb_ec_clear_all_trace_func(const rb_execution_context_t *ec)
void * ruby_process_options(int, char **)
RUBY_EXTERN VALUE rb_cBasicObject
#define INTERNAL_EXCEPTION_P(exc)
int ruby_vm_destruct(ruby_vm_t *vm)
#define RUBY_VM_VALID_CONTROL_FRAME_P(cfp, ecfp)
void ruby_init_stack(volatile VALUE *)
VALUE rb_const_list(void *)
ID rb_frame_this_func(void)
The original name of the current method.
enum rb_thread_status status
VALUE rb_vm_top_self(void)
void rb_jump_tag(int tag)
Continues the exception caught by rb_protect() and rb_eval_string_protect().
VALUE rb_hash_lookup(VALUE hash, VALUE key)
VALUE rb_errinfo(void)
The current exception in the current thread.
VALUE rb_ary_push(VALUE ary, VALUE item)
VALUE rb_include_class_new(VALUE module, VALUE super)
VALUE rb_vrescue2(VALUE(*b_proc)(VALUE), VALUE data1, VALUE(*r_proc)(VALUE, VALUE), VALUE data2, va_list args)
An equivalent of rescue clause.
VALUE rb_file_dirname(VALUE fname)
enum rb_iseq_constant_body::iseq_type type
const char * rb_source_location_cstr(int *pline)
void rb_interrupt(void)
Raises an Interrupt exception.
int rb_ec_set_raised(rb_execution_context_t *ec)
#define warn_print_str(x)
void * rb_mod_const_at(VALUE, void *)
void rb_frozen_error_raise(VALUE frozen_obj, const char *fmt,...)
void rb_hash_foreach(VALUE hash, rb_foreach_func *func, VALUE farg)
MJIT_STATIC void rb_error_arity(int argc, int min, int max)
#define RB_OBJ_WRITE(a, slot, b)
VALUE rb_obj_dup(VALUE)
Equivalent to Object#dup in Ruby.
#define CONST_ID(var, str)
void rb_extend_object(VALUE obj, VALUE module)
Extend the object with the module.
void rb_vm_encoded_insn_data_table_init(void)
#define RCLASS_REFINED_CLASS(c)
ID rb_frame_callee(void)
The name of the current method.
#define unknown_longjmp_status(status)
const MJIT_STATIC rb_callable_method_entry_t * rb_vm_frame_method_entry(const rb_control_frame_t *cfp)
VALUE rb_current_realfilepath(void)
RUBY_EXTERN VALUE rb_cObject
void rb_exc_raise(VALUE mesg)
Raises an exception in the current thread.
void ruby_default_signal(int)
RUBY_EXTERN VALUE rb_mKernel
void rb_set_errinfo(VALUE err)
Sets the current exception ($!) to the given value.
void ruby_sig_finalize(void)
MJIT_FUNC_EXPORTED void rb_vm_localjump_error(const char *mesg, VALUE value, int reason)
void rb_vm_rewind_cfp(rb_execution_context_t *ec, rb_control_frame_t *cfp)
VALUE rb_sprintf(const char *format,...)
#define PASS_PASSED_BLOCK_HANDLER()
void rb_thread_stop_timer_thread(void)
#define MEMCPY(p1, p2, type, n)
int ruby_executable_node(void *n, int *status)
Checks the return value of ruby_options().
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val)
void Init_vm_objects(void)
VALUE rb_ivar_defined(VALUE, ID)
void * rb_mod_const_of(VALUE, void *)
void Init_eval_method(void)
const char * rb_obj_classname(VALUE)
VALUE rb_singleton_class(VALUE obj)
Returns the singleton class of obj.
void rb_obj_call_init(VALUE obj, int argc, const VALUE *argv)
Calls #initialize method of obj with the given arguments.
VALUE rb_ec_backtrace_object(const rb_execution_context_t *ec)
#define RUBY_DTRACE_HOOK(name, arg)
MJIT_STATIC void rb_vm_pop_frame(rb_execution_context_t *ec)
#define RUBY_EVENT_C_RETURN
struct rb_method_definition_struct *const def
VALUE rb_get_backtrace(VALUE exc)
int rb_ec_reset_raised(rb_execution_context_t *ec)
VALUE rb_rescue2(VALUE(*b_proc)(VALUE), VALUE data1, VALUE(*r_proc)(VALUE, VALUE), VALUE data2,...)
An equivalent of rescue clause.
struct rb_vm_protect_tag * prev
int rb_keyword_given_p(void)
struct rb_iseq_constant_body * body
VALUE rb_ivar_set(VALUE, ID, VALUE)
void rb_exc_fatal(VALUE mesg)
Raises a fatal error in the current thread.
#define get_ec_errinfo(ec)
#define RCLASS_REFINED_BY_ANY
VALUE rb_f_trace_var(int, const VALUE *)
#define SAVE_ROOT_JMPBUF(th, stmt)
VALUE rb_ensure(VALUE(*b_proc)(VALUE), VALUE data1, VALUE(*e_proc)(VALUE), VALUE data2)
An equivalent to ensure clause.
void rb_define_virtual_variable(const char *q, type *w, void_type *e)
Define a function-backended global variable.
void rb_ec_clear_current_thread_trace_func(const rb_execution_context_t *ec)
VALUE rb_iseq_eval_main(const rb_iseq_t *iseq)
#define UNREACHABLE_RETURN(val)
VALUE rb_rescue(VALUE(*b_proc)(VALUE), VALUE data1, VALUE(*r_proc)(VALUE, VALUE), VALUE data2)
An equivalent of rescue clause.
void rb_thread_terminate_all(void)
void rb_define_private_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
struct rb_ensure_list * next
#define RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp)
VALUE rb_obj_is_kind_of(VALUE, VALUE)
Determines if obj is a kind of c.
VALUE rb_f_untrace_var(int, const VALUE *)