ruby-changes:34512
From: nobu <ko1@a...>
Date: Sat, 28 Jun 2014 13:58:34 +0900 (JST)
Subject: [ruby-changes:34512] nobu:r46593 (trunk): eval.c: no method calls at stack overflow
nobu 2014-06-28 13:58:25 +0900 (Sat, 28 Jun 2014) New Revision: 46593 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=46593 Log: eval.c: no method calls at stack overflow * eval.c (setup_exception): get rid of method calls before raising stack overflow, not to cause stack overflow again. * defs/id.def: add IDs for backtraces. Modified files: trunk/ChangeLog trunk/defs/id.def trunk/eval.c trunk/test/ruby/test_exception.rb trunk/vm_insnhelper.c Index: defs/id.def =================================================================== --- defs/id.def (revision 46592) +++ defs/id.def (revision 46593) @@ -36,6 +36,8 @@ firstline, predefined = __LINE__+1, %[\ https://github.com/ruby/ruby/blob/trunk/defs/id.def#L36 to_a to_s to_i + bt + bt_locations _ UScore "/*NULL*/" NULL Index: ChangeLog =================================================================== --- ChangeLog (revision 46592) +++ ChangeLog (revision 46593) @@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sat Jun 28 13:58:19 2014 Nobuyoshi Nakada <nobu@r...> + + * eval.c (setup_exception): get rid of method calls before raising + stack overflow, not to cause stack overflow again. + + * defs/id.def: add IDs for backtraces. + Sat Jun 28 04:08:22 2014 NARUSE, Yui <naruse@r...> * lib/uri/mailto.rb: update to latest specs, RFC 6068 and HTML5. Index: eval.c =================================================================== --- eval.c (revision 46592) +++ eval.c (revision 46593) @@ -469,7 +469,6 @@ sysstack_error_p(VALUE exc) https://github.com/ruby/ruby/blob/trunk/eval.c#L469 static void setup_exception(rb_thread_t *th, int tag, volatile VALUE mesg, VALUE cause) { - VALUE at; VALUE e; const char *file = 0; volatile int line = 0; @@ -492,24 +491,22 @@ setup_exception(rb_thread_t *th, int tag https://github.com/ruby/ruby/blob/trunk/eval.c#L491 file = rb_sourcefile(); if (file) line = rb_sourceline(); if (file && !NIL_P(mesg)) { - if (mesg == sysstack_error) { - /* machine stack overflow, reduce too long backtrace */ - ID func = rb_frame_this_func(); - at = rb_enc_sprintf(rb_usascii_encoding(), "%s:%d", file, line); - if (func) { - VALUE name = rb_id2str(func); - if (name) rb_str_catf(at, ":in `%"PRIsVALUE"'", name); + VALUE at; + if (sysstack_error_p(mesg)) { + at = rb_vm_backtrace_object(); + if (mesg == sysstack_error) { + VALUE ruby_vm_sysstack_error_copy(void); + mesg = ruby_vm_sysstack_error_copy(); } - at = rb_ary_new3(1, at); - mesg = rb_obj_dup(mesg); - rb_iv_set(mesg, "bt", at); + rb_ivar_set(mesg, idBt, at); + rb_ivar_set(mesg, idBt_locations, at); } - else if (sysstack_error_p(mesg) || NIL_P(at = get_backtrace(mesg))) { + else if (NIL_P(get_backtrace(mesg))) { at = rb_vm_backtrace_object(); if (OBJ_FROZEN(mesg)) { mesg = rb_obj_dup(mesg); } - rb_iv_set(mesg, "bt_locations", at); + rb_ivar_set(mesg, idBt_locations, at); set_backtrace(mesg, at); } } Index: vm_insnhelper.c =================================================================== --- vm_insnhelper.c (revision 46592) +++ vm_insnhelper.c (revision 46593) @@ -24,12 +24,18 @@ https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L24 static rb_control_frame_t *vm_get_ruby_level_caller_cfp(rb_thread_t *th, rb_control_frame_t *cfp); -static void -vm_stackoverflow(void) +VALUE +ruby_vm_sysstack_error_copy(void) { VALUE e = rb_obj_alloc(rb_eSysStackError); rb_obj_copy_ivar(e, sysstack_error); - rb_exc_raise(e); + return e; +} + +static void +vm_stackoverflow(void) +{ + rb_exc_raise(ruby_vm_sysstack_error_copy()); } static inline rb_control_frame_t * Index: test/ruby/test_exception.rb =================================================================== --- test/ruby/test_exception.rb (revision 46592) +++ test/ruby/test_exception.rb (revision 46593) @@ -529,8 +529,10 @@ end.join https://github.com/ruby/ruby/blob/trunk/test/ruby/test_exception.rb#L529 end def test_stackoverflow - e = assert_raise(SystemStackError){m} - assert_operator(e.backtrace.size, :>, 10) + feature6216 = '[ruby-core:43794] [Feature #6216]' + e = assert_raise(SystemStackError, feature6216) {m} + level = e.backtrace.size + assert_operator(level, :>, 10, feature6216) end def test_machine_stackoverflow -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/