Endian packing errors.

B

Brian Mitchell

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.
 
J

Jim Freeze

* Brian Mitchell said:
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])
 
B

Brian Mitchell

* Brian Mitchell said:
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?
=20
Hmm, What do your machines (specifically the iMac) return for this:
=20
BigEndian =3D (0 =3D=3D [1].pack('l')[0])
PB(G4): true
iMac(G5): true
Linux(x86): false
LittleEndian =3D (1 =3D=3D [1].pack('l')[0])
PB(G4): false
iMac(G5): false
Linux(x86): true

Brian.
 
J

Jim Freeze

* Brian Mitchell said:
* Brian Mitchell said:
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
 
B

Brian Mitchell

* Brian Mitchell said:
* Brian Mitchell <[email protected]> [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 box= es,
an iMac with 10.3 but on my Powerbook with 10.4 it returns the reve= rse
"A\000\000\000". What is causing this. Did Apple mess up yet again
with including ruby? Could someone duplicate this on tiger?
=20
On my PowerBook with Ruby 1.8.2, I get:
=20
irb(main):001:0> [65].pack('N')
=3D> "\000\000\000A"
irb(main):002:0> [65].pack('n')
=3D> "\000A"
=20
The "A\000\000\000" is not making sense to me.
Sorry I don't have Tiger installed to compare with.
=20

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.
 
C

Charles Steinman

Brian said:
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.
 
B

Brian Mitchell

=20

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.
 
G

Gavin Kistner

--Apple-Mail-1--956494231
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
delsp=yes;
format=flowed

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


--Apple-Mail-1--956494231--
 
B

Brian Mitchell

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?
=20
Not reproducible by me. MacOS 10.4.1 on a 1GHz Powerbook
=20

I this using the ruby that comes with 10.4, a custom build, or something el=
se?
[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.
 
C

Charles Steinman

Gavin said:
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

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?
 
G

Gavin Kistner

--Apple-Mail-1--950495792
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
delsp=yes;
format=flowed

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"


--Apple-Mail-1--950495792--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,172
Messages
2,570,934
Members
47,477
Latest member
ColumbusMa

Latest Threads

Top