From 1be6a498ba8d1c113d4e0e7547d01c86c188e5c4 Mon Sep 17 00:00:00 2001 From: mrkn Date: Mon, 7 Jan 2013 14:42:52 +0000 Subject: * 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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38734 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 9 +++++++++ ext/bigdecimal/bigdecimal.c | 2 ++ test/bigdecimal/test_bigdecimal.rb | 6 ++++++ 3 files changed, 17 insertions(+) diff --git a/ChangeLog b/ChangeLog index ef2bfb6531..d355eefecc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Mon Jan 7 23:43:00 2013 Kenta Murata + + * 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 * 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(/^#$/, 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 -- cgit v1.2.3