X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Finterpreter%2Fdynamic.c;h=1f3749195fc93e7a8ed3653c306535100de21196;hb=d1417a2edfcc842415bb651be80d5669a31cd717;hp=002bf338ba704f5f61efaa4590d7237614309bde;hpb=9198aaf324dd1b4bb876e26b60bb4d11c0485510;p=ghc-hetmet.git diff --git a/ghc/interpreter/dynamic.c b/ghc/interpreter/dynamic.c index 002bf33..1f37491 100644 --- a/ghc/interpreter/dynamic.c +++ b/ghc/interpreter/dynamic.c @@ -9,32 +9,44 @@ * included in the distribution. * * $RCSfile: dynamic.c,v $ - * $Revision: 1.11 $ - * $Date: 1999/10/28 14:32:06 $ + * $Revision: 1.15 $ + * $Date: 2000/03/23 14:54:21 $ * ------------------------------------------------------------------------*/ -#include "prelude.h" +#include "hugsbasictypes.h" #include "storage.h" #include "errors.h" -#include "dynamic.h" +#include "connect.h" #if HAVE_WINDOWS_H && !defined(__MSDOS__) #include -void* getDLLSymbol(line,dll0,symbol) /* load dll and lookup symbol */ +void* getDLLSymbol(line,dll0,symbol0) /* load dll and lookup symbol */ Int line; String dll0; -String symbol; { +String symbol0; { void* sym; char dll[1000]; + char symbol[100]; ObjectFile instance; - if (strlen(dll0) > 996) { - ERRMSG(line) "Excessively long library name:\n%s\n",dll + + if (strlen(dll0) > 996-strlen(installDir)) { + ERRMSG(line) "Excessively long library name:\n%s\n",dll0 EEND; } - strcpy(dll,dll0); + dll[0] = 0; + if (strcmp("nHandle",dll0)==0) strcat(dll,installDir); + strcat(dll,dll0); strcat(dll, ".dll"); + + if (strlen(symbol0) > 96) { + ERRMSG(line) "Excessively long symbol name:\n%s\n",symbol0 + EEND; + } + strcpy(&(symbol[1]),symbol0); + symbol[0] = '_'; + instance = LoadLibrary(dll); if (NULL == instance) { /* GetLastError allegedly provides more detail - in practice, @@ -43,7 +55,8 @@ String symbol; { ERRMSG(line) "Can't open library \"%s\"", dll EEND; } - return GetProcAddress(instance,symbol); + sym = GetProcAddress(instance,symbol0); + return sym; } Bool stdcallAllowed ( void ) @@ -68,11 +81,13 @@ String symbol; { void* sym; char dll[1000]; ObjectFile instance; - if (strlen(dll0) > 996) { - ERRMSG(line) "Excessively long library name:\n%s\n",dll + if (strlen(dll0) > 996-strlen(installDir)) { + ERRMSG(line) "Excessively long library name:\n%s\n",dll0 EEND; } - strcpy(dll,dll0); + dll[0] = 0; + if (strcmp("nHandle",dll0)==0) strcat(dll,installDir); + strcat(dll,dll0); strcat(dll, ".so"); #ifdef RTLD_NOW instance = dlopen(dll,RTLD_NOW); @@ -114,7 +129,7 @@ String symbol; { ObjectFile instance = shl_load(dll,BIND_IMMEDIATE,0L); void* r; if (NULL == instance) { - ERRMSG(line) "Error while importing DLL \"%s\"", dll + ERRMSG(line) "Error while importing DLL \"%s\"", dll0 EEND; } return (0 == shl_findsym(&instance,symbol,TYPE_PROCEDURE,&r)) ? r : 0;