summaryrefslogtreecommitdiff
path: root/eval.c
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-22 05:38:08 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-22 05:38:08 +0000
commit22a97cbf830ff18042a8b59df8eaa03ab29bbc30 (patch)
tree26d34bf8e12784cbe30119d3a32aa5e199294c99 /eval.c
parent82e65291b1851895fd2d6eedcf7ed53348e5d2a0 (diff)
merge revision(s) 53819,53822: [Backport #12068]
* eval.c (setup_exception): set the cause only if it is explicitly given or not set yet. [Bug #12068] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@54675 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/eval.c b/eval.c
index dc5af43928..65c604c3b2 100644
--- a/eval.c
+++ b/eval.c
@@ -24,6 +24,8 @@ NORETURN(void rb_raise_jump(VALUE, VALUE));
VALUE rb_eLocalJumpError;
VALUE rb_eSysStackError;
+static ID id_cause;
+
#define exception_error GET_VM()->special_exceptions[ruby_error_reenter]
#include "eval_error.c"
@@ -450,9 +452,6 @@ static VALUE get_thread_errinfo(rb_thread_t *th);
static VALUE
exc_setup_cause(VALUE exc, VALUE cause)
{
- ID id_cause;
- CONST_ID(id_cause, "cause");
-
#if SUPPORT_JOKE
if (NIL_P(cause)) {
ID id_true_cause;
@@ -496,10 +495,15 @@ 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) {
- cause = nocause ? Qnil : get_thread_errinfo(th);
+ 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));
}
- exc_setup_cause(mesg, cause);
file = rb_sourcefile();
if (file) line = rb_sourceline();
@@ -1710,4 +1714,6 @@ Init_eval(void)
rb_define_global_function("untrace_var", rb_f_untrace_var, -1); /* in variable.c */
rb_vm_register_special_exception(ruby_error_reenter, rb_eFatal, "exception reentered");
+
+ id_cause = rb_intern_const("cause");
}