diff options
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | ext/bigdecimal/bigdecimal.c | 2 | ||||
-rw-r--r-- | test/bigdecimal/test_bigdecimal.rb | 6 |
3 files changed, 17 insertions, 0 deletions
@@ -1,3 +1,12 @@ +Mon Jan 7 23:43:00 2013 Kenta Murata <mrkn@mrkn.jp> + + * ext/bigdecimal/bigdecimal.c (rmpd_power_by_big_decimal): + add RB_GC_GUARD to prevent the immediate object is GCed too early. + This patch was made by Yusuke Endoh. [Bug #7044] [ruby-core:47632] + + * test/bigdecimal/test_bigdecimal.rb: add a reproduction test for + the issue [Bug #7044] + Mon Jan 7 21:40:36 2013 Shugo Maeda <shugo@ruby-lang.org> * vm_method.c (Init_eval_method): main.public and main.private diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c index b161bc95ca..7cd0044532 100644 --- a/ext/bigdecimal/bigdecimal.c +++ b/ext/bigdecimal/bigdecimal.c @@ -2046,6 +2046,7 @@ static VALUE rmpd_power_by_big_decimal(Real const* x, Real const* exp, ssize_t const n) { VALUE log_x, multiplied, y; + volatile VALUE obj = exp->obj; if (VpIsZero(exp)) { return ToValue(VpCreateRbObject(n, "1")); @@ -2054,6 +2055,7 @@ rmpd_power_by_big_decimal(Real const* x, Real const* exp, ssize_t const n) log_x = BigMath_log(x->obj, SSIZET2NUM(n+1)); multiplied = BigDecimal_mult2(exp->obj, log_x, SSIZET2NUM(n+1)); y = BigMath_exp(multiplied, SSIZET2NUM(n)); + RB_GC_GUARD(obj); return y; } diff --git a/test/bigdecimal/test_bigdecimal.rb b/test/bigdecimal/test_bigdecimal.rb index a06adb1356..51d2e8f309 100644 --- a/test/bigdecimal/test_bigdecimal.rb +++ b/test/bigdecimal/test_bigdecimal.rb @@ -874,6 +874,12 @@ class TestBigDecimal < Test::Unit::TestCase assert_match(/^#<BigDecimal:[0-9a-f]+,'0.12345678E4',#{prec}\(#{maxprec}\)>$/, x.inspect) end + def test_power + assert_nothing_raised(TypeError, '[ruby-core:47632]') do + 1000.times { BigDecimal.new('1001.10')**0.75 } + end + end + def test_power_with_nil assert_raise(TypeError) do BigDecimal(3) ** nil |