summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-12-28 21:00:45 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-12-28 21:00:45 +0000
commitd785c36b885f2cee8353954b87cf5624d387a769 (patch)
tree07e43222d10fe2890179056a51a72ec5f49f9ed7
parent543a8b5e3d6869ab2312019afdd7ec277125b626 (diff)
merge revision(s) 57137: [Backport #13043]
eval.c: fix circular cause * eval.c (exc_setup_cause): always set cause of cause to get rid of circular references. [ruby-core:78688] [Bug #13043] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@57229 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--eval.c5
-rw-r--r--test/ruby/test_exception.rb20
-rw-r--r--version.h6
4 files changed, 32 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 41eb04b2b5..8f6f8d983d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Thu Dec 29 06:00:08 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * eval.c (exc_setup_cause): always set cause of cause to get rid
+ of circular references. [ruby-core:78688] [Bug #13043]
+
Tue Dec 27 20:43:54 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
* time.c (usec2subsecx): fix return type, which is a numeric object but
diff --git a/eval.c b/eval.c
index fbd28565ed..43d1948f2f 100644
--- a/eval.c
+++ b/eval.c
@@ -466,8 +466,11 @@ exc_setup_cause(VALUE exc, VALUE cause)
}
}
#endif
- if (!NIL_P(cause) && cause != exc) {
+ if (!NIL_P(cause) && cause != exc && BUILTIN_TYPE(cause) != T_NODE) {
rb_ivar_set(exc, id_cause, cause);
+ if (!rb_ivar_defined(cause, id_cause)) {
+ rb_ivar_set(cause, id_cause, Qnil);
+ }
}
return exc;
}
diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb
index 3268096463..0e0179fd5f 100644
--- a/test/ruby/test_exception.rb
+++ b/test/ruby/test_exception.rb
@@ -717,6 +717,26 @@ end.join
assert_equal({}, e.arg, bug)
end
+ def test_circular_cause
+ bug13043 = '[ruby-core:78688] [Bug #13043]'
+ begin
+ begin
+ raise "error 1"
+ ensure
+ orig_error = $!
+ begin
+ raise "error 2"
+ rescue => err
+ raise orig_error
+ end
+ end
+ rescue => x
+ end
+ assert_equal(orig_error, x)
+ assert_equal(orig_error, err.cause)
+ assert_nil(orig_error.cause, bug13043)
+ end
+
def test_anonymous_message
assert_in_out_err([], "raise Class.new(RuntimeError), 'foo'", [], /foo\n/)
end
diff --git a/version.h b/version.h
index 85ff56b277..ed93db84f7 100644
--- a/version.h
+++ b/version.h
@@ -1,10 +1,10 @@
#define RUBY_VERSION "2.2.7"
-#define RUBY_RELEASE_DATE "2016-12-27"
-#define RUBY_PATCHLEVEL 416
+#define RUBY_RELEASE_DATE "2016-12-29"
+#define RUBY_PATCHLEVEL 417
#define RUBY_RELEASE_YEAR 2016
#define RUBY_RELEASE_MONTH 12
-#define RUBY_RELEASE_DAY 27
+#define RUBY_RELEASE_DAY 29
#include "ruby/version.h"