You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by br...@apache.org on 2009/03/24 01:34:17 UTC

svn commit: r757619 - in /incubator/thrift/trunk: compiler/cpp/src/generate/t_hs_generator.cc lib/hs/src/TBinaryProtocol.hs lib/hs/src/Thrift.hs

Author: bryanduxbury
Date: Tue Mar 24 00:34:16 2009
New Revision: 757619

URL: http://svn.apache.org/viewvc?rev=757619&view=rev
Log:
THRIFT-385. hs: 64-bit integer and double types incorrectly serialized on 32-bit platforms

Use 64-bit types where appropriate.


Modified:
    incubator/thrift/trunk/compiler/cpp/src/generate/t_hs_generator.cc
    incubator/thrift/trunk/lib/hs/src/TBinaryProtocol.hs
    incubator/thrift/trunk/lib/hs/src/Thrift.hs

Modified: incubator/thrift/trunk/compiler/cpp/src/generate/t_hs_generator.cc
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/compiler/cpp/src/generate/t_hs_generator.cc?rev=757619&r1=757618&r2=757619&view=diff
==============================================================================
--- incubator/thrift/trunk/compiler/cpp/src/generate/t_hs_generator.cc (original)
+++ incubator/thrift/trunk/compiler/cpp/src/generate/t_hs_generator.cc Tue Mar 24 00:34:16 2009
@@ -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";
     }

Modified: incubator/thrift/trunk/lib/hs/src/TBinaryProtocol.hs
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/hs/src/TBinaryProtocol.hs?rev=757619&r1=757618&r2=757619&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/hs/src/TBinaryProtocol.hs (original)
+++ incubator/thrift/trunk/lib/hs/src/TBinaryProtocol.hs Tue Mar 24 00:34:16 2009
@@ -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)

Modified: incubator/thrift/trunk/lib/hs/src/Thrift.hs
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/hs/src/Thrift.hs?rev=757619&r1=757618&r2=757619&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/hs/src/Thrift.hs (original)
+++ incubator/thrift/trunk/lib/hs/src/Thrift.hs Tue Mar 24 00:34:16 2009
@@ -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]