1
0
forked from GitHub/gf-core

Fix for a PGF portability problem

GF produced slightly different PGF files on 64-bit systems and 32-bit systems.
This could cause problems when a PGF was produced on a 32-bit system and used
on a 64-bit system.

To fix this, the GF compiler and the Haskell PGF run-time library now reads
and writes PGF files like the 32-bit version even when compiled on a 64-bit
system.

Note: the Haskell type Int is still used internally in GF, which could be
32 bits or 64 bits...
This commit is contained in:
hallgren
2013-02-13 14:28:06 +00:00
parent 4922ab6cc4
commit 4f243fbf12

View File

@@ -348,7 +348,7 @@ instance Binary Int32 where
put i = put (fromIntegral i :: Word32)
get = liftM fromIntegral (get :: Get Word32)
-- Int64s are written as a 4 bytes in big endian format
-- Int64s are written as a 8 bytes in big endian format
instance Binary Int64 where
put i = put (fromIntegral i :: Word64)
get = liftM fromIntegral (get :: Get Word64)
@@ -368,13 +368,16 @@ instance Binary Word where
put (b .|. 0x80)
put (c .|. 0x80)
put d
#if WORD_SIZE_IN_BITS < 64
-- #if WORD_SIZE_IN_BITS < 64
| otherwise = do put (a .|. 0x80)
put (b .|. 0x80)
put (c .|. 0x80)
put (d .|. 0x80)
put e
#else
{-
-- Restricted to 32 bits even on 64-bit systems, so that negative
-- Ints are written as 5 bytes instead of 10 bytes (TH 2013-02-13)
--#else
| i <= 0x7ffffffff = do put (a .|. 0x80)
put (b .|. 0x80)
put (c .|. 0x80)
@@ -428,19 +431,21 @@ instance Binary Word where
put (h .|. 0x80)
put (j .|. 0x80)
put k
#endif
-- #endif
-}
where
a = fromIntegral ( i .&. 0x7f) :: Word8
b = fromIntegral (shiftR i 7 .&. 0x7f) :: Word8
c = fromIntegral (shiftR i 14 .&. 0x7f) :: Word8
d = fromIntegral (shiftR i 21 .&. 0x7f) :: Word8
e = fromIntegral (shiftR i 28 .&. 0x7f) :: Word8
{-
f = fromIntegral (shiftR i 35 .&. 0x7f) :: Word8
g = fromIntegral (shiftR i 42 .&. 0x7f) :: Word8
h = fromIntegral (shiftR i 49 .&. 0x7f) :: Word8
j = fromIntegral (shiftR i 56 .&. 0x7f) :: Word8
k = fromIntegral (shiftR i 63 .&. 0x7f) :: Word8
-}
get = do i <- getWord8
(if i <= 0x7f
then return (fromIntegral i)
@@ -450,7 +455,10 @@ instance Binary Word where
-- Int has the same representation as Word
instance Binary Int where
put i = put (fromIntegral i :: Word)
get = liftM fromIntegral (get :: Get Word)
get = liftM toInt32 (get :: Get Word)
where
-- restrict to 32 bits (for PGF portability, TH 2013-02-13)
toInt32 w = fromIntegral (fromIntegral w::Int32)::Int
------------------------------------------------------------------------
--