addDLL -- :: String -> IO (Ptr CChar)
) where
-import PrelByteArr
-import PrelPack ( packString )
-
import Monad ( when )
-import CTypes ( CChar )
+import Foreign.C
import Foreign ( Ptr, nullPtr )
import Panic ( panic )
import DriverUtil ( prefixUnderscore )
lookupSymbol :: String -> IO (Maybe (Ptr a))
lookupSymbol str_in = do
let str = prefixUnderscore str_in
- addr <- c_lookupSymbol (packString str)
- if addr == nullPtr
+ withCString str $ \c_str -> do
+ addr <- c_lookupSymbol c_str
+ if addr == nullPtr
then return Nothing
else return (Just addr)
loadObj :: String -> IO ()
-loadObj str = do
- r <- c_loadObj (packString str)
- when (r == 0) (panic "loadObj: failed")
+loadObj str =
+ withCString str $ \c_str -> do
+ r <- c_loadObj c_str
+ when (r == 0) (panic "loadObj: failed")
unloadObj :: String -> IO ()
-unloadObj str = do
- r <- c_unloadObj (packString str)
- when (r == 0) (panic "unloadObj: failed")
+unloadObj str =
+ withCString str $ \c_str -> do
+ r <- c_unloadObj c_str
+ when (r == 0) (panic "unloadObj: failed")
resolveObjs :: IO Bool
resolveObjs = do
addDLL :: String -> String -> IO (Ptr CChar)
addDLL path lib = do
- maybe_errmsg <- c_addDLL (packString path) (packString lib)
- return maybe_errmsg
-
-
-foreign import "initLinker" unsafe
- initLinker :: IO ()
+ withCString path $ \c_path -> do
+ withCString lib $ \c_lib -> do
+ maybe_errmsg <- c_addDLL c_path c_lib
+ return maybe_errmsg
-- ---------------------------------------------------------------------------
-- Foreign declaractions to RTS entry points which does the real work;
-- ---------------------------------------------------------------------------
-type PackedString = ByteArray Int
+foreign import "initLinker" unsafe
+ initLinker :: IO ()
foreign import "lookupSymbol" unsafe
- c_lookupSymbol :: PackedString -> IO (Ptr a)
+ c_lookupSymbol :: CString -> IO (Ptr a)
foreign import "loadObj" unsafe
- c_loadObj :: PackedString -> IO Int
+ c_loadObj :: CString -> IO Int
foreign import "unloadObj" unsafe
- c_unloadObj :: PackedString -> IO Int
+ c_unloadObj :: CString -> IO Int
foreign import "resolveObjs" unsafe
c_resolveObjs :: IO Int
foreign import "addDLL" unsafe
- c_addDLL :: PackedString -> PackedString -> IO (Ptr CChar)
+ c_addDLL :: CString -> CString -> IO (Ptr CChar)
\end{code}