1-- | Platform-specific dynamic linking support. Add new platforms to this file
2-- through conditional compilation.
3{-# LANGUAGE ExistentialQuantification, CPP #-}
4module Util.DynamicLinker where
7import Foreign.Ptr (nullPtr, FunPtr, nullFunPtr,castPtrToFunPtr)
10import System.Posix.DynamicLinker
12import System.Win32.DLL
13import System.Win32.Types
17hostDynamicLibExt :: String
19hostDynamicLibExt = "so"
21hostDynamicLibExt = "dylib"
23hostDynamicLibExt = "dll"
26data ForeignFun = forall a. Fun { fun_name :: String
27 , fun_handle :: FunPtr a
30data DynamicLib = Lib { lib_name :: String
35tryLoadLib :: String -> IO (Maybe DynamicLib)
36tryLoadLib lib = do exactName <- doesFileExist lib
37 let filename = if exactName then lib else lib ++ "." ++ hostDynamicLibExt
38 handle <- dlopen filename [RTLD_NOW]
39 if undl handle == nullPtr
41 else return . Just $ Lib lib handle
44tryLoadFn :: String -> DynamicLib -> IO (Maybe ForeignFun)
45tryLoadFn fn (Lib _ h) = do cFn <- dlsym h fn
48 else return . Just $ Fun fn cFn
50tryLoadLib :: String -> IO (Maybe DynamicLib)
51tryLoadLib lib = do exactName <- doesFileExist lib
52 let filename = if exactName then lib else lib ++ "." ++ hostDynamicLibExt
53 handle <- loadLibrary filename
56 else return . Just $ Lib lib handle
58tryLoadFn :: String -> DynamicLib -> IO (Maybe ForeignFun)
59tryLoadFn fn (Lib _ h) = do cFn <- getProcAddress h fn
62 else return . Just $ Fun fn (castPtrToFunPtr cFn)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list