https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112013-04-03T10:12:03ZRuby Issue Tracking SystemRuby master - Bug #8204: ObjectSpace.each_object(Bignum) can generate Bignums that are to small to be Bignumshttps://bugs.ruby-lang.org/issues/8204?journal_id=381322013-04-03T10:12:03Zhsbt (Hiroshi SHIBATA)hsbt@ruby-lang.org
<ul><li><strong>Category</strong> set to <i>core</i></li><li><strong>Assignee</strong> set to <i>ko1 (Koichi Sasada)</i></li><li><strong>Target version</strong> set to <i>2.1.0</i></li></ul> Ruby master - Bug #8204: ObjectSpace.each_object(Bignum) can generate Bignums that are to small to be Bignumshttps://bugs.ruby-lang.org/issues/8204?journal_id=381432013-04-03T11:23:12ZAnonymous
<ul></ul><p>Note that you can obtain whichever Bignum you want using coerce. For<br>
example:</p>
<p>x = (1 << 100).coerce(42).first # => 42<br>
x.class # => Bignum</p>
<p>I saw that used in test/*</p>
<p>I never bothered to investigate it, but I'm pretty sure this could lead to<br>
multiple bugs as MRI assumes that Bignum means big number in many places.</p> Ruby master - Bug #8204: ObjectSpace.each_object(Bignum) can generate Bignums that are to small to be Bignumshttps://bugs.ruby-lang.org/issues/8204?journal_id=381572013-04-03T16:34:34Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li><li><strong>% Done</strong> changed from <i>0</i> to <i>100</i></li></ul><p>This issue was solved with changeset r40076.<br>
Hans, thank you for reporting this issue.<br>
Your contribution to Ruby is greatly appreciated.<br>
May Ruby be with you.</p>
<hr>
<p>bignum.c: Bignum zero comparison</p>
<ul>
<li>bignum.c (rb_big_eq): test as Fixnum if possible and get rid of zero<br>
length Bignum. <a href="/issues/8204">[ruby-core:53893]</a> [Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: ObjectSpace.each_object(Bignum) can generate Bignums that are to small to be Bignums (Closed)" href="https://bugs.ruby-lang.org/issues/8204">#8204</a>]</li>
</ul> Ruby master - Bug #8204: ObjectSpace.each_object(Bignum) can generate Bignums that are to small to be Bignumshttps://bugs.ruby-lang.org/issues/8204?journal_id=382042013-04-04T14:27:47ZHanmac (Hans Mackowiak)hanmac@gmx.de
<ul></ul><p>okay that solvs a bit, so the generated Bignums are zero too,<br>
but for sample</p>
<p>ObjectSpace.each_object(Bignum).select &:zero?</p>
<p>still generates Bignum zeros and the 3 that was inside the Bignum list at the beginning confuses me</p> Ruby master - Bug #8204: ObjectSpace.each_object(Bignum) can generate Bignums that are to small to be Bignumshttps://bugs.ruby-lang.org/issues/8204?journal_id=385932013-04-16T12:18:24Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><blockquote>
<p>x = (1 << 100).coerce(42).first # => 42<br>
x.class # => Bignum</p>
</blockquote>
<p>It's a Feature.</p>
<p>Numeric#coerce must return a pair of converted interoperable values.</p>
<p>In future version, Fixnum and Bignum might be merged.<br>
However, these commits do not intend it.<br>
Just fixes the comparison, and hides and frees intermediate objects earlier.</p>