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

ruby-changes:15737

From: nobu <ko1@a...>
Date: Sat, 8 May 2010 11:08:13 +0900 (JST)
Subject: [ruby-changes:15737] Ruby:r27665 (ruby_1_9_2, ruby_1_8, trunk): * ext/bigdecimal/bigdecimal.c (VpAlloc): ensure buf does not get

nobu	2010-05-08 11:07:43 +0900 (Sat, 08 May 2010)

  New Revision: 27665

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

  Log:
    * ext/bigdecimal/bigdecimal.c (VpAlloc): ensure buf does not get
      collected.  based on a patch masaya tarui at [ruby-dev:41213].

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

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 27664)
+++ ChangeLog	(revision 27665)
@@ -1,3 +1,8 @@
+Sat May  8 11:07:41 2010  Nobuyoshi Nakada  <nobu@r...>
+
+	* ext/bigdecimal/bigdecimal.c (VpAlloc): ensure buf does not get
+	  collected.  based on a patch masaya tarui at [ruby-dev:41213].
+
 Sat May  8 10:03:39 2010  Tanaka Akira  <akr@f...>
 
 	* ext/socket/lib/socket.rb (BasicSocket#connect_address): MacOS X 10.6
Index: ext/bigdecimal/bigdecimal.c
===================================================================
--- ext/bigdecimal/bigdecimal.c	(revision 27664)
+++ ext/bigdecimal/bigdecimal.c	(revision 27665)
@@ -2593,7 +2593,7 @@
     int  sign=1;
     Real *vp = NULL;
     U_LONG mf = VpGetPrecLimit();
-    volatile VALUE buf;
+    VALUE buf;
 
     mx = (mx + BASE_FIG - 1) / BASE_FIG + 1;    /* Determine allocation unit. */
     if(szVal) {
@@ -2621,7 +2621,7 @@
 
     /* Skip all '_' after digit: 2006-6-30 */
     ni = 0;
-    buf = rb_str_new(0,strlen(szVal)+1);
+    buf = rb_str_tmp_new(strlen(szVal)+1);
     psz = RSTRING_PTR(buf);
     i   = 0;
     ipn = 0;
@@ -2720,6 +2720,7 @@
     vp->MaxPrec = mx;        /* set max precision */
     VpSetZero(vp,sign);
     VpCtoV(vp, &(szVal[ipn]), ni, &(szVal[ipf]), nf, &(szVal[ipe]), ne);
+    rb_str_resize(buf, 0);
     return vp;
 }
 
Index: test/bigdecimal/test_bigdecimal.rb
===================================================================
--- test/bigdecimal/test_bigdecimal.rb	(revision 27664)
+++ test/bigdecimal/test_bigdecimal.rb	(revision 27665)
@@ -698,4 +698,15 @@
     assert_equal(BigDecimal::SIGN_POSITIVE_ZERO, BigDecimal.new("1E-1" + "0" * 10000).sign)
     assert_equal(BigDecimal::SIGN_NEGATIVE_ZERO, BigDecimal.new("-1E-1" + "0" * 10000).sign)
   end
+
+  def test_gc
+    bug3258 = '[ruby-dev:41213]'
+    stress, GC.stress = GC.stress, true
+    1000.times do |i|
+      b = BigDecimal.new("1"+"0"*i).to_s
+      assert_equal([1, "1", 10, i+1], b.split, bug3258)
+    end
+  ensure
+    GC.stress = stress
+  end
 end
Index: ruby_1_8/ext/bigdecimal/bigdecimal.c
===================================================================
--- ruby_1_8/ext/bigdecimal/bigdecimal.c	(revision 27664)
+++ ruby_1_8/ext/bigdecimal/bigdecimal.c	(revision 27665)
@@ -2531,7 +2531,7 @@
     int  sign=1;
     Real *vp = NULL;
     U_LONG mf = VpGetPrecLimit();
-    volatile VALUE buf;
+    VALUE buf;
 
     mx = (mx + BASE_FIG - 1) / BASE_FIG + 1;    /* Determine allocation unit. */
     if(szVal) {
@@ -2559,7 +2559,7 @@
 
     /* Skip all '_' after digit: 2006-6-30 */
     ni = 0;
-    buf = rb_str_new(0,strlen(szVal)+1);
+    buf = rb_str_tmp_new(strlen(szVal)+1);
     psz = RSTRING_PTR(buf);
     i   = 0;
     ipn = 0;
@@ -2658,6 +2658,7 @@
     vp->MaxPrec = mx;        /* set max precision */
     VpSetZero(vp,sign);
     VpCtoV(vp, &(szVal[ipn]), ni, &(szVal[ipf]), nf, &(szVal[ipe]), ne);
+    rb_str_resize(buf, 0);
     return vp;
 }
 
Index: ruby_1_8/ChangeLog
===================================================================
--- ruby_1_8/ChangeLog	(revision 27664)
+++ ruby_1_8/ChangeLog	(revision 27665)
@@ -1,3 +1,8 @@
+Sat May  8 11:07:41 2010  Nobuyoshi Nakada  <nobu@r...>
+
+	* ext/bigdecimal/bigdecimal.c (VpAlloc): ensure buf does not get
+	  collected.  based on a patch masaya tarui at [ruby-dev:41213].
+
 Fri May  7 11:31:50 2010  Nobuyoshi Nakada  <nobu@r...>
 
 	* instruby.rb (install-man): install mdocs directly without
Index: ruby_1_8/test/bigdecimal/test_bigdecimal.rb
===================================================================
--- ruby_1_8/test/bigdecimal/test_bigdecimal.rb	(revision 27664)
+++ ruby_1_8/test/bigdecimal/test_bigdecimal.rb	(revision 27665)
@@ -687,4 +687,15 @@
     assert_equal(BigDecimal::SIGN_POSITIVE_ZERO, BigDecimal.new("1E-1" + "0" * 10000).sign)
     assert_equal(BigDecimal::SIGN_NEGATIVE_ZERO, BigDecimal.new("-1E-1" + "0" * 10000).sign)
   end
+
+  def test_gc
+    bug3258 = '[ruby-dev:41213]'
+    stress, GC.stress = GC.stress, true
+    1000.times do |i|
+      b = BigDecimal.new("1"+"0"*i).to_s
+      assert_equal([1, "1", 10, i+1], b.split, bug3258)
+    end
+  ensure
+    GC.stress = stress
+  end
 end
Index: ruby_1_9_2/ChangeLog
===================================================================
--- ruby_1_9_2/ChangeLog	(revision 27664)
+++ ruby_1_9_2/ChangeLog	(revision 27665)
@@ -1,3 +1,8 @@
+Sat May  8 11:07:41 2010  Nobuyoshi Nakada  <nobu@r...>
+
+	* ext/bigdecimal/bigdecimal.c (VpAlloc): ensure buf does not get
+	  collected.  based on a patch masaya tarui at [ruby-dev:41213].
+
 Sat May  8 10:03:39 2010  Tanaka Akira  <akr@f...>
 
 	* ext/socket/lib/socket.rb (BasicSocket#connect_address): MacOS X 10.6
Index: ruby_1_9_2/ext/bigdecimal/bigdecimal.c
===================================================================
--- ruby_1_9_2/ext/bigdecimal/bigdecimal.c	(revision 27664)
+++ ruby_1_9_2/ext/bigdecimal/bigdecimal.c	(revision 27665)
@@ -2593,7 +2593,7 @@
     int  sign=1;
     Real *vp = NULL;
     U_LONG mf = VpGetPrecLimit();
-    volatile VALUE buf;
+    VALUE buf;
 
     mx = (mx + BASE_FIG - 1) / BASE_FIG + 1;    /* Determine allocation unit. */
     if(szVal) {
@@ -2621,7 +2621,7 @@
 
     /* Skip all '_' after digit: 2006-6-30 */
     ni = 0;
-    buf = rb_str_new(0,strlen(szVal)+1);
+    buf = rb_str_tmp_new(strlen(szVal)+1);
     psz = RSTRING_PTR(buf);
     i   = 0;
     ipn = 0;
@@ -2720,6 +2720,7 @@
     vp->MaxPrec = mx;        /* set max precision */
     VpSetZero(vp,sign);
     VpCtoV(vp, &(szVal[ipn]), ni, &(szVal[ipf]), nf, &(szVal[ipe]), ne);
+    rb_str_resize(buf, 0);
     return vp;
 }
 
Index: ruby_1_9_2/test/bigdecimal/test_bigdecimal.rb
===================================================================
--- ruby_1_9_2/test/bigdecimal/test_bigdecimal.rb	(revision 27664)
+++ ruby_1_9_2/test/bigdecimal/test_bigdecimal.rb	(revision 27665)
@@ -698,4 +698,15 @@
     assert_equal(BigDecimal::SIGN_POSITIVE_ZERO, BigDecimal.new("1E-1" + "0" * 10000).sign)
     assert_equal(BigDecimal::SIGN_NEGATIVE_ZERO, BigDecimal.new("-1E-1" + "0" * 10000).sign)
   end
+
+  def test_gc
+    bug3258 = '[ruby-dev:41213]'
+    stress, GC.stress = GC.stress, true
+    1000.times do |i|
+      b = BigDecimal.new("1"+"0"*i).to_s
+      assert_equal([1, "1", 10, i+1], b.split, bug3258)
+    end
+  ensure
+    GC.stress = stress
+  end
 end

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

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