@@ -5,11 +5,12 @@ module Util.DynamicLinker where
55
66#ifdef IDRIS_FFI
77import Foreign.LibFFI
8−import Foreign.Ptr (nullPtr, FunPtr, nullFunPtr,castPtrToFunPtr)
8+import Foreign.Ptr (Ptr(), nullPtr, FunPtr, nullFunPtr, castPtrToFunPtr)
99import System.Directory
1010#ifndef WINDOWS
1111import System.Posix.DynamicLinker
1212#else
13+import qualified Control.Exception as Exception (catch, IOException)
1314import System.Win32.DLL
1415import System.Win32.Types
1516type DL = HMODULE
@@ -63,10 +64,13 @@ tryLoadFn fn (Lib _ h) = do cFn <- dlsym h fn
6364tryLoadLib :: String -> IO (Maybe DynamicLib)
6465tryLoadLib lib = do exactName <- doesFileExist lib
6566 let filename = if exactName then lib else lib ++ "." ++ hostDynamicLibExt
66− handle <- loadLibrary filename
67+ handle <- Exception.catch (loadLibrary filename) nullPtrOnException
6768 if handle == nullPtr
6869 then return Nothing
6970 else return . Just $ Lib lib handle
71+ where nullPtrOnException :: Exception.IOException -> IO DL
72+ nullPtrOnException e = return nullPtr
73+ -- `show e` will however give broken error message
7074
7175tryLoadFn :: String -> DynamicLib -> IO (Maybe ForeignFun)
7276tryLoadFn fn (Lib _ h) = do cFn <- getProcAddress h fn