From: "Klaus Kämpf" Date: 2010-05-10T03:48:23+09:00 Subject: [ruby-core:30121] [Bug #1131] String#unpack("V") does not work correctly is linux on s390x Issue #1131 has been updated by Klaus K��mpf. File bnc603914_string_unpack.patch added unpack("V") broken on all systems with sizeof(long) == 8, ppc64 is also affected. It is caused by the following code (pack.c, pack_unpack(), case 'V') unsigned long tmp = 0; memcpy(OFF32(&tmp), s, NATINT_LEN(long,4)); s += NATINT_LEN(long,4); rb_ary_push(ary, ULONG2NUM(vtohl(tmp))); The use of OFF32 in memcpy copies the int32 value into the correct half of the 8-byte target value (tmp). The call to vtohl() swaps the complete 8-byte value (acting like swap64), thereby bringing the 4 bytes of the int32 into the right endianess but also into the wrong half of the 8-byte target. The fix is to either drop of OFF32 call or to replace the vtohl with swap32. I choose the latter since swap32 is faster than vtohl. Proposed patch attached ---------------------------------------- http://redmine.ruby-lang.org/issues/show/1131 ---------------------------------------- http://redmine.ruby-lang.org