diff options
| author | Ian Lynagh <igloo@earth.li> | 2012-07-20 16:54:01 +0100 |
|---|---|---|
| committer | Ian Lynagh <igloo@earth.li> | 2012-07-20 16:54:01 +0100 |
| commit | 2844abb416975d589ab598162e70eff0df49751f (patch) | |
| tree | 04751d84c518758d3a37d4382dae161d4804395f /compiler/utils/Fingerprint.hsc | |
| parent | 8a1334404cee2f1d668bc77786b1d6381877612c (diff) | |
| download | haskell-2844abb416975d589ab598162e70eff0df49751f.tar.gz | |
GHC 7.4 is now required for building HEAD
Diffstat (limited to 'compiler/utils/Fingerprint.hsc')
| -rw-r--r-- | compiler/utils/Fingerprint.hsc | 64 |
1 files changed, 0 insertions, 64 deletions
diff --git a/compiler/utils/Fingerprint.hsc b/compiler/utils/Fingerprint.hsc index 0b8c02cf7b..5f9bef18b1 100644 --- a/compiler/utils/Fingerprint.hsc +++ b/compiler/utils/Fingerprint.hsc @@ -24,71 +24,7 @@ import Outputable import Text.Printf import Numeric ( readHex ) -##if __GLASGOW_HASKELL__ >= 701 --- The MD5 implementation is now in base, to support Typeable import GHC.Fingerprint -##endif - -##if __GLASGOW_HASKELL__ < 701 -import Data.Char -import Foreign -import Foreign.C -import GHC.IO (unsafeDupablePerformIO) - --- Using 128-bit MD5 fingerprints for now. - -data Fingerprint = Fingerprint {-# UNPACK #-} !Word64 {-# UNPACK #-} !Word64 - deriving (Eq, Ord) - -- or ByteString? - -fingerprint0 :: Fingerprint -fingerprint0 = Fingerprint 0 0 - -peekFingerprint :: Ptr Word8 -> IO Fingerprint -peekFingerprint p = do - let peekW64 :: Ptr Word8 -> Int -> Word64 -> IO Word64 - STRICT3(peekW64) - peekW64 _ 0 i = return i - peekW64 p n i = do - w8 <- peek p - peekW64 (p `plusPtr` 1) (n-1) - ((i `shiftL` 8) .|. fromIntegral w8) - - high <- peekW64 p 8 0 - low <- peekW64 (p `plusPtr` 8) 8 0 - return (Fingerprint high low) - -fingerprintData :: Ptr Word8 -> Int -> IO Fingerprint -fingerprintData buf len = do - allocaBytes (#const sizeof(struct MD5Context)) $ \pctxt -> do - c_MD5Init pctxt - c_MD5Update pctxt buf (fromIntegral len) - allocaBytes 16 $ \pdigest -> do - c_MD5Final pdigest pctxt - peekFingerprint (castPtr pdigest) - --- This is duplicated in libraries/base/GHC/Fingerprint.hs -fingerprintString :: String -> Fingerprint -fingerprintString str = unsafeDupablePerformIO $ - withArrayLen word8s $ \len p -> - fingerprintData p len - where word8s = concatMap f str - f c = let w32 :: Word32 - w32 = fromIntegral (ord c) - in [fromIntegral (w32 `shiftR` 24), - fromIntegral (w32 `shiftR` 16), - fromIntegral (w32 `shiftR` 8), - fromIntegral w32] - -data MD5Context - -foreign import ccall unsafe "MD5Init" - c_MD5Init :: Ptr MD5Context -> IO () -foreign import ccall unsafe "MD5Update" - c_MD5Update :: Ptr MD5Context -> Ptr Word8 -> CInt -> IO () -foreign import ccall unsafe "MD5Final" - c_MD5Final :: Ptr Word8 -> Ptr MD5Context -> IO () -##endif instance Outputable Fingerprint where ppr (Fingerprint w1 w2) = text (printf "%016x%016x" w1 w2) |
