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)
9import System.Posix.DynamicLinker
11import System.Win32.DLL
12import System.Win32.Types
16hostDynamicLibExt :: String
18hostDynamicLibExt = "so"
20hostDynamicLibExt = "dylib"
22hostDynamicLibExt = "dll"
25data ForeignFun = forall a. Fun { fun_name :: String
26 , fun_handle :: FunPtr a
29data DynamicLib = Lib { lib_name :: String
34tryLoadLib :: String -> IO (Maybe DynamicLib)
35tryLoadLib lib = do handle <- dlopen (lib ++ "." ++ hostDynamicLibExt) [RTLD_NOW]
36 if undl handle == nullPtr
38 else return . Just $ Lib lib handle
41tryLoadFn :: String -> DynamicLib -> IO (Maybe ForeignFun)
42tryLoadFn fn (Lib _ h) = do cFn <- dlsym h fn
45 else return . Just $ Fun fn cFn
47tryLoadLib :: String -> IO (Maybe DynamicLib)
48tryLoadLib lib = do handle <- loadLibrary (lib ++ "." ++ hostDynamicLibExt)
51 else return . Just $ Lib lib handle
53tryLoadFn :: String -> DynamicLib -> IO (Maybe ForeignFun)
54tryLoadFn fn (Lib _ h) = do cFn <- getProcAddress h fn
57 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