[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

pack("l"), 64 bit question

Berger, Daniel

2/15/2006 4:51:00 PM

Hi all,

Ruby 1.8.4
Solaris 10

Is this correct?

# 32 bit
irb(main):002:0> [-1].pack("l")
=> "\377\377\377\377"
irb(main):003:0> "\377\377\377\377".unpack("l")
=> [-1]

# 64 bit
irb(main):002:0> [-1].pack("l")
=> "\377\377\377\377"
irb(main):003:0> "\377\377\377\377".unpack("l")
=> [4294967295]

Regards,

Dan


10 Answers

Ara.T.Howard

2/15/2006 4:55:00 PM

0

Ara.T.Howard

2/15/2006 5:03:00 PM

0

Yukihiro Matsumoto

2/15/2006 5:36:00 PM

0

Hi,

In message "Re: pack("l"), 64 bit question"
on Thu, 16 Feb 2006 01:50:34 +0900, Daniel Berger <Daniel.Berger@qwest.com> writes:

|Ruby 1.8.4
|Solaris 10
|
|Is this correct?
|
|# 32 bit
|irb(main):002:0> [-1].pack("l")
|=> "\377\377\377\377"
|irb(main):003:0> "\377\377\377\377".unpack("l")
|=> [-1]
|
|# 64 bit
|irb(main):002:0> [-1].pack("l")
|=> "\377\377\377\377"
|irb(main):003:0> "\377\377\377\377".unpack("l")
|=> [4294967295]

Hmm, unpack("l") should have returned negative value unless "_" suffix
is supplied.

matz.


Berger, Daniel

2/15/2006 5:48:00 PM

0

Yukihiro Matsumoto wrote:
> List-Unsubscribe: <mailto:ruby-talk-ctl@ruby-lang.org?body=unsubscribe>
>
> Hi,
>
> In message "Re: pack("l"), 64 bit question"
> on Thu, 16 Feb 2006 01:50:34 +0900, Daniel Berger <Daniel.Berger@qwest.com> writes:
>
> |Ruby 1.8.4
> |Solaris 10
> |
> |Is this correct?
> |
> |# 32 bit
> |irb(main):002:0> [-1].pack("l")
> |=> "\377\377\377\377"
> |irb(main):003:0> "\377\377\377\377".unpack("l")
> |=> [-1]
> |
> |# 64 bit
> |irb(main):002:0> [-1].pack("l")
> |=> "\377\377\377\377"
> |irb(main):003:0> "\377\377\377\377".unpack("l")
> |=> [4294967295]
>
> Hmm, unpack("l") should have returned negative value unless "_" suffix
> is supplied.
>
> matz.
>

Here's some more info that may or may not be useful:

# 64 bit
irb(main):004:0> "\377\377\377\377".unpack("l_")
=> [nil]
irb(main):005:0> [-1].pack("l_")
=> "\377\377\377\377\377\377\377\377"
irb(main):006:0> "\377\377\377\377\377\377\377\377".unpack("l_")
=> [-1]

Regards,

Dan


Yukihiro Matsumoto

2/15/2006 5:49:00 PM

0

Hi,

In message "Re: pack("l"), 64 bit question"
on Thu, 16 Feb 2006 02:35:53 +0900, Yukihiro Matsumoto <matz@ruby-lang.org> writes:

||irb(main):003:0> "\377\377\377\377".unpack("l")
||=> [4294967295]
|
|Hmm, unpack("l") should have returned negative value unless "_" suffix
|is supplied.

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?

matz.


H.Yamamoto

2/16/2006 8:46:00 AM

0

Hello.

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

Index: pack.c
===================================================================
RCS file: /src/ruby/pack.c,v
retrieving revision 1.62.2.12
diff -u -w -b -p -r1.62.2.12 pack.c
--- 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)



Yukihiro Matsumoto

2/16/2006 8:50:00 AM

0

Hi,

In message "Re: pack("l"), 64 bit question"
on Thu, 16 Feb 2006 17:45:50 +0900, H.Yamamoto <ocean@m2.ccsnet.ne.jp> 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)


Ville Mattila

2/16/2006 10:06:00 AM

0

Yukihiro Matsumoto <matz@ruby-lang.org> writes:

> Hi,
>
> In message "Re: pack("l"), 64 bit question"
> on Thu, 16 Feb 2006 17:45:50 +0900, H.Yamamoto <ocean@m2.ccsnet.ne.jp> 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?

The pach works for me on my opteron 64 box. Here is another.
The sun studio cc, warned
cc: Warning: -fsimple option is ignored.
"../pack.c", line 1954: warning: integer overflow detected: op "<<"
"../pack.c", line 1954: warning: initializer does not fit or is out of range: -144115188075855872

Is the patch correct?

index: pack.c
===================================================================
RCS file: /src/ruby/pack.c,v
retrieving revision 1.62.2.12
@@ -1951,7 +1951,7 @@ pack_unpack(str, fmt)
case 'w':
{
unsigned long ul = 0;
- unsigned long ulmask = 0xfeL << ((sizeof(unsigned long) - 1) * 8);
+ unsigned long ulmask = 0xfeUL << ((sizeof(unsigned long) - 1UL) * 8UL);

while (len > 0 && s < send) {
ul <<= 7;

Berger, Daniel

2/16/2006 4:48:00 PM

0

Yukihiro Matsumoto wrote:
> Hi,
>
> In message "Re: pack("l"), 64 bit question"
> on Thu, 16 Feb 2006 17:45:50 +0900, H.Yamamoto <ocean@m2.ccsnet.ne.jp> 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


Yukihiro Matsumoto

2/16/2006 10:48:00 PM

0

Hi,

In message "Re: pack("l"), 64 bit question"
on Fri, 17 Feb 2006 01:47:36 +0900, Daniel Berger <Daniel.Berger@qwest.com> writes:

|> Daniel, could you try this patch on your 64bit box?

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

No, it should return [4294967295]. How about a patch from Ville
Mattila in [ruby-talk:180126]?

matz.