mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
19768b6cac
commit
1be6a498ba
3 changed files with 17 additions and 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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue