[前][次][番号順一覧][スレッド一覧]

ruby-changes:26683

From: mrkn <ko1@a...>
Date: Mon, 7 Jan 2013 23:43:31 +0900 (JST)
Subject: [ruby-changes:26683] mrkn:r38734 (trunk): * ext/bigdecimal/bigdecimal.c (rmpd_power_by_big_decimal):

mrkn	2013-01-07 23:42:52 +0900 (Mon, 07 Jan 2013)

  New Revision: 38734

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38734

  Log:
    * 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]

  Modified files:
    trunk/ChangeLog
    trunk/ext/bigdecimal/bigdecimal.c
    trunk/test/bigdecimal/test_bigdecimal.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38733)
+++ ChangeLog	(revision 38734)
@@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Jan  7 23:43:00 2013  Kenta Murata  <mrkn@m...>
+
+	* 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@r...>
 
 	* vm_method.c (Init_eval_method): main.public and main.private
Index: ext/bigdecimal/bigdecimal.c
===================================================================
--- ext/bigdecimal/bigdecimal.c	(revision 38733)
+++ ext/bigdecimal/bigdecimal.c	(revision 38734)
@@ -2046,6 +2046,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L2046
 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, https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L2055
     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;
 }
Index: test/bigdecimal/test_bigdecimal.rb
===================================================================
--- test/bigdecimal/test_bigdecimal.rb	(revision 38733)
+++ test/bigdecimal/test_bigdecimal.rb	(revision 38734)
@@ -874,6 +874,12 @@ class TestBigDecimal < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/bigdecimal/test_bigdecimal.rb#L874
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]