[project @ 1999-10-20 02:15:56 by andy]
[ghc-hetmet.git] / ghc / interpreter / dynamic.c
index 57653d5..58e085e 100644 (file)
@@ -2,13 +2,15 @@
 /* --------------------------------------------------------------------------
  * Dynamic loading (of .dll or .so files) for Hugs
  *
- * Copyright (c) The University of Nottingham and Yale University, 1994-1997.
- * All rights reserved. See NOTICE for details and conditions of use etc...
- * Hugs version 1.4, December 1997
+ * The Hugs 98 system is Copyright (c) Mark P Jones, Alastair Reid, the
+ * Yale Haskell Group, and the Oregon Graduate Institute of Science and
+ * Technology, 1994-1999, All rights reserved.  It is distributed as
+ * free software under the license in the file "License", which is
+ * included in the distribution.
  *
  * $RCSfile: dynamic.c,v $
- * $Revision: 1.4 $
- * $Date: 1999/03/01 14:46:45 $
+ * $Revision: 1.8 $
+ * $Date: 1999/10/20 02:15:59 $
  * ------------------------------------------------------------------------*/
 
 #include "prelude.h"
 #include "errors.h"
 #include "dynamic.h"
 
-#if HAVE_DLFCN_H /* eg LINUX, SOLARIS, ULTRIX */
+#if HAVE_WINDOWS_H && !defined(__MSDOS__)
+
+#include <windows.h>
+
+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 "<unknown>";
+}
+
+void* getDLLSymbol(dll,symbol)  /* load dll and lookup symbol */
+String dll;
+String symbol; {
+    ObjectFile 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
+        EEND;
+    }
+    return GetProcAddress(instance,symbol);
+}
+
+#elif HAVE_DLFCN_H /* eg LINUX, SOLARIS, ULTRIX */
 
 #include <stdio.h>
 #include <dlfcn.h>
 
-#if 0 /* apparently unused */
 ObjectFile loadLibrary(fn)
 String fn; {
     return dlopen(fn,RTLD_NOW | RTLD_GLOBAL);
@@ -32,7 +67,6 @@ ObjectFile file;
 String symbol; {
     return dlsym(file,symbol);
 }
-#endif
 
 void* getDLLSymbol(dll,symbol)  /* load dll and lookup symbol */
 String dll;
@@ -44,11 +78,17 @@ String symbol; {
 #else /* eg FreeBSD doesn't have RTLD_LAZY */
     ObjectFile instance = dlopen(dll,1);
 #endif
+    void *sym;
+
     if (NULL == instance) {
-        ERRMSG(0) "Error %s while importing DLL \"%s\"", dlerror(), dll
+       ERRMSG(0) "Error while importing DLL \"%s\":\n%s\n", dll, dlerror()
         EEND;
     }
-    return dlsym(instance,symbol);
+    if (sym = dlsym(instance,symbol))
+        return sym;
+
+    ERRMSG(0) "Error loading sym:\n%s\n", dlerror()
+    EEND;
 }
 
 #elif HAVE_DL_H /* eg HPUX */
@@ -67,40 +107,6 @@ String symbol; {
     return (0 == shl_findsym(&instance,symbol,TYPE_PROCEDURE,&r)) ? r : 0;
 }
 
-#elif HAVE_WINDOWS_H && !defined(__MSDOS__)
-
-#include <windows.h>
-
-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 "<unknown>";
-}
-
-void* getDLLSymbol(dll,symbol)  /* load dll and lookup symbol */
-String dll;
-String symbol; {
-    ObjectFile 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
-        EEND;
-    }
-    return GetProcAddress(instance,symbol);
-}
-
 #else /* Dynamic loading not available */
 
 void* getDLLSymbol(dll,symbol)  /* load dll and lookup symbol */