[project @ 2002-02-12 15:17:13 by simonmar]
[ghc-hetmet.git] / ghc / compiler / ghci / Linker.lhs
index 475f707..32a34f1 100644 (file)
@@ -15,12 +15,9 @@ module Linker (
    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 )
@@ -32,20 +29,23 @@ 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
@@ -54,31 +54,30 @@ 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}