summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-05-08 02:07:43 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-05-08 02:07:43 +0000
commitcccc8cbd45078028a1bae2d28c934172723bebf3 (patch)
treef3edd29f375956499f506623e667cb03409fb340
parent01a21e44fece658e46e12b29cea566052c67cb43 (diff)
* ext/bigdecimal/bigdecimal.c (VpAlloc): ensure buf does not get
collected. based on a patch masaya tarui at [ruby-dev:41213]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@27665 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--ext/bigdecimal/bigdecimal.c5
-rw-r--r--test/bigdecimal/test_bigdecimal.rb11
3 files changed, 19 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 26be72ecfa..813210bebd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sat May 8 11:07:41 2010 Nobuyoshi Nakada <[email protected]>
+
+ * 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 <[email protected]>
* instruby.rb (install-man): install mdocs directly without
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index 78ea21a0f3..64562edb5b 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -2531,7 +2531,7 @@ VpAlloc(U_LONG mx, const char *szVal)
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 @@ VpAlloc(U_LONG mx, const char *szVal)
/* 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 @@ VpAlloc(U_LONG mx, const char *szVal)
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;
}
diff --git a/test/bigdecimal/test_bigdecimal.rb b/test/bigdecimal/test_bigdecimal.rb
index 19beec1c74..78c50f6d27 100644
--- a/test/bigdecimal/test_bigdecimal.rb
+++ b/test/bigdecimal/test_bigdecimal.rb
@@ -687,4 +687,15 @@ class TestBigDecimal < Test::Unit::TestCase
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