Project

General

Profile

Actions

Bug #1330

closed

BigDecimal オブジェクトを何度も使い回すと Bus Error が発生することがある

Added by mrkn (Kenta Murata) about 15 years ago. Updated almost 13 years ago.

Status:
Closed
Target version:
ruby -v:
ruby 1.8.8dev (2009-03-28) [i386-darwin9.6.0]

Description

=begin
以下のように BigDecimal オブジェクトを何度も再利用すると BusError が起こります。

$ ~/ruby-1.8.8-r23088/bin/ruby -rbigdecimal -ve '
a = BigDecimal("10000000000000000000000000000000000000000")
b = BigDecimal("0.0000000000000000000000000000001")
1000000.times{ a + b }'
ruby 1.8.8dev (2009-03-28) [i386-darwin9.6.0]
-e:4: [BUG] Bus Error
ruby 1.8.8dev (2009-03-28) [i386-darwin9.6.0]

Abort trap

次のように、times のブロック内で何かを puts することで、これを回避できることが分かりました。

$ ~/ruby-1.8.8-r23088/bin/ruby -rbigdecimal -ve '
a = BigDecimal("10000000000000000000000000000000000000000")
b = BigDecimal("0.0000000000000000000000000000001")
1000000.times{ $stderr.puts ""; a + b }' 2>/dev/null
ruby 1.8.8dev (2009-03-28) [i386-darwin9.6.0]

ところが、puts の引数を省略すると Bus Error が復活します。

$ ~/ruby-1.8.8-r23088/bin/ruby -rbigdecimal -ve '
a = BigDecimal("10000000000000000000000000000000000000000")
b = BigDecimal("0.0000000000000000000000000000001")
1000000.times{ $stderr.puts; a + b }'
ruby 1.8.8dev (2009-03-28) [i386-darwin9.6.0]
(非常に大量の改行文字は省略)
-e:4: [BUG] Bus Error
ruby 1.8.8dev (2009-03-28) [i386-darwin9.6.0]

Abort trap
=end

Actions #1

Updated by shyouhei (Shyouhei Urabe) over 14 years ago

  • Status changed from Open to Assigned
  • Assignee set to tad (Tadashi Saito)

=begin

=end

Actions #2

Updated by tad (Tadashi Saito) over 14 years ago

=begin
どうも、忘年会に行ったら突然「Assignしといたから」と言われた斎藤です。

最新のruby_1_8を手元の環境で試したところ、N.timesのNを増やしても、あるいは
GC.stress = trueを手前に入れても再現しませんでした。r23613でalloca()を
使わないようになったのが影響する気がしないでもないので、再度テストを
お願いできないでしょうか? >むらけんさん
=end

Actions #3

Updated by mrkn (Kenta Murata) over 14 years ago

=begin
以下のように、再現されないことを確認しました。

$ /opt/ruby/ruby_1_8/bin/ruby -rbigdecimal -ve '

a = BigDecimal("10000000000000000000000000000000000000000")
b = BigDecimal("0.0000000000000000000000000000001")
1000000.times{ a + b }'

ruby 1.8.8dev (2009-12-21) [x86_64-darwin]

$ /opt/ruby/ruby_1_8/bin/ruby -rbigdecimal -ve '

a = BigDecimal("10000000000000000000000000000000000000000")
b = BigDecimal("0.0000000000000000000000000000001")
1000000.times{ $stderr.puts ""; a + b }' 2>/dev/null

ruby 1.8.8dev (2009-12-21) [x86_64-darwin]

$ /opt/ruby/ruby_1_8/bin/ruby -rbigdecimal -ve '

a = BigDecimal("10000000000000000000000000000000000000000")
b = BigDecimal("0.0000000000000000000000000000001")
1000000.times{ $stderr.puts; a + b }'

ruby 1.8.8dev (2009-12-21) [x86_64-darwin]

=end

Actions #4

Updated by naruse (Yui NARUSE) over 14 years ago

  • Status changed from Assigned to Closed

=begin

=end

Actions #5

Updated by mrkn (Kenta Murata) over 14 years ago

=begin
アーキテクチャが違ってました。
i386 でもう一度試しましたが、再現しなかったので閉じて良いと思います。

$ /opt/ruby/ruby_1_8/bin/ruby -rbigdecimal -ve '

a = BigDecimal("10000000000000000000000000000000000000000")
b = BigDecimal("0.0000000000000000000000000000001")
1000000.times{ a + b }'
ruby 1.8.8dev (2009-12-21) [i386-darwin10.2.0]

$ /opt/ruby/ruby_1_8/bin/ruby -rbigdecimal -ve '

a = BigDecimal("10000000000000000000000000000000000000000")
b = BigDecimal("0.0000000000000000000000000000001")
1000000.times{ $stderr.puts ""; a + b }' 2>/dev/null
ruby 1.8.8dev (2009-12-21) [i386-darwin10.2.0]

$ /opt/ruby/ruby_1_8/bin/ruby -rbigdecimal -ve '

a = BigDecimal("10000000000000000000000000000000000000000")
b = BigDecimal("0.0000000000000000000000000000001")
1000000.times{ $stderr.puts; a + b }' 2>/dev/null
ruby 1.8.8dev (2009-12-21) [i386-darwin10.2.0]

=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0