From: sewardj Date: Thu, 28 Oct 1999 14:32:08 +0000 (+0000) Subject: [project @ 1999-10-28 14:32:06 by sewardj] X-Git-Tag: Approximately_9120_patches~5652 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=9198aaf324dd1b4bb876e26b60bb4d11c0485510;p=ghc-hetmet.git [project @ 1999-10-28 14:32:06 by sewardj] Make platform-specific dynamic loaders add ".so", ".dll" etc to library names, so that f-i decls can be written without them. Modify Prelude accordingly. Remove unused functionality in dynamic.c and make err msgs a bit better. --- diff --git a/ghc/interpreter/dynamic.c b/ghc/interpreter/dynamic.c index 2144706..002bf33 100644 --- a/ghc/interpreter/dynamic.c +++ b/ghc/interpreter/dynamic.c @@ -9,8 +9,8 @@ * included in the distribution. * * $RCSfile: dynamic.c,v $ - * $Revision: 1.10 $ - * $Date: 1999/10/26 17:27:39 $ + * $Revision: 1.11 $ + * $Date: 1999/10/28 14:32:06 $ * ------------------------------------------------------------------------*/ #include "prelude.h" @@ -22,31 +22,25 @@ #include -ObjectFile loadLibrary(fn) -String fn; { - return LoadLibrary(fn); -} - -void* lookupSymbol(file,symbol) -ObjectFile file; -String symbol; { - return GetProcAddress(file,symbol); -} - -const char *dlerror(void) -{ - return ""; -} - -void* getDLLSymbol(dll,symbol) /* load dll and lookup symbol */ -String dll; +void* getDLLSymbol(line,dll0,symbol) /* load dll and lookup symbol */ +Int line; +String dll0; String symbol; { - ObjectFile instance = LoadLibrary(dll); + void* sym; + char dll[1000]; + ObjectFile instance; + if (strlen(dll0) > 996) { + ERRMSG(line) "Excessively long library name:\n%s\n",dll + EEND; + } + strcpy(dll,dll0); + strcat(dll, ".dll"); + instance = LoadLibrary(dll); if (NULL == instance) { /* GetLastError allegedly provides more detail - in practice, * it tells you nothing more. */ - ERRMSG(0) "Error while importing DLL \"%s\"", dll + ERRMSG(line) "Can't open library \"%s\"", dll EEND; } return GetProcAddress(instance,symbol); @@ -67,37 +61,35 @@ Bool stdcallAllowed ( void ) #include #include -ObjectFile loadLibrary(fn) -String fn; { - return dlopen(fn,RTLD_NOW | RTLD_GLOBAL); -} - -void* lookupSymbol(file,symbol) -ObjectFile file; -String symbol; { - return dlsym(file,symbol); -} - -void* getDLLSymbol(dll,symbol) /* load dll and lookup symbol */ -String dll; +void* getDLLSymbol(line,dll0,symbol) /* load dll and lookup symbol */ +Int line; +String dll0; String symbol; { + void* sym; + char dll[1000]; + ObjectFile instance; + if (strlen(dll0) > 996) { + ERRMSG(line) "Excessively long library name:\n%s\n",dll + EEND; + } + strcpy(dll,dll0); + strcat(dll, ".so"); #ifdef RTLD_NOW - ObjectFile instance = dlopen(dll,RTLD_NOW); + instance = dlopen(dll,RTLD_NOW); #elif defined RTLD_LAZY /* eg SunOS4 doesn't have RTLD_NOW */ - ObjectFile instance = dlopen(dll,RTLD_LAZY); + instance = dlopen(dll,RTLD_LAZY); #else /* eg FreeBSD doesn't have RTLD_LAZY */ - ObjectFile instance = dlopen(dll,1); + instance = dlopen(dll,1); #endif - void *sym; if (NULL == instance) { - ERRMSG(0) "Error while importing DLL \"%s\":\n%s\n", dll, dlerror() + ERRMSG(line) "Can't open library \"%s\":\n %s\n",dll,dlerror() EEND; } if ((sym = dlsym(instance,symbol))) return sym; - ERRMSG(0) "Error loading sym:\n%s\n", dlerror() + ERRMSG(line) "Can't find symbol \"%s\" in library \"%s\"",symbol,dll EEND; } @@ -115,13 +107,14 @@ Bool stdcallAllowed ( void ) #include -void* getDLLSymbol(dll,symbol) /* load dll and lookup symbol */ -String dll; +void* getDLLSymbol(line,dll0,symbol) /* load dll and lookup symbol */ +Int line; +String dll0; String symbol; { ObjectFile instance = shl_load(dll,BIND_IMMEDIATE,0L); void* r; if (NULL == instance) { - ERRMSG(0) "Error while importing DLL \"%s\"", dll + ERRMSG(line) "Error while importing DLL \"%s\"", dll EEND; } return (0 == shl_findsym(&instance,symbol,TYPE_PROCEDURE,&r)) ? r : 0; @@ -139,13 +132,14 @@ Bool stdcallAllowed ( void ) #else /* Dynamic loading not available */ -void* getDLLSymbol(dll,symbol) /* load dll and lookup symbol */ -String dll; +void* getDLLSymbol(line,dll0,symbol) /* load dll and lookup symbol */ +Int line; +String dll0; String symbol; { #if 1 /* very little to choose between these options */ return 0; #else - ERRMSG(0) "This Hugs build does not support dynamic loading\n" + ERRMSG(line) "This Hugs build does not support dynamic loading\n" EEND; #endif } diff --git a/ghc/interpreter/dynamic.h b/ghc/interpreter/dynamic.h index 61612a0..9534312 100644 --- a/ghc/interpreter/dynamic.h +++ b/ghc/interpreter/dynamic.h @@ -1,6 +1,4 @@ -extern void* getDLLSymbol Args((String,String)); -extern void* lookupSymbol Args((ObjectFile file, String symbol)); -extern ObjectFile loadLibrary Args((String fn)); +extern void* getDLLSymbol Args((Int,String,String)); extern Bool stdcallAllowed Args((void)); diff --git a/ghc/interpreter/lib/Prelude.hs b/ghc/interpreter/lib/Prelude.hs index dd5f825..3c80d2b 100644 --- a/ghc/interpreter/lib/Prelude.hs +++ b/ghc/interpreter/lib/Prelude.hs @@ -1703,24 +1703,24 @@ data IOResult = IOResult deriving (Show) type FILE_STAR = Int -- FILE * -foreign import "nHandle.so" "nh_stdin" nh_stdin :: IO FILE_STAR -foreign import "nHandle.so" "nh_stdout" nh_stdout :: IO FILE_STAR -foreign import "nHandle.so" "nh_stderr" nh_stderr :: IO FILE_STAR -foreign import "nHandle.so" "nh_write" nh_write :: FILE_STAR -> Int -> IO () -foreign import "nHandle.so" "nh_read" nh_read :: FILE_STAR -> IO Int -foreign import "nHandle.so" "nh_open" nh_open :: Addr -> Int -> IO FILE_STAR -foreign import "nHandle.so" "nh_flush" nh_flush :: FILE_STAR -> IO () -foreign import "nHandle.so" "nh_close" nh_close :: FILE_STAR -> IO () -foreign import "nHandle.so" "nh_errno" nh_errno :: IO Int - -foreign import "nHandle.so" "nh_malloc" nh_malloc :: Int -> IO Addr -foreign import "nHandle.so" "nh_free" nh_free :: Addr -> IO () -foreign import "nHandle.so" "nh_store" nh_store :: Addr -> Int -> IO () -foreign import "nHandle.so" "nh_load" nh_load :: Addr -> IO Int - -foreign import "nHandle.so" "nh_argc" nh_argc :: IO Int -foreign import "nHandle.so" "nh_argvb" nh_argvb :: Int -> Int -> IO Int -foreign import "nHandle.so" "nh_getenv" nh_getenv :: Addr -> IO Addr +foreign import "nHandle" "nh_stdin" nh_stdin :: IO FILE_STAR +foreign import "nHandle" "nh_stdout" nh_stdout :: IO FILE_STAR +foreign import "nHandle" "nh_stderr" nh_stderr :: IO FILE_STAR +foreign import "nHandle" "nh_write" nh_write :: FILE_STAR -> Int -> IO () +foreign import "nHandle" "nh_read" nh_read :: FILE_STAR -> IO Int +foreign import "nHandle" "nh_open" nh_open :: Addr -> Int -> IO FILE_STAR +foreign import "nHandle" "nh_flush" nh_flush :: FILE_STAR -> IO () +foreign import "nHandle" "nh_close" nh_close :: FILE_STAR -> IO () +foreign import "nHandle" "nh_errno" nh_errno :: IO Int + +foreign import "nHandle" "nh_malloc" nh_malloc :: Int -> IO Addr +foreign import "nHandle" "nh_free" nh_free :: Addr -> IO () +foreign import "nHandle" "nh_store" nh_store :: Addr -> Int -> IO () +foreign import "nHandle" "nh_load" nh_load :: Addr -> IO Int + +foreign import "nHandle" "nh_argc" nh_argc :: IO Int +foreign import "nHandle" "nh_argvb" nh_argvb :: Int -> Int -> IO Int +foreign import "nHandle" "nh_getenv" nh_getenv :: Addr -> IO Addr copy_String_to_cstring :: String -> IO Addr copy_String_to_cstring s diff --git a/ghc/interpreter/translate.c b/ghc/interpreter/translate.c index 7f11faa..62147b5 100644 --- a/ghc/interpreter/translate.c +++ b/ghc/interpreter/translate.c @@ -10,8 +10,8 @@ * included in the distribution. * * $RCSfile: translate.c,v $ - * $Revision: 1.12 $ - * $Date: 1999/10/27 11:57:32 $ + * $Revision: 1.13 $ + * $Date: 1999/10/28 14:32:07 $ * ------------------------------------------------------------------------*/ #include "prelude.h" @@ -874,7 +874,8 @@ Void implementForeignImport ( Name n ) { Pair extName = name(n).defn; - void* funPtr = getDLLSymbol(textToStr(textOf(fst(extName))), + void* funPtr = getDLLSymbol(name(n).line, + textToStr(textOf(fst(extName))), textToStr(textOf(snd(extName)))); List extra_args = doubleton(mkPtr(descriptor),mkPtr(funPtr)); StgRhs rhs = makeStgPrim(n,addState,extra_args,descriptor->arg_tys, diff --git a/ghc/lib/hugs/Prelude.hs b/ghc/lib/hugs/Prelude.hs index dd5f825..3c80d2b 100644 --- a/ghc/lib/hugs/Prelude.hs +++ b/ghc/lib/hugs/Prelude.hs @@ -1703,24 +1703,24 @@ data IOResult = IOResult deriving (Show) type FILE_STAR = Int -- FILE * -foreign import "nHandle.so" "nh_stdin" nh_stdin :: IO FILE_STAR -foreign import "nHandle.so" "nh_stdout" nh_stdout :: IO FILE_STAR -foreign import "nHandle.so" "nh_stderr" nh_stderr :: IO FILE_STAR -foreign import "nHandle.so" "nh_write" nh_write :: FILE_STAR -> Int -> IO () -foreign import "nHandle.so" "nh_read" nh_read :: FILE_STAR -> IO Int -foreign import "nHandle.so" "nh_open" nh_open :: Addr -> Int -> IO FILE_STAR -foreign import "nHandle.so" "nh_flush" nh_flush :: FILE_STAR -> IO () -foreign import "nHandle.so" "nh_close" nh_close :: FILE_STAR -> IO () -foreign import "nHandle.so" "nh_errno" nh_errno :: IO Int - -foreign import "nHandle.so" "nh_malloc" nh_malloc :: Int -> IO Addr -foreign import "nHandle.so" "nh_free" nh_free :: Addr -> IO () -foreign import "nHandle.so" "nh_store" nh_store :: Addr -> Int -> IO () -foreign import "nHandle.so" "nh_load" nh_load :: Addr -> IO Int - -foreign import "nHandle.so" "nh_argc" nh_argc :: IO Int -foreign import "nHandle.so" "nh_argvb" nh_argvb :: Int -> Int -> IO Int -foreign import "nHandle.so" "nh_getenv" nh_getenv :: Addr -> IO Addr +foreign import "nHandle" "nh_stdin" nh_stdin :: IO FILE_STAR +foreign import "nHandle" "nh_stdout" nh_stdout :: IO FILE_STAR +foreign import "nHandle" "nh_stderr" nh_stderr :: IO FILE_STAR +foreign import "nHandle" "nh_write" nh_write :: FILE_STAR -> Int -> IO () +foreign import "nHandle" "nh_read" nh_read :: FILE_STAR -> IO Int +foreign import "nHandle" "nh_open" nh_open :: Addr -> Int -> IO FILE_STAR +foreign import "nHandle" "nh_flush" nh_flush :: FILE_STAR -> IO () +foreign import "nHandle" "nh_close" nh_close :: FILE_STAR -> IO () +foreign import "nHandle" "nh_errno" nh_errno :: IO Int + +foreign import "nHandle" "nh_malloc" nh_malloc :: Int -> IO Addr +foreign import "nHandle" "nh_free" nh_free :: Addr -> IO () +foreign import "nHandle" "nh_store" nh_store :: Addr -> Int -> IO () +foreign import "nHandle" "nh_load" nh_load :: Addr -> IO Int + +foreign import "nHandle" "nh_argc" nh_argc :: IO Int +foreign import "nHandle" "nh_argvb" nh_argvb :: Int -> Int -> IO Int +foreign import "nHandle" "nh_getenv" nh_getenv :: Addr -> IO Addr copy_String_to_cstring :: String -> IO Addr copy_String_to_cstring s