Add a magic number to the beginning of interface files (0x1face :-) to
avoid trying to read old text-style interfaces as binary (the usual
result is an attempt to allocate a ByteArray larger than the available
memory size and an obscure crash).
import {-# SOURCE #-} Module
import FastString
import Unique
import {-# SOURCE #-} Module
import FastString
import Unique
import UniqFM
#if __GLASGOW_HASKELL__ < 503
import UniqFM
#if __GLASGOW_HASKELL__ < 503
getBinFileWithDict :: Binary a => FilePath -> IO a
getBinFileWithDict file_path = do
bh <- Binary.readBinMem file_path
getBinFileWithDict :: Binary a => FilePath -> IO a
getBinFileWithDict file_path = do
bh <- Binary.readBinMem file_path
+ magic <- get bh
+ when (magic /= binaryInterfaceMagic) $
+ throwDyn (ProgramError (
+ "magic number mismatch: old/corrupt interface file?"))
dict_p <- Binary.get bh -- get the dictionary ptr
data_p <- tellBin bh
seekBin bh dict_p
dict_p <- Binary.get bh -- get the dictionary ptr
data_p <- tellBin bh
seekBin bh dict_p
initBinMemSize = (1024*1024) :: Int
initBinMemSize = (1024*1024) :: Int
+binaryInterfaceMagic = 0x1face :: Word32
+
putBinFileWithDict :: Binary a => FilePath -> Module -> a -> IO ()
putBinFileWithDict file_path mod a = do
bh <- openBinMem initBinMemSize mod
putBinFileWithDict :: Binary a => FilePath -> Module -> a -> IO ()
putBinFileWithDict file_path mod a = do
bh <- openBinMem initBinMemSize mod
+ put_ bh binaryInterfaceMagic
p <- tellBin bh
put_ bh p -- placeholder for ptr to dictionary
put_ bh a
p <- tellBin bh
put_ bh p -- placeholder for ptr to dictionary
put_ bh a