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"
25hostDynamicLibExt = error $ unwords
26 [ "Undefined file extension for dynamic libraries"
27 , "in Idris' Util.DynamicLinker."
31data ForeignFun = forall a. Fun { fun_name :: String
32 , fun_handle :: FunPtr a
35data DynamicLib = Lib { lib_name :: String
39instance Eq DynamicLib where
40 (Lib a _) == (Lib b _) = a == b
43tryLoadLib :: String -> IO (Maybe DynamicLib)
44tryLoadLib lib = do exactName <- doesFileExist lib
45 let filename = if exactName then lib else lib ++ "." ++ hostDynamicLibExt
46 handle <- dlopen filename [RTLD_NOW, RTLD_GLOBAL]
47 if undl handle == nullPtr
49 else return . Just $ Lib lib handle
52tryLoadFn :: String -> DynamicLib -> IO (Maybe ForeignFun)
53tryLoadFn fn (Lib _ h) = do cFn <- dlsym h fn
56 else return . Just $ Fun fn cFn
58tryLoadLib :: String -> IO (Maybe DynamicLib)
59tryLoadLib lib = do exactName <- doesFileExist lib
60 let filename = if exactName then lib else lib ++ "." ++ hostDynamicLibExt
61 handle <- loadLibrary filename
64 else return . Just $ Lib lib handle
66tryLoadFn :: String -> DynamicLib -> IO (Maybe ForeignFun)
67tryLoadFn fn (Lib _ h) = do cFn <- getProcAddress h fn
70 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