[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

pack bug on 64-bit ruby

Berger, Daniel

11/17/2003 9:11:00 PM

Hi all,

Solaris 9

>/opt/bin/ruby -v
ruby 1.8.1 (2003-10-31) [sparc-solaris2.9]

>file /opt/bin/ruby
/opt/bin/ruby: ELF 64-bit MSB executable SPARCV9 Version 1, UltraSPARC1
Extensions Required, dynamically linked, not stripped

Looks like there's a 64-bit related bug in pack():

irb(main):007:0> [-1].pack("V")
RangeError: integer 18446744073709551615 too big to convert to `unsigned
int'
from (irb):7:in `pack'
from (irb):7

Regards,

Dan


1 Answer

Lyle Johnson

11/17/2003 9:47:00 PM

0

Daniel Berger wrote:

> Looks like there's a 64-bit related bug in pack():
>
> irb(main):007:0> [-1].pack("V")
> RangeError: integer 18446744073709551615 too big to convert to `unsigned
> int'
> from (irb):7:in `pack'
> from (irb):7

If Array#pack is supposed to output a four-character string for the
*unsigned* long value, I think maybe this shouldn't work for 64-bit.
You're passing in a value of -1, which is 2**64 - 1 when represented as
an unsigned long on a 64-bit machine. You can't pack that into four
characters (bytes).

Out of curiosity, what happens if you instead try this?

[-1].pack("L_")

Note the trailing underscore. If I read the code right, this should do
the right thing.