diff options
Diffstat (limited to 'eval.c')
-rw-r--r-- | eval.c | 146 |
1 files changed, 88 insertions, 58 deletions
@@ -70,8 +70,6 @@ ruby_setup(void) if (GET_VM()) return 0; - ruby_init_stack((void *)&state); - /* * Disable THP early before mallocs happen because we want this to * affect as many future pages as possible for CoW-friendliness @@ -80,7 +78,6 @@ ruby_setup(void) prctl(PR_SET_THP_DISABLE, 1, 0, 0, 0); #endif Init_BareVM(); - Init_heap(); rb_vm_encoded_insn_data_table_init(); Init_vm_objects(); @@ -115,10 +112,9 @@ ruby_options(int argc, char **argv) enum ruby_tag_type state; void *volatile iseq = 0; - ruby_init_stack((void *)&iseq); EC_PUSH_TAG(ec); if ((state = EC_EXEC_TAG()) == TAG_NONE) { - SAVE_ROOT_JMPBUF(GET_THREAD(), iseq = ruby_process_options(argc, argv)); + iseq = ruby_process_options(argc, argv); } else { rb_ec_clear_current_thread_trace_func(ec); @@ -200,16 +196,15 @@ rb_ec_cleanup(rb_execution_context_t *ec, enum ruby_tag_type ex) EC_PUSH_TAG(ec); if ((state = EC_EXEC_TAG()) == TAG_NONE) { - SAVE_ROOT_JMPBUF(th, { RUBY_VM_CHECK_INTS(ec); }); + RUBY_VM_CHECK_INTS(ec); step_0: step++; save_error = ec->errinfo; if (THROW_DATA_P(ec->errinfo)) ec->errinfo = Qnil; - ruby_init_stack(&message); /* exits with failure but silently when an exception raised * here */ - SAVE_ROOT_JMPBUF(th, rb_ec_teardown(ec)); + rb_ec_teardown(ec); step_1: step++; VALUE err = ec->errinfo; @@ -227,7 +222,7 @@ rb_ec_cleanup(rb_execution_context_t *ec, enum ruby_tag_type ex) mode1 = exiting_split(err, (mode0 & EXITING_WITH_STATUS) ? NULL : &sysex, &signaled); if (mode1 & EXITING_WITH_MESSAGE) { buf = rb_str_new(NULL, 0); - SAVE_ROOT_JMPBUF(th, rb_ec_error_print_detailed(ec, err, buf, Qundef)); + rb_ec_error_print_detailed(ec, err, buf, Qundef); message = buf; } } @@ -236,7 +231,7 @@ rb_ec_cleanup(rb_execution_context_t *ec, enum ruby_tag_type ex) /* protect from Thread#raise */ th->status = THREAD_KILLED; - SAVE_ROOT_JMPBUF(th, rb_ractor_terminate_all()); + rb_ractor_terminate_all(); step_3: step++; if (!NIL_P(buf = message)) { @@ -283,10 +278,7 @@ rb_ec_exec_node(rb_execution_context_t *ec, void *n) EC_PUSH_TAG(ec); if ((state = EC_EXEC_TAG()) == TAG_NONE) { - rb_thread_t *const th = rb_ec_thread_ptr(ec); - SAVE_ROOT_JMPBUF(th, { - rb_iseq_eval_main(iseq); - }); + rb_iseq_eval_main(iseq); } EC_POP_TAG(); return state; @@ -324,14 +316,12 @@ ruby_run_node(void *n) rb_ec_cleanup(ec, (NIL_P(ec->errinfo) ? TAG_NONE : TAG_RAISE)); return status; } - ruby_init_stack((void *)&status); return rb_ec_cleanup(ec, rb_ec_exec_node(ec, n)); } int ruby_exec_node(void *n) { - ruby_init_stack((void *)&n); return rb_ec_exec_node(GET_EC(), n); } @@ -419,11 +409,11 @@ rb_mod_s_constants(int argc, VALUE *argv, VALUE mod) return rb_const_list(data); } -/*! - * Asserts that \a klass is not a frozen class. - * \param[in] klass a \c Module object - * \exception RuntimeError if \a klass is not a class or frozen. - * \ingroup class +/** + * Asserts that `klass` is not a frozen class. + * @param[in] klass a `Module` object + * @exception RuntimeError if `klass` is not a class or frozen. + * @ingroup class */ void rb_class_modify_check(VALUE klass) @@ -437,7 +427,7 @@ rb_class_modify_check(VALUE klass) if (OBJ_FROZEN(klass)) { const char *desc; - if (FL_TEST(klass, FL_SINGLETON)) { + if (RCLASS_SINGLETON_P(klass)) { desc = "object"; klass = RCLASS_ATTACHED_OBJECT(klass); if (!SPECIAL_CONST_P(klass)) { @@ -472,7 +462,7 @@ rb_class_modify_check(VALUE klass) } } -NORETURN(static void rb_longjmp(rb_execution_context_t *, int, volatile VALUE, VALUE)); +NORETURN(static void rb_longjmp(rb_execution_context_t *, enum ruby_tag_type, volatile VALUE, VALUE)); static VALUE get_errinfo(void); #define get_ec_errinfo(ec) rb_ec_get_errinfo(ec) @@ -550,7 +540,7 @@ exc_setup_message(const rb_execution_context_t *ec, VALUE mesg, VALUE *cause) } static void -setup_exception(rb_execution_context_t *ec, int tag, volatile VALUE mesg, VALUE cause) +setup_exception(rb_execution_context_t *ec, enum ruby_tag_type tag, volatile VALUE mesg, VALUE cause) { VALUE e; int line; @@ -598,15 +588,15 @@ setup_exception(rb_execution_context_t *ec, int tag, volatile VALUE mesg, VALUE e = rb_obj_as_string(mesg); ec->errinfo = mesg; if (file && line) { - e = rb_sprintf("Exception `%"PRIsVALUE"' at %s:%d - %"PRIsVALUE"\n", + e = rb_sprintf("Exception '%"PRIsVALUE"' at %s:%d - %"PRIsVALUE"\n", rb_obj_class(mesg), file, line, e); } else if (file) { - e = rb_sprintf("Exception `%"PRIsVALUE"' at %s - %"PRIsVALUE"\n", + e = rb_sprintf("Exception '%"PRIsVALUE"' at %s - %"PRIsVALUE"\n", rb_obj_class(mesg), file, e); } else { - e = rb_sprintf("Exception `%"PRIsVALUE"' - %"PRIsVALUE"\n", + e = rb_sprintf("Exception '%"PRIsVALUE"' - %"PRIsVALUE"\n", rb_obj_class(mesg), e); } warn_print_str(e); @@ -654,7 +644,7 @@ rb_ec_setup_exception(const rb_execution_context_t *ec, VALUE mesg, VALUE cause) } static void -rb_longjmp(rb_execution_context_t *ec, int tag, volatile VALUE mesg, VALUE cause) +rb_longjmp(rb_execution_context_t *ec, enum ruby_tag_type tag, volatile VALUE mesg, VALUE cause) { mesg = exc_setup_message(ec, mesg, &cause); setup_exception(ec, tag, mesg, cause); @@ -664,10 +654,10 @@ rb_longjmp(rb_execution_context_t *ec, int tag, volatile VALUE mesg, VALUE cause static VALUE make_exception(int argc, const VALUE *argv, int isstr); -NORETURN(static void rb_exc_exception(VALUE mesg, int tag, VALUE cause)); +NORETURN(static void rb_exc_exception(VALUE mesg, enum ruby_tag_type tag, VALUE cause)); static void -rb_exc_exception(VALUE mesg, int tag, VALUE cause) +rb_exc_exception(VALUE mesg, enum ruby_tag_type tag, VALUE cause) { if (!NIL_P(mesg)) { mesg = make_exception(1, &mesg, FALSE); @@ -675,12 +665,12 @@ rb_exc_exception(VALUE mesg, int tag, VALUE cause) rb_longjmp(GET_EC(), tag, mesg, cause); } -/*! +/** * Raises an exception in the current thread. - * \param[in] mesg an Exception class or an \c Exception object. - * \exception always raises an instance of the given exception class or - * the given \c Exception object. - * \ingroup exception + * @param[in] mesg an Exception class or an `Exception` object. + * @exception always raises an instance of the given exception class or + * the given `Exception` object. + * @ingroup exception */ void rb_exc_raise(VALUE mesg) @@ -770,7 +760,8 @@ rb_f_raise(int argc, VALUE *argv) * object that returns an +Exception+ object when sent an +exception+ * message). The optional second parameter sets the message associated with * the exception (accessible via Exception#message), and the third parameter - * is an array of callback information (accessible via Exception#backtrace). + * is an array of callback information (accessible via + * Exception#backtrace_locations or Exception#backtrace). * The +cause+ of the generated exception (accessible via Exception#cause) * is automatically set to the "current" exception (<code>$!</code>), if any. * An alternative value, either an +Exception+ object or +nil+, can be @@ -780,7 +771,7 @@ rb_f_raise(int argc, VALUE *argv) * <code>begin...end</code> blocks. * * raise "Failed to create socket" - * raise ArgumentError, "No parameters", caller + * raise ArgumentError, "No parameters", caller_locations */ static VALUE @@ -980,7 +971,7 @@ rb_protect(VALUE (* proc) (VALUE), VALUE data, int *pstate) EC_PUSH_TAG(ec); if ((state = EC_EXEC_TAG()) == TAG_NONE) { - SAVE_ROOT_JMPBUF(rb_ec_thread_ptr(ec), result = (*proc) (data)); + result = (*proc)(data); } else { rb_vm_rewind_cfp(ec, cfp); @@ -994,7 +985,7 @@ rb_protect(VALUE (* proc) (VALUE), VALUE data, int *pstate) VALUE rb_ensure(VALUE (*b_proc)(VALUE), VALUE data1, VALUE (*e_proc)(VALUE), VALUE data2) { - int state; + enum ruby_tag_type state; volatile VALUE result = Qnil; VALUE errinfo; rb_execution_context_t * volatile ec = GET_EC(); @@ -1285,12 +1276,6 @@ rb_using_refinement(rb_cref_t *cref, VALUE klass, VALUE module) RCLASS_M_TBL(c) = RCLASS_M_TBL(module); - module = RCLASS_SUPER(module); - while (module && module != klass) { - c = RCLASS_SET_SUPER(c, rb_include_class_new(module, RCLASS_SUPER(c))); - RB_OBJ_WRITE(c, &RCLASS_REFINED_CLASS(c), klass); - module = RCLASS_SUPER(module); - } rb_hash_aset(CREF_REFINEMENTS(cref), klass, iclass); } @@ -1341,14 +1326,21 @@ rb_using_module(const rb_cref_t *cref, VALUE module) { Check_Type(module, T_MODULE); using_module_recursive(cref, module); - rb_clear_method_cache_all(); + rb_clear_all_refinement_method_cache(); } /* * call-seq: - * refined_class -> class + * target -> class_or_module * - * Return the class refined by the receiver. + * Return the class or module refined by the receiver. + * + * module M + * refine String do + * end + * end + * + * M.refinements[0].target # => String */ VALUE rb_refinement_module_get_refined_class(VALUE module) @@ -1359,6 +1351,21 @@ rb_refinement_module_get_refined_class(VALUE module) return rb_attr_get(module, id_refined_class); } +/* + * call-seq: + * refined_class -> class + * + * Deprecated; prefer #target. + * + * Return the class refined by the receiver. + */ +static VALUE +rb_refinement_refined_class(VALUE module) +{ + rb_warn_deprecated_to_remove("3.4", "Refinement#refined_class", "Refinement#target"); + return rb_refinement_module_get_refined_class(module); +} + static void add_activated_refinement(VALUE activated_refinements, VALUE klass, VALUE refinement) @@ -1775,6 +1782,16 @@ rb_obj_extend(int argc, VALUE *argv, VALUE obj) return obj; } +VALUE +rb_top_main_class(const char *method) +{ + VALUE klass = GET_THREAD()->top_wrapper; + + if (!klass) return rb_cObject; + rb_warning("main.%s in the wrapped load is effective only in wrapper module", method); + return klass; +} + /* * call-seq: * include(module, ...) -> self @@ -1787,13 +1804,7 @@ rb_obj_extend(int argc, VALUE *argv, VALUE obj) static VALUE top_include(int argc, VALUE *argv, VALUE self) { - rb_thread_t *th = GET_THREAD(); - - if (th->top_wrapper) { - rb_warning("main.include in the wrapped load is effective only in wrapper module"); - return rb_mod_include(argc, argv, th->top_wrapper); - } - return rb_mod_include(argc, argv, rb_cObject); + return rb_mod_include(argc, argv, rb_top_main_class("include")); } /* @@ -1807,7 +1818,7 @@ top_include(int argc, VALUE *argv, VALUE self) static VALUE top_using(VALUE self, VALUE module) { - const rb_cref_t *cref = CREF_NEXT(rb_vm_cref());; + const rb_cref_t *cref = CREF_NEXT(rb_vm_cref()); rb_control_frame_t *prev_cfp = previous_frame(GET_EC()); rb_thread_t *th = GET_THREAD(); @@ -2000,7 +2011,7 @@ f_global_variables(VALUE _) * +Proc+ object) or block is executed whenever the variable * is assigned. The block or +Proc+ object receives the * variable's new value as a parameter. Also see - * Kernel::untrace_var. + * #untrace_var. * * trace_var :$_, proc {|v| puts "$_ is now '#{v}'" } * $_ = "hello" @@ -2067,7 +2078,8 @@ Init_eval(void) rb_mod_s_used_refinements, 0); rb_undef_method(rb_cClass, "refine"); rb_define_private_method(rb_cRefinement, "import_methods", refinement_import_methods, -1); - rb_define_method(rb_cRefinement, "refined_class", rb_refinement_module_get_refined_class, 0); + rb_define_method(rb_cRefinement, "target", rb_refinement_module_get_refined_class, 0); + rb_define_method(rb_cRefinement, "refined_class", rb_refinement_refined_class, 0); rb_undef_method(rb_cRefinement, "append_features"); rb_undef_method(rb_cRefinement, "prepend_features"); rb_undef_method(rb_cRefinement, "extend_object"); @@ -2096,3 +2108,21 @@ Init_eval(void) id_signo = rb_intern_const("signo"); id_status = rb_intern_const("status"); } + +int +rb_errno(void) +{ + return *rb_orig_errno_ptr(); +} + +void +rb_errno_set(int e) +{ + *rb_orig_errno_ptr() = e; +} + +int * +rb_errno_ptr(void) +{ + return rb_orig_errno_ptr(); +} |