THRIFT-385. hs: 64-bit integer and double types incorrectly serialized on 32-bit platforms
Use 64-bit types where appropriate.
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@757619 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/src/generate/t_hs_generator.cc b/compiler/cpp/src/generate/t_hs_generator.cc
index 0ea5ddc..580340d 100644
--- a/compiler/cpp/src/generate/t_hs_generator.cc
+++ b/compiler/cpp/src/generate/t_hs_generator.cc
@@ -1453,7 +1453,7 @@
case t_base_type::TYPE_I32:
return "Int";
case t_base_type::TYPE_I64:
- return "Int";
+ return "Int64";
case t_base_type::TYPE_DOUBLE:
return "Double";
}
diff --git a/lib/hs/src/TBinaryProtocol.hs b/lib/hs/src/TBinaryProtocol.hs
index 2903d01..ff0df16 100644
--- a/lib/hs/src/TBinaryProtocol.hs
+++ b/lib/hs/src/TBinaryProtocol.hs
@@ -12,9 +12,12 @@
version_mask = 0xffff0000
version_1 = 0x80010000;
- getByte i b= 255 .&. (shiftR i (8*b))
+ getByte :: Bits a => a -> Int -> a
+ getByte i b = 255 .&. (shiftR i (8*b))
+
+ getBytes :: (Bits a, Integral a) => a -> Int -> String
getBytes i 0 = []
- getBytes i n = (toEnum (getByte i (n-1)) :: Char):(getBytes i (n-1))
+ getBytes i n = (toEnum $ fromIntegral $ getByte i (n-1)):(getBytes i (n-1))
floatBits :: Double -> Word64
floatBits (D# d#) = W64# (unsafeCoerce# d#)
@@ -40,7 +43,7 @@
writeI16 (TBinaryProtocol tr) b = twrite tr (getBytes b 2)
writeI32 (TBinaryProtocol tr) b = twrite tr (getBytes b 4)
writeI64 (TBinaryProtocol tr) b = twrite tr (getBytes b 8)
- writeDouble (TBinaryProtocol tr) b = writeI64 (TBinaryProtocol tr) (fromIntegral (floatBits b) :: Int)
+ writeDouble (TBinaryProtocol tr) b = writeI64 (TBinaryProtocol tr) (fromIntegral (floatBits b) :: Int64)
writeString (TBinaryProtocol tr) s = do twrite tr (getBytes (length s) 4)
twrite tr s
writeBinary = writeString
@@ -70,7 +73,7 @@
readI32 (TBinaryProtocol tr) = do b <- treadAll tr 4
return $ (fromIntegral (fromIntegral (compBytes b) :: Int32) :: Int)
readI64 (TBinaryProtocol tr) = do b <- treadAll tr 8
- return $ (fromIntegral (fromIntegral (compBytes64 b) :: Int64) :: Int)
+ return $ (fromIntegral (compBytes64 b) :: Int64)
readDouble (TBinaryProtocol tr) = do b <- readI64 (TBinaryProtocol tr)
return $ floatOfBits (fromIntegral b :: Word64)
readBool (TBinaryProtocol tr) = do b <- readByte (TBinaryProtocol tr)
diff --git a/lib/hs/src/Thrift.hs b/lib/hs/src/Thrift.hs
index bb9f0bc..74810a3 100644
--- a/lib/hs/src/Thrift.hs
+++ b/lib/hs/src/Thrift.hs
@@ -137,7 +137,7 @@
writeByte :: TTransport t => a t -> Int -> IO ()
writeI16 :: TTransport t => a t -> Int -> IO ()
writeI32 :: TTransport t => a t -> Int -> IO ()
- writeI64 :: TTransport t => a t -> Int -> IO ()
+ writeI64 :: TTransport t => a t -> Int64 -> IO ()
writeDouble :: TTransport t => a t -> Double -> IO ()
writeString :: TTransport t => a t -> [Char] -> IO ()
writeBinary :: TTransport t => a t -> [Char] -> IO ()
@@ -157,7 +157,7 @@
readByte :: TTransport t => a t -> IO Int
readI16 :: TTransport t => a t -> IO Int
readI32 :: TTransport t => a t -> IO Int
- readI64 :: TTransport t => a t -> IO Int
+ readI64 :: TTransport t => a t -> IO Int64
readDouble :: TTransport t => a t -> IO Double
readString :: TTransport t => a t -> IO [Char]
readBinary :: TTransport t => a t -> IO [Char]