[Python-Dev] test_gettext.py fails on 64-bit architectures (original) (raw)

Mark Favas m.favas@per.dem.csiro.au
Thu, 31 Aug 2000 15:23:43 +0800


(Tru64 Unix) - test_gettext fails with the message: IOError: [Errno 0] Bad magic number: './xx/LC_MESSAGES/gettext.mo'

This is because the magic number is read in by the code in Lib/gettext.py as FFFFFFFF950412DE (hex) (using unpack('<i', buf[:4])[0]), and checked against LE_MAGIC (defined as 950412DE) and BE_MAGIC (calculated as FFFFFFFFDE120495 using struct.unpack('>i',struct.pack('<i', LE_MAGIC))[0]) These format strings work for machines where a Python integer is the same size as a C int, but not for machines where a Python integer is larger than a C int. The problem arises because the LE_MAGIC number is negative if a 32-bit int, but positive if Python integers are 64-bit. Replacing the "i" in the code that generates BE_MAGIC and reads in "magic" by "I" makes the test work for me, but there's other uses of "i" and "ii" when the rest of the .mo file is processed that I'm unsure about with different inputs.

Mark

Email - m.favas@per.dem.csiro.au Postal - Mark C Favas Phone - +61 8 9333 6268, 041 892 6074 CSIRO Exploration & Mining Fax - +61 8 9333 6121 Private Bag No 5 Wembley, Western Australia 6913