[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Endian packing errors.

Brian Mitchell

5/23/2005 5:54:00 PM

I have a number I must convert to a network long. I have been using
this thus far with success:

[number].pack("N")

for 65 it should return "\000\000\000A". It does so on my linux boxes,
an iMac with 10.3 but on my Powerbook with 10.4 it returns the reverse
"A\000\000\000". What is causing this. Did Apple mess up yet again
with including ruby? Could someone duplicate this on tiger?

I have installed the ruby fix pack from the Ruby On Rails HowTo.

Thanks,
Brian.


10 Answers

Jim Freeze

5/23/2005 6:20:00 PM

0

* Brian Mitchell <binary42@gmail.com> [2005-05-24 02:53:52 +0900]:

> I have a number I must convert to a network long. I have been using
> this thus far with success:
>
> [number].pack("N")
>
> for 65 it should return "\000\000\000A". It does so on my linux boxes,
> an iMac with 10.3 but on my Powerbook with 10.4 it returns the reverse
> "A\000\000\000". What is causing this. Did Apple mess up yet again
> with including ruby? Could someone duplicate this on tiger?

Hmm, What do your machines (specifically the iMac) return for this:

BigEndian = (0 == [1].pack('l')[0])
LittleEndian = (1 == [1].pack('l')[0])

--
Jim Freeze
Ruby: I can explain it to ya but I can't understand it fer ya.


Brian Mitchell

5/23/2005 6:25:00 PM

0

On 5/23/05, Jim Freeze <jim@freeze.org> wrote:
> * Brian Mitchell <binary42@gmail.com> [2005-05-24 02:53:52 +0900]:
>
> > I have a number I must convert to a network long. I have been using
> > this thus far with success:
> >
> > [number].pack("N")
> >
> > for 65 it should return "\000\000\000A". It does so on my linux boxes,
> > an iMac with 10.3 but on my Powerbook with 10.4 it returns the reverse
> > "A\000\000\000". What is causing this. Did Apple mess up yet again
> > with including ruby? Could someone duplicate this on tiger?
>
> Hmm, What do your machines (specifically the iMac) return for this:
>
> BigEndian = (0 == [1].pack('l')[0])
PB(G4): true
iMac(G5): true
Linux(x86): false
> LittleEndian = (1 == [1].pack('l')[0])
PB(G4): false
iMac(G5): false
Linux(x86): true

Brian.


Jim Freeze

5/23/2005 6:39:00 PM

0

* Brian Mitchell <binary42@gmail.com> [2005-05-24 03:25:24 +0900]:

> On 5/23/05, Jim Freeze <jim@freeze.org> wrote:
> > * Brian Mitchell <binary42@gmail.com> [2005-05-24 02:53:52 +0900]:
> >
> > > I have a number I must convert to a network long. I have been using
> > > this thus far with success:
> > >
> > > [number].pack("N")
> > >
> > > for 65 it should return "\000\000\000A". It does so on my linux boxes,
> > > an iMac with 10.3 but on my Powerbook with 10.4 it returns the reverse
> > > "A\000\000\000". What is causing this. Did Apple mess up yet again
> > > with including ruby? Could someone duplicate this on tiger?

On my PowerBook with Ruby 1.8.2, I get:

irb(main):001:0> [65].pack('N')
=> "\000\000\000A"
irb(main):002:0> [65].pack('n')
=> "\000A"

The "A\000\000\000" is not making sense to me.
Sorry I don't have Tiger installed to compare with.

> > Hmm, What do your machines (specifically the iMac) return for this:
> >
> > BigEndian = (0 == [1].pack('l')[0])
> PB(G4): true
> iMac(G5): true
> Linux(x86): false
> > LittleEndian = (1 == [1].pack('l')[0])
> PB(G4): false
> iMac(G5): false
> Linux(x86): true

--
Jim Freeze
Ruby: I can explain it to ya but I can't understand it fer ya.


Brian Mitchell

5/23/2005 6:47:00 PM

0

On 5/23/05, Jim Freeze <jim@freeze.org> wrote:
> * Brian Mitchell <binary42@gmail.com> [2005-05-24 03:25:24 +0900]:
>
> > On 5/23/05, Jim Freeze <jim@freeze.org> wrote:
> > > * Brian Mitchell <binary42@gmail.com> [2005-05-24 02:53:52 +0900]:
> > >
> > > > I have a number I must convert to a network long. I have been using
> > > > this thus far with success:
> > > >
> > > > [number].pack("N")
> > > >
> > > > for 65 it should return "\000\000\000A". It does so on my linux boxes,
> > > > an iMac with 10.3 but on my Powerbook with 10.4 it returns the reverse
> > > > "A\000\000\000". What is causing this. Did Apple mess up yet again
> > > > with including ruby? Could someone duplicate this on tiger?
>
> On my PowerBook with Ruby 1.8.2, I get:
>
> irb(main):001:0> [65].pack('N')
> => "\000\000\000A"
> irb(main):002:0> [65].pack('n')
> => "\000A"
>
> The "A\000\000\000" is not making sense to me.
> Sorry I don't have Tiger installed to compare with.
>

I think that is what it is. I just compiled ruby from source to check
(actually just miniruby) and it does not have the problem. I am
submitting a bug report to apple. It looks like there is yet another
problem with ruby on tiger. It may be with the ruby patcher that I
installed but I have not had time to verify that with a clean install.
Anyone with a fresh tiger install want to try it out?

Brian.


acharlieblue

5/23/2005 7:59:00 PM

0


Brian Mitchell wrote:
> I think that is what it is. I just compiled ruby from source to check
> (actually just miniruby) and it does not have the problem. I am
> submitting a bug report to apple. It looks like there is yet another
> problem with ruby on tiger. It may be with the ruby patcher that I
> installed but I have not had time to verify that with a clean
install.
> Anyone with a fresh tiger install want to try it out?
I haven't patched my Apple-supplied Ruby at all (I use a different
version installed in /usr/local), and it shows the bug. It looks like
this is a problem with the version of Ruby bundled with Tiger.

Brian Mitchell

5/23/2005 8:08:00 PM

0

On 5/23/05, Charles Steinman <acharlieblue@gmail.com> wrote:
>
> Brian Mitchell wrote:
> > I think that is what it is. I just compiled ruby from source to check
> > (actually just miniruby) and it does not have the problem. I am
> > submitting a bug report to apple. It looks like there is yet another
> > problem with ruby on tiger. It may be with the ruby patcher that I
> > installed but I have not had time to verify that with a clean
> install.
> > Anyone with a fresh tiger install want to try it out?
> I haven't patched my Apple-supplied Ruby at all (I use a different
> version installed in /usr/local), and it shows the bug. It looks like
> this is a problem with the version of Ruby bundled with Tiger.

Thanks for the post! I've filed a bug report but it's probably more
likely to get fixed soon if we can have a few more pop their head into
Apple's bug reporter.

Brian.


Gavin Kistner

5/24/2005 12:19:00 PM

0

On May 23, 2005, at 11:53 AM, Brian Mitchell wrote:
> I have a number I must convert to a network long. I have been using
> this thus far with success:
>
> [number].pack("N")
>
> for 65 it should return "\000\000\000A". It does so on my linux boxes,
> an iMac with 10.3 but on my Powerbook with 10.4 it returns the reverse
> "A\000\000\000". What is causing this. Did Apple mess up yet again
> with including ruby? Could someone duplicate this on tiger?

Not reproducible by me. MacOS 10.4.1 on a 1GHz Powerbook

[Slim:~] gavinkis% ruby -v
ruby 1.8.2 (2004-12-25) [powerpc-darwin8.0.0]
[Slim:~] gavinkis% cat pack.rb
p [65].pack("N")
[Slim:~] gavinkis% ruby pack.rb
"\000\000\000A"
[Slim:~] gavinkis% uname -a
Darwin Slim.local 8.1.0 Darwin Kernel Version 8.1.0: Tue May 10
18:16:08 PDT 2005; root:xnu-792.1.5.obj~4/RELEASE_PPC Power Macintosh
powerpc

Brian Mitchell

5/24/2005 1:40:00 PM

0

On 5/24/05, Gavin Kistner <gavin@refinery.com> wrote:
> On May 23, 2005, at 11:53 AM, Brian Mitchell wrote:
> > I have a number I must convert to a network long. I have been using
> > this thus far with success:
> >
> > [number].pack("N")
> >
> > for 65 it should return "\000\000\000A". It does so on my linux boxes,
> > an iMac with 10.3 but on my Powerbook with 10.4 it returns the reverse
> > "A\000\000\000". What is causing this. Did Apple mess up yet again
> > with including ruby? Could someone duplicate this on tiger?
>
> Not reproducible by me. MacOS 10.4.1 on a 1GHz Powerbook
>

I this using the ruby that comes with 10.4, a custom build, or something else?

> [Slim:~] gavinkis% ruby -v
> ruby 1.8.2 (2004-12-25) [powerpc-darwin8.0.0]
> [Slim:~] gavinkis% cat pack.rb
> p [65].pack("N")
> [Slim:~] gavinkis% ruby pack.rb
> "\000\000\000A"
> [Slim:~] gavinkis% uname -a
> Darwin Slim.local 8.1.0 Darwin Kernel Version 8.1.0: Tue May 10
> 18:16:08 PDT 2005; root:xnu-792.1.5.obj~4/RELEASE_PPC Power Macintosh
> powerpc

Thanks,
Brian.


acharlieblue

5/24/2005 1:52:00 PM

0


Gavin Kistner wrote:
> Not reproducible by me. MacOS 10.4.1 on a 1GHz Powerbook
>
> [Slim:~] gavinkis% ruby -v
> ruby 1.8.2 (2004-12-25) [powerpc-darwin8.0.0]
> [Slim:~] gavinkis% cat pack.rb
> p [65].pack("N")
> [Slim:~] gavinkis% ruby pack.rb
> "\000\000\000A"
> [Slim:~] gavinkis% uname -a
> Darwin Slim.local 8.1.0 Darwin Kernel Version 8.1.0: Tue May 10
> 18:16:08 PDT 2005; root:xnu-792.1.5.obj~4/RELEASE_PPC Power Macintosh

> powerpc

I suspect that's a custom build, because the version string is slightly
different from mine, which just says [powerpc-darwin8.0] (no second .0
at the end). Are you sure this is the bundled copy?

Gavin Kistner

5/24/2005 1:59:00 PM

0

On May 24, 2005, at 7:40 AM, Brian Mitchell wrote:
> On 5/24/05, Gavin Kistner <gavin@refinery.com> wrote:
>> On May 23, 2005, at 11:53 AM, Brian Mitchell wrote:
>>> I have a number I must convert to a network long. I have been using
>>> this thus far with success:
>> Not reproducible by me. MacOS 10.4.1 on a 1GHz Powerbook
> I this using the ruby that comes with 10.4, a custom build, or
> something else?

Ah, there's the rub. Yes, this was with a custom build of ruby, not
the default Tiger install.

I have both installed, and there you can see the discrepancy clearly:

[Slim:~] gavinkis% /usr/bin/ruby -v
ruby 1.8.2 (2004-12-25) [powerpc-darwin8.0]
[Slim:~] gavinkis% /usr/bin/ruby pack.rb
"A\000\000\000"

[Slim:~] gavinkis% /usr/local/bin/ruby -v
ruby 1.8.2 (2004-12-25) [powerpc-darwin8.0.0]
[Slim:~] gavinkis% /usr/local/bin/ruby pack.rb
"\000\000\000A"