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
40tryLoadLib :: String -> IO (Maybe DynamicLib)
41tryLoadLib lib = do exactName <- doesFileExist lib
42 let filename = if exactName then lib else lib ++ "." ++ hostDynamicLibExt
43 handle <- dlopen filename [RTLD_NOW, RTLD_GLOBAL]
44 if undl handle == nullPtr
46 else return . Just $ Lib lib handle
49tryLoadFn :: String -> DynamicLib -> IO (Maybe ForeignFun)
50tryLoadFn fn (Lib _ h) = do cFn <- dlsym h fn
53 else return . Just $ Fun fn cFn
55tryLoadLib :: String -> IO (Maybe DynamicLib)
56tryLoadLib lib = do exactName <- doesFileExist lib
57 let filename = if exactName then lib else lib ++ "." ++ hostDynamicLibExt
58 handle <- loadLibrary filename
61 else return . Just $ Lib lib handle
63tryLoadFn :: String -> DynamicLib -> IO (Maybe ForeignFun)
64tryLoadFn fn (Lib _ h) = do cFn <- getProcAddress h fn
67 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