From: Daniel Berger Date: 2006-02-17T01:47:36+09:00 Subject: Re: pack("l"), 64 bit question Yukihiro Matsumoto wrote: > Hi, > > In message "Re: pack("l"), 64 bit question" > on Thu, 16 Feb 2006 17:45:50 +0900, H.Yamamoto writes: > | > |>This means EXTEND32() macro in pack.c is not working on 64bit Solaris > |>(and perhaps on other 64bit systems neither). I have no 64bit machine > |>at hand. Could somebody confirm? > | > |Me neigher. But we can use HP TestDrive :-) > | > |Probably this patch will solve the problem. > > Daniel, could you try this patch on your 64bit box? > > matz. > > |--- pack.c 13 Oct 2005 14:30:49 -0000 1.62.2.12 > |+++ pack.c 16 Feb 2006 06:01:07 -0000 > |@@ -347,11 +347,11 @@ num2i32(x) > | return 0; /* not reached */ > | } > | > |-#if SIZEOF_LONG == SIZE32 || SIZEOF_INT == SIZE32 > |+#if SIZEOF_LONG == SIZE32 > | # define EXTEND32(x) > | #else > | /* invariant in modulo 1<<31 */ > |-# define EXTEND32(x) do {if (!natint) {(x) = (I32)(((1<<31)-1-(x))^~(~0<<31));}} while(0) > |+# define EXTEND32(x) do { if (!natint) {(x) = (((1L<<31)-1-(x))^~(~0L<<31));}} while(0) > | #endif > | #if SIZEOF_SHORT == SIZE16 > | # define EXTEND16(x) > Looks good. The only one I found odd was the [nil] returned by "\377\377\377\377".unpack("l_"). Is that expected? The 32 bit version returns [-1]. # 64 bit Ruby irb(main):001:0> [-1].pack("l") => "\377\377\377\377" irb(main):002:0> "\377\377\377\377".unpack("l") => [-1] irb(main):003:0> "\377\377\377\377".unpack("l_") => [nil] irb(main):004:0> [-1].pack("l_") => "\377\377\377\377\377\377\377\377" irb(main):005:0> "\377\377\377\377\377\377\377\377".unpack("l") => [-1] irb(main):006:0> "\377\377\377\377\377\377\377\377".unpack("l_") => [-1] Thanks, Dan