Possible Array#pack issue on OS X?

Discussion in 'Ruby' started by Daniel Berger, Nov 3, 2005.

  1. 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.
     
    Daniel Berger, Nov 3, 2005
    #1
    1. Advertising

  2. On 11/3/05, Daniel Berger <> wrote:
    > 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
     
    Sean O'Halpin, Nov 3, 2005
    #2
    1. Advertising

  3. Sean O'Halpin wrote:
    > On 11/3/05, Daniel Berger <> wrote:
    >
    >>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"

    >
    >
    > 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
     
    Daniel Berger, Nov 3, 2005
    #3
  4. Daniel Berger wrote:
    > 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
     
    Daniel Berger, Nov 8, 2005
    #4
  5. 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
     
    Jeremy Kemper, Nov 8, 2005
    #5
  6. Jeremy Kemper wrote:
    > 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.

    Regards,

    Dan
     
    Daniel Berger, Nov 8, 2005
    #6
  7. Daniel Berger

    lists Guest

    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

    On Nov 7, 2005, at 8:32 PM, Daniel Berger wrote:

    > Jeremy Kemper wrote:
    >> 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.
    >
    > Regards,
    >
    > Dan
    >
    >
     
    lists, Nov 8, 2005
    #7
  8. On Nov 7, 2005, at 6:32 PM, Daniel Berger wrote:

    > Jeremy Kemper wrote:
    >> 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"


    (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

    509-577-7732
     
    Ezra Zygmuntowicz, Nov 8, 2005
    #8
  9. Daniel Berger

    Eric Hodel Guest

    On Nov 7, 2005, at 6:32 PM, Daniel Berger wrote:

    > Jeremy Kemper wrote:
    >> 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?

    --
    Eric Hodel - - http://segment7.net
    FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04
     
    Eric Hodel, Nov 8, 2005
    #9
  10. Eric Hodel wrote:
    > On Nov 7, 2005, at 6:32 PM, Daniel Berger wrote:
    >
    >> Jeremy Kemper wrote:
    >>
    >>> 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
     
    Eero Saynatkari, Nov 8, 2005
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tim Jones
    Replies:
    0
    Views:
    381
    Tim Jones
    Jan 31, 2004
  2. Alexandre Hudelot
    Replies:
    4
    Views:
    142
    Alexandre Hudelot
    Jul 16, 2006
  3. Liang He
    Replies:
    4
    Views:
    148
    Peña, Botp
    Oct 15, 2007
  4. Alexander Farber

    pack 'C3U*' not same as pack 'C3(xC)*'

    Alexander Farber, Jun 23, 2005, in forum: Perl Misc
    Replies:
    2
    Views:
    137
    Ilmari Karonen
    Jun 23, 2005
  5. sonet

    pack /unpack issue

    sonet, Nov 10, 2005, in forum: Perl Misc
    Replies:
    1
    Views:
    125
Loading...

Share This Page