aboutsummaryrefslogtreecommitdiffstats
path: root/eval.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-04-17 02:41:00 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-04-17 02:41:00 +0000
commit8cad54a696cba1f2585cdca8d0f5e210d19e2662 (patch)
treea2618c43fd928fa8b0d64c9128fe2b75f2faa122 /eval.c
parentbf8f8a0ec1e75200f4217e4715cd9d1f45140c90 (diff)
downloadruby-8cad54a696cba1f2585cdca8d0f5e210d19e2662.tar.gz
eval.c: copy before cause setup
* eval.c (setup_exception): copy frozen exception before setting up a cause not only a backtrace. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58381 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/eval.c b/eval.c
index 7f500b8d64..15a38c5d71 100644
--- a/eval.c
+++ b/eval.c
@@ -481,18 +481,17 @@ setup_exception(rb_thread_t *th, int tag, volatile VALUE mesg, VALUE cause)
mesg = rb_exc_new(rb_eRuntimeError, 0, 0);
nocause = 0;
}
- if (cause != Qundef) {
- exc_setup_cause(mesg, cause);
- }
- else if (nocause) {
- exc_setup_cause(mesg, Qnil);
- }
- else if (!rb_ivar_defined(mesg, id_cause)) {
- exc_setup_cause(mesg, get_thread_errinfo(th));
+ if (cause == Qundef) {
+ if (nocause) {
+ cause = Qnil;
+ }
+ else if (!rb_ivar_defined(mesg, id_cause)) {
+ cause = get_thread_errinfo(th);
+ }
}
file = rb_source_loc(&line);
- if (file && !NIL_P(mesg)) {
+ if ((file && !NIL_P(mesg)) || (cause != Qundef)) {
VALUE at;
int status;
@@ -501,11 +500,16 @@ setup_exception(rb_thread_t *th, int tag, volatile VALUE mesg, VALUE cause)
VALUE bt;
if (rb_threadptr_set_raised(th)) goto fatal;
bt = rb_get_backtrace(mesg);
- if (NIL_P(bt)) {
- at = rb_threadptr_backtrace_object(th);
+ if (!NIL_P(bt) || cause == Qundef) {
if (OBJ_FROZEN(mesg)) {
mesg = rb_obj_dup(mesg);
}
+ }
+ if (cause != Qundef) {
+ exc_setup_cause(mesg, cause);
+ }
+ if (NIL_P(bt)) {
+ at = rb_threadptr_backtrace_object(th);
rb_ivar_set(mesg, idBt_locations, at);
set_backtrace(mesg, at);
}