summaryrefslogtreecommitdiff
path: root/src/runtime/haskell/Data
diff options
context:
space:
mode:
authorhallgren <hallgren@chalmers.se>2013-02-13 14:28:06 +0000
committerhallgren <hallgren@chalmers.se>2013-02-13 14:28:06 +0000
commit4f243fbf1217a5d635fb4ddb941d375c5777e49b (patch)
treecdf975bc55d877775fb75b76c375533bab12ac30 /src/runtime/haskell/Data
parent4922ab6cc495087f40399746f616cd88590fd884 (diff)
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...
Diffstat (limited to 'src/runtime/haskell/Data')
-rw-r--r--src/runtime/haskell/Data/Binary.hs20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/runtime/haskell/Data/Binary.hs b/src/runtime/haskell/Data/Binary.hs
index 2bebaf148..c8f04083a 100644
--- a/src/runtime/haskell/Data/Binary.hs
+++ b/src/runtime/haskell/Data/Binary.hs
@@ -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
------------------------------------------------------------------------
--