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.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46593 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-06-28 04:58:25 +00:00
parent 76bb597728
commit 3ff85b795a
5 changed files with 32 additions and 18 deletions

View File

@ -1,3 +1,10 @@
Sat Jun 28 13:58:19 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
* 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@ruby-lang.org> Sat Jun 28 04:08:22 2014 NARUSE, Yui <naruse@ruby-lang.org>
* lib/uri/mailto.rb: update to latest specs, RFC 6068 and HTML5. * lib/uri/mailto.rb: update to latest specs, RFC 6068 and HTML5.

View File

@ -36,6 +36,8 @@ firstline, predefined = __LINE__+1, %[\
to_a to_a
to_s to_s
to_i to_i
bt
bt_locations
_ UScore _ UScore
"/*NULL*/" NULL "/*NULL*/" NULL

21
eval.c
View File

@ -469,7 +469,6 @@ sysstack_error_p(VALUE exc)
static void static void
setup_exception(rb_thread_t *th, int tag, volatile VALUE mesg, VALUE cause) setup_exception(rb_thread_t *th, int tag, volatile VALUE mesg, VALUE cause)
{ {
VALUE at;
VALUE e; VALUE e;
const char *file = 0; const char *file = 0;
volatile int line = 0; volatile int line = 0;
@ -492,24 +491,22 @@ setup_exception(rb_thread_t *th, int tag, volatile VALUE mesg, VALUE cause)
file = rb_sourcefile(); file = rb_sourcefile();
if (file) line = rb_sourceline(); if (file) line = rb_sourceline();
if (file && !NIL_P(mesg)) { if (file && !NIL_P(mesg)) {
VALUE at;
if (sysstack_error_p(mesg)) {
at = rb_vm_backtrace_object();
if (mesg == sysstack_error) { if (mesg == sysstack_error) {
/* machine stack overflow, reduce too long backtrace */ VALUE ruby_vm_sysstack_error_copy(void);
ID func = rb_frame_this_func(); mesg = ruby_vm_sysstack_error_copy();
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);
} }
at = rb_ary_new3(1, at); rb_ivar_set(mesg, idBt, at);
mesg = rb_obj_dup(mesg); rb_ivar_set(mesg, idBt_locations, at);
rb_iv_set(mesg, "bt", 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(); at = rb_vm_backtrace_object();
if (OBJ_FROZEN(mesg)) { if (OBJ_FROZEN(mesg)) {
mesg = rb_obj_dup(mesg); mesg = rb_obj_dup(mesg);
} }
rb_iv_set(mesg, "bt_locations", at); rb_ivar_set(mesg, idBt_locations, at);
set_backtrace(mesg, at); set_backtrace(mesg, at);
} }
} }

View File

@ -529,8 +529,10 @@ end.join
end end
def test_stackoverflow def test_stackoverflow
e = assert_raise(SystemStackError){m} feature6216 = '[ruby-core:43794] [Feature #6216]'
assert_operator(e.backtrace.size, :>, 10) e = assert_raise(SystemStackError, feature6216) {m}
level = e.backtrace.size
assert_operator(level, :>, 10, feature6216)
end end
def test_machine_stackoverflow def test_machine_stackoverflow

View File

@ -24,12 +24,18 @@
static rb_control_frame_t *vm_get_ruby_level_caller_cfp(rb_thread_t *th, rb_control_frame_t *cfp); static rb_control_frame_t *vm_get_ruby_level_caller_cfp(rb_thread_t *th, rb_control_frame_t *cfp);
static void VALUE
vm_stackoverflow(void) ruby_vm_sysstack_error_copy(void)
{ {
VALUE e = rb_obj_alloc(rb_eSysStackError); VALUE e = rb_obj_alloc(rb_eSysStackError);
rb_obj_copy_ivar(e, sysstack_error); 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 * static inline rb_control_frame_t *