summaryrefslogtreecommitdiff
path: root/compiler/utils
diff options
context:
space:
mode:
authorRyan Newton <rrnewton@gmail.com>2013-08-31 15:28:02 -0400
committerRyan Newton <rrnewton@gmail.com>2013-08-31 15:28:02 -0400
commite251a51a990c3a9c95dabab139d42ad69479f61c (patch)
tree94243fe32bb64d0cab79074ef8de8cb3530d2973 /compiler/utils
parent6fd60b2382efa357fe99fa017fd343db9724d43a (diff)
parentea87014a7ad4454f18bb15f6f0ee4b6e61b148be (diff)
downloadhaskell-e251a51a990c3a9c95dabab139d42ad69479f61c.tar.gz
Merge branch 'master' into atomics
Diffstat (limited to 'compiler/utils')
-rw-r--r--compiler/utils/FastString.lhs2
-rw-r--r--compiler/utils/Fingerprint.hsc43
2 files changed, 41 insertions, 4 deletions
diff --git a/compiler/utils/FastString.lhs b/compiler/utils/FastString.lhs
index 25f98021f4..2800d8ab2e 100644
--- a/compiler/utils/FastString.lhs
+++ b/compiler/utils/FastString.lhs
@@ -530,7 +530,7 @@ nilFS = mkFastString ""
getFastStringTable :: IO [[FastString]]
getFastStringTable = do
tbl <- readIORef string_table
- buckets <- mapM (lookupTbl tbl) [0 .. hASH_TBL_SIZE]
+ buckets <- mapM (lookupTbl tbl) [0 .. hASH_TBL_SIZE-1]
return buckets
-- -----------------------------------------------------------------------------
diff --git a/compiler/utils/Fingerprint.hsc b/compiler/utils/Fingerprint.hsc
index 95f31c08bb..e0da2da567 100644
--- a/compiler/utils/Fingerprint.hsc
+++ b/compiler/utils/Fingerprint.hsc
@@ -1,5 +1,5 @@
-- ----------------------------------------------------------------------------
---
+--
-- (c) The University of Glasgow 2006
--
-- Fingerprints for recompilation checking and ABI versioning.
@@ -8,18 +8,26 @@
--
-- ----------------------------------------------------------------------------
-{-# OPTIONS_GHC -fno-warn-orphans #-}
module Fingerprint (
Fingerprint(..), fingerprint0,
readHexFingerprint,
fingerprintData,
- fingerprintString
+ fingerprintString,
+ -- Re-exported from GHC.Fingerprint for GHC >= 7.7, local otherwise
+ getFileHash
) where
#include "md5.h"
##include "HsVersions.h"
import Numeric ( readHex )
+#if __GLASGOW_HASKELL__ < 707
+-- Only needed for getFileHash below.
+import Foreign
+import Panic
+import System.IO
+import Control.Monad ( when )
+#endif
import GHC.Fingerprint
@@ -30,3 +38,32 @@ readHexFingerprint s = Fingerprint w1 w2
[(w1,"")] = readHex s1
[(w2,"")] = readHex (take 16 s2)
+
+#if __GLASGOW_HASKELL__ < 707
+-- Only use this if we're smaller than GHC 7.7, otherwise
+-- GHC.Fingerprint exports a better version of this function.
+
+-- | Computes the hash of a given file.
+-- It loads the full file into memory an does not work with files bigger than
+-- MAXINT.
+getFileHash :: FilePath -> IO Fingerprint
+getFileHash path = withBinaryFile path ReadMode $ \h -> do
+
+ fileSize <- toIntFileSize `fmap` hFileSize h
+
+ allocaBytes fileSize $ \bufPtr -> do
+ n <- hGetBuf h bufPtr fileSize
+ when (n /= fileSize) readFailedError
+ fingerprintData bufPtr fileSize
+
+ where
+ toIntFileSize :: Integer -> Int
+ toIntFileSize size
+ | size > fromIntegral (maxBound :: Int) = throwGhcException $
+ Sorry $ "Fingerprint.getFileHash: Tried to calculate hash of file "
+ ++ path ++ " with size > maxBound :: Int. This is not supported."
+ | otherwise = fromIntegral size
+
+ readFailedError = throwGhcException $
+ Panic $ "Fingerprint.getFileHash: hGetBuf failed on interface file"
+#endif