aboutsummaryrefslogtreecommitdiffstats
path: root/eval.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-04-20 03:20:44 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-04-20 03:20:44 +0000
commitcc1757bce8abc852963b9253e930e2599055c653 (patch)
tree3075b60ec0e512b6e30e4b566d3fc68f5fdfe094 /eval.c
parent52ecaf65b0ff40492c5a85cdd9f5cd34201b4a0e (diff)
downloadruby-cc1757bce8abc852963b9253e930e2599055c653.tar.gz
* eval.c (ruby_cleanup): fixed access to out of bound, and inversed
the order of errinfos. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12202 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/eval.c b/eval.c
index a7f5cbbd0b..3755c6b1a2 100644
--- a/eval.c
+++ b/eval.c
@@ -153,38 +153,42 @@ ruby_finalize(void)
int
ruby_cleanup(int ex)
{
- int state, i;
- volatile VALUE errs[2] = {GET_THREAD()->errinfo, 0};
- rb_vm_t *vm = GET_THREAD()->vm;
+ int state, nerr;
+ VALUE err;
+ rb_thread_t *th = GET_THREAD();
+ volatile VALUE errs[2];
+ rb_vm_t *vm = th->vm;
- GET_THREAD()->safe_level = 0;
+ errs[0] = th->errinfo;
+ th->safe_level = 0;
Init_stack((void *)&state);
+ ruby_finalize_0();
+ errs[1] = th->errinfo;
PUSH_THREAD_TAG();
if ((state = EXEC_TAG()) == 0) {
- ruby_finalize_0();
+ rb_thread_terminate_all();
}
else if (ex == 0) {
ex = state;
}
- errs[1] = GET_THREAD()->errinfo;
- rb_thread_terminate_all();
- GET_THREAD()->errinfo = errs[0];
+ th->errinfo = errs[0];
ex = error_handle(ex);
ruby_finalize_1();
POP_THREAD_TAG();
rb_thread_stop_timer_thread();
- for (i = 2; i > 0; --i) {
- VALUE err = errs[i];
+ for (nerr = sizeof(errs) / sizeof(errs[0]); nerr;) {
+ if (!RTEST(err = errs[--nerr])) continue;
/* th->errinfo contains a NODE while break'ing */
- if (!RTEST(err) || (TYPE(err) == T_NODE)) continue;
+ if (TYPE(err) == T_NODE) continue;
if (rb_obj_is_kind_of(err, rb_eSystemExit)) {
return sysexit_status(err);
}
else if (rb_obj_is_kind_of(err, rb_eSignal)) {
- ruby_default_signal(NUM2INT(rb_iv_get(err, "signo")));
+ VALUE sig = rb_iv_get(err, "signo");
+ ruby_default_signal(NUM2INT(sig));
}
}