Possible Array#pack issue on OS X?

D

Daniel Berger

Hi all,

I've got a user who's having a problem with the spreadsheet-excel package. It
looks like the Format#font_biff method is returning a bogus result. Here's
some code that simulates the default behavior:

# fontbiff.rb
font = "Arial"
dyheight = 200
cch = font.length
length = 0x0F + cch
record = 0x31
reserved = 0x00
grbit = 0x00
color = 32767
bold = 0x0190
font_script = 0
underline = 0
font_family = 0
font_charset = 0

fields = [dyheight, grbit, color, bold, font_script, underline]
fields.push(font_family, font_charset, reserved, cch)

header = [record, length].pack("vv")
data = fields.pack("vvvvvCCCCC")

p header + data + font

That should result in this string (on big endian machines):

"1\000\024\000\310\000\000\000\377\177\220\001\000\000\000\000\000\000\005Arial"

This can be confirmed by running this snippet, which should give you the same
string:

require "spreadsheet/excel"
include Spreadsheet
p Format.new.font_biff

But he's reporting this as the result:

"\0001\000\024\000\310\000\000\177\377\001\220\000\000\000\000\000\000\005Arial"

Any ideas what's happening here?

Thanks,

Dan

PS - Come to think of it, I forgot to ask him which version of Ruby he's
running, and which version of OSX.
 
S

Sean O'Halpin

That should result in this string (on big endian machines):

"1\000\024\000\310\000\000\000\377\177\220\001\000\000\000\000\000\000\00=
5Arial"

That's the same result I get on my (little-endian) WinXP Pentium.

Regards,

Sean
 
D

Daniel Berger

Sean said:
That's the same result I get on my (little-endian) WinXP Pentium.

Regards,

Yeah, you're right. The "v" directive forces little-endian byte order, so it
shouldn't matter.

Does OS X do something different?

Regards,

Dan
 
D

Daniel Berger

Daniel said:
Hi all,

I've got a user who's having a problem with the spreadsheet-excel package. It
looks like the Format#font_biff method is returning a bogus result. Here's
some code that simulates the default behavior:

<snip>

Ok, can the folks on OSX tell me what the following returns?

[0x31].pack("v")

Thanks,

Dan
 
D

Daniel Berger

Jeremy said:
[0x31].pack("v")

ruby 1.8.2 (2004-12-25) [powerpc-darwin8.2.0]

irb(main):001:0> [0x31].pack("v")
=> "1\000"

jeremy

One email I've received says this:

TiBook-5:~ xdefrang$ uname -a
Darwin TiBook-5.local 8.3.0 Darwin Kernel Version 8.3.0: Mon Oct 3
20:04:04 PDT 2005; root:xnu-792.6.22.obj~2/RELEASE_PPC Power Macintosh
powerpc

result: "\0001"

So, I'm quite confused.

Regards,

Dan
 
L

lists

The pack('v') from OS 10.4's default ruby (/usr/bin/ruby) is
currently broken:

% /usr/bin/ruby -e "p [0x31].pack('v')"
"\0001"

Here's the ruby from darwinports.org:

% ruby -e "p [0x31].pack('v')"
"1\000"

-Ryan

Jeremy said:
[0x31].pack("v")

ruby 1.8.2 (2004-12-25) [powerpc-darwin8.2.0]

irb(main):001:0> [0x31].pack("v")
=> "1\000"

jeremy

One email I've received says this:

TiBook-5:~ xdefrang$ uname -a
Darwin TiBook-5.local 8.3.0 Darwin Kernel Version 8.3.0: Mon Oct 3
20:04:04 PDT 2005; root:xnu-792.6.22.obj~2/RELEASE_PPC Power Macintosh
powerpc

result: "\0001"

So, I'm quite confused.

Regards,

Dan
 
E

Ezra Zygmuntowicz

Jeremy said:
[0x31].pack("v")

ruby 1.8.2 (2004-12-25) [powerpc-darwin8.2.0]

irb(main):001:0> [0x31].pack("v")
=> "1\000"

jeremy

One email I've received says this:

TiBook-5:~ xdefrang$ uname -a
Darwin TiBook-5.local 8.3.0 Darwin Kernel Version 8.3.0: Mon Oct 3
20:04:04 PDT 2005; root:xnu-792.6.22.obj~2/RELEASE_PPC Power Macintosh
powerpc

result: "\0001"

(ez@ezras-powerbook-g4-17)()(19:52:55 Mon Nov 07)
(~/Sites/select/):~>$: uname -a
Darwin ezras-powerbook-g4-17.local 8.3.0 Darwin Kernel Version 8.3.0:
Mon Oct 3 20:04:04 PDT 2005; root:xnu-792.6.22.obj~2/RELEASE_PPC
Power Macintosh powerpc

(ez@ezras-powerbook-g4-17)()(20:30:11 Mon Nov 07)
(~/Sites/select/):~>$: irb
[0x31].pack("v") => "1\000"


-Ezra Zygmuntowicz
WebMaster
Yakima Herald-Republic Newspaper
(e-mail address removed)
509-577-7732
 
E

Eric Hodel

Jeremy said:
[0x31].pack("v")

ruby 1.8.2 (2004-12-25) [powerpc-darwin8.2.0]

irb(main):001:0> [0x31].pack("v")
=> "1\000"

jeremy

One email I've received says this:

TiBook-5:~ xdefrang$ uname -a
Darwin TiBook-5.local 8.3.0 Darwin Kernel Version 8.3.0: Mon Oct 3
20:04:04 PDT 2005; root:xnu-792.6.22.obj~2/RELEASE_PPC Power Macintosh
powerpc

result: "\0001"

So, I'm quite confused.

I cane get you both on the same machine:

$ uname -a
Darwin kaa.jijo.segment7.net 8.3.0 Darwin Kernel Version 8.3.0: Mon
Oct 3 20:04:04 PDT 2005; root:xnu-792.6.22.obj~2/RELEASE_PPC Power
Macintosh powerpc
$ ruby168 -ve 'p [0x31].pack("v")'
ruby 1.6.8 (2002-12-24) [powerpc-darwin8.2.0]
"1\000"

I built this Ruby by hand.

$ ruby182-orig -ve 'p [0x31].pack("v")'
ruby 1.8.2 (2004-12-25) [powerpc-darwin8.0]
"\0001"

This one came with Tiger, and I didn't install that gem patch.

$ ruby183 -ve 'p [0x31].pack("v")'
ruby 1.8.3 (2005-09-21) [powerpc-darwin8.2.0]
"1\000"

I built this Ruby by hand too.

I wonder if this has anything to do with it:

$ ruby182-orig -v -rrbconfig -e 'p Config::CONFIG["CFLAGS"]'
ruby 1.8.2 (2004-12-25) [powerpc-darwin8.0]
"-arch i386 -arch ppc -g -Os -pipe -fno-common -arch i386 -arch ppc -
pipe -pipe -fno-common"
$ ruby183 -v -rrbconfig -e 'p Config::CONFIG["CFLAGS"]'
ruby 1.8.3 (2005-09-21) [powerpc-darwin8.2.0]
"-g -O2 -pipe -fno-common"

Does cross-compilation affect the endianness of ruby?
 
E

Eero Saynatkari

Eric said:
Jeremy said:
On Nov 7, 2005, at 5:57 PM, Daniel Berger wrote:

[0x31].pack("v")


ruby 1.8.2 (2004-12-25) [powerpc-darwin8.2.0]

irb(main):001:0> [0x31].pack("v")
=> "1\000"

jeremy


One email I've received says this:

TiBook-5:~ xdefrang$ uname -a
Darwin TiBook-5.local 8.3.0 Darwin Kernel Version 8.3.0: Mon Oct 3
20:04:04 PDT 2005; root:xnu-792.6.22.obj~2/RELEASE_PPC Power Macintosh
powerpc

result: "\0001"

So, I'm quite confused.


I cane get you both on the same machine:

$ uname -a
Darwin kaa.jijo.segment7.net 8.3.0 Darwin Kernel Version 8.3.0: Mon
Oct 3 20:04:04 PDT 2005; root:xnu-792.6.22.obj~2/RELEASE_PPC Power
Macintosh powerpc
$ ruby168 -ve 'p [0x31].pack("v")'
ruby 1.6.8 (2002-12-24) [powerpc-darwin8.2.0]
"1\000"

I built this Ruby by hand.

$ ruby182-orig -ve 'p [0x31].pack("v")'
ruby 1.8.2 (2004-12-25) [powerpc-darwin8.0]
"\0001"

This one came with Tiger, and I didn't install that gem patch.

$ ruby183 -ve 'p [0x31].pack("v")'
ruby 1.8.3 (2005-09-21) [powerpc-darwin8.2.0]
"1\000"

I built this Ruby by hand too.

I wonder if this has anything to do with it:

$ ruby182-orig -v -rrbconfig -e 'p Config::CONFIG["CFLAGS"]'
ruby 1.8.2 (2004-12-25) [powerpc-darwin8.0]
"-arch i386 -arch ppc -g -Os -pipe -fno-common -arch i386 -arch ppc -
pipe -pipe -fno-common"
$ ruby183 -v -rrbconfig -e 'p Config::CONFIG["CFLAGS"]'
ruby 1.8.3 (2005-09-21) [powerpc-darwin8.2.0]
"-g -O2 -pipe -fno-common"

Does cross-compilation affect the endianness of ruby?

I would venture 'yes' if you are in fact cross-compiling it
on a different platform.

E
 

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

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top