ObjectFileLoader.st
changeset 180 a38d34ef8bde
parent 178 7342b41b7fe7
child 182 b8316f207380
--- a/ObjectFileLoader.st	Tue Dec 26 18:29:19 1995 +0100
+++ b/ObjectFileLoader.st	Tue Dec 26 19:43:21 1995 +0100
@@ -65,6 +65,8 @@
 # undef COFF
 # undef ELF
 # undef A_DOT_OUT
+# define HAS_DL
+# define WIN_DL
 #endif
 
 /*
@@ -132,6 +134,35 @@
 # include <sys/ldr.h>
 # include <errno.h>
 #endif
+
+#ifdef WIN_DL
+
+# ifdef WIN32
+#   undef INT
+#   undef Array
+#   undef Number
+#   undef Method
+
+#   ifdef i386
+#    define _X86_
+#   endif
+
+/* #  include <windows.h> /* */
+#  include <windef.h> /* */
+#  include <winbase.h> /* */
+
+#   ifdef DEF_Array
+#    define Array DEF_Array
+#   endif
+#   ifdef DEF_Number
+#    define Number DEF_Number
+#   endif
+#   ifdef DEF_Method
+#    define Method DEF_Method
+#   endif
+# endif
+
+#endif
 %}
 ! !
 
@@ -374,8 +405,7 @@
     (os = 'linux') ifTrue:[^ '.o'].
     (os = 'aix') ifTrue:[^ '.so'].
     (os = 'hpux') ifTrue:[^ '.sl'].
-    (os = 'msdos') ifTrue:[^ '.dll'].
-    (os = 'mswindows') ifTrue:[^ '.dll'].
+    (os = 'win32') ifTrue:[^ '.dll'].
     (os = 'os2') ifTrue:[^ '.dll'].
 
     "/ mhmh what is a useful default ?
@@ -395,8 +425,7 @@
     (os = 'linux') ifTrue:[^ #('.o' '.obj' '.so') ].
     (os = 'aix') ifTrue:[^ #('.o' '.so') ].
     (os = 'hpux') ifTrue:[^ #('.o' '.sl') ].
-    (os = 'msdos') ifTrue:[^ #('.dll') ].
-    (os = 'mswindows') ifTrue:[^ #('.dll') ].
+    (os = 'win32') ifTrue:[^ #('.dll') ].
     (os = 'os2') ifTrue:[^ #('.dll') ].
 
     "/ mhmh what is a useful default ?
@@ -785,19 +814,27 @@
      first, expect the classes-name to be the fileName-base
     "
     className := OperatingSystem baseNameOf:aFileName.
-    (className endsWith:'.o') ifTrue:[
-	suffixLen := 2.
-    ] ifFalse:[
-	(className endsWith:'.obj') ifTrue:[
-	    suffixLen := 4.
-	] ifFalse:[
-	    (className endsWith:'.so') ifTrue:[
-		suffixLen := 3.
-	    ] ifFalse:[
-		suffixLen := 0.
+    suffixLen := 0.
+    self validBinaryExtensions do:[:suffix |
+	suffixLen == 0 ifTrue:[
+	    (className endsWith:suffix) ifTrue:[
+		suffixLen := suffix size
 	    ]
 	]
     ].
+"/    (className endsWith:'.o') ifTrue:[
+"/	suffixLen := 2.
+"/    ] ifFalse:[
+"/	(className endsWith:'.obj') ifTrue:[
+"/	    suffixLen := 4.
+"/	] ifFalse:[
+"/	    (className endsWith:'.so') ifTrue:[
+"/		suffixLen := 3.
+"/	    ] ifFalse:[
+"/		suffixLen := 0.
+"/	    ]
+"/	]
+"/    ].
     suffixLen ~~ 0 ifTrue:[
 	className := className copyWithoutLast:suffixLen
     ].
@@ -1147,7 +1184,7 @@
 deinitializeClassesFromModule:handle
     "send #deinitialize to all classes of a module"
 
-    |id classes|
+    |classes|
 
     classes := handle classes.
     classes notNil ifTrue:[
@@ -1239,6 +1276,13 @@
      * dont know how to do it
      */
 #endif
+
+#ifdef WIN_DL
+    /*
+     * dont know how to do it
+     */
+#endif
+
 %}.
     ^ list
 !
@@ -1301,6 +1345,38 @@
   }
 #endif /* GNU_DL */
 
+#ifdef WIN_DL
+  {
+    void *h;
+    void *addr;
+    int val;
+    FARPROC entry;
+    HMODULE handle;
+
+    if (__bothSmallInteger(sysHandle1, sysHandle2)) {
+        val = (_intVal(sysHandle2) << 16) + _intVal(sysHandle1);
+        handle = (HMODULE)(val);
+        if (__isString(aString)) {
+            if (ObjectFileLoader_Verbose == true)
+                printf("get sym <%s> handle = %x\n", __stringVal(aString), (int)handle);
+            entry = GetProcAddress(handle, (char *) __stringVal(aString));
+            if (entry != NULL) {
+		addr = (void *)entry;
+                if (ObjectFileLoader_Verbose == true) {
+                    printf("GetProcAddr %s ok; addr = %x\n", __stringVal(aString), addr);
+                }
+                lowAddr = _MKSMALLINT( (int)addr & 0xFFFF );
+                hiAddr = _MKSMALLINT( ((int)addr >> 16) & 0xFFFF );
+            } else {
+                if (ObjectFileLoader_Verbose == true) {
+                    printf("GetProcAddr %s error: %x\n", __stringVal(aString), GetLastError());
+                }
+            }
+        }
+    }
+  }
+#endif
+
 #ifdef DL1_6
   {
     void *h;
@@ -1449,6 +1525,7 @@
     }
   }
 #endif
+
 %}.
 
     lowAddr notNil ifTrue:[
@@ -1843,6 +1920,29 @@
   }
 #endif
 
+#ifdef WIN_DL
+  {
+    HINSTANCE handle;
+    int err;
+
+    if (__isString(pathName)) {
+        if ((handle = LoadLibrary(__stringVal(pathName))) == NULL) {
+	    err = GetLastError();
+            if (ObjectFileLoader_Verbose == true) {
+                printf ("LoadLibrary %s failed; error: %x\n", 
+				__stringVal(pathName), err);
+            }
+            ObjectFileLoader_LastError = __MKINT(err);
+            RETURN ( nil );
+        }
+	_ArrayInstPtr(anInfoBuffer)->a_element[0] = _MKSMALLINT( (int)handle & 0xFFFF );
+	_ArrayInstPtr(anInfoBuffer)->a_element[1] = _MKSMALLINT( ((int)handle >> 16) & 0xFFFF );
+        RETURN ( anInfoBuffer );
+    }
+    RETURN ( nil );
+  }
+#endif
+
 #ifdef DL1_6
   {
     extern char *__myName__;
@@ -2027,6 +2127,28 @@
     RETURN (false);
 #endif
 
+#ifdef WIN_DL
+    int val;
+    HINSTANCE handle;
+    int err;
+
+    if (__bothSmallInteger(sysHandle1, sysHandle2)) {
+        val = (_intVal(sysHandle2) << 16) + _intVal(sysHandle1);
+        handle = (HINSTANCE)(val);
+
+        if (FreeLibrary(handle) != TRUE) {
+	    err = GetLastError();
+            if (ObjectFileLoader_Verbose == true) {
+                printf ("unlink file %s failed; error: %x\n", 
+			__stringVal(sysHandle1), err);
+            }
+            RETURN (false);
+        }
+        RETURN (true);
+    }
+    RETURN (false);
+#endif
+
 #ifdef SYSV4_DL
   {
     void *h;
@@ -2876,6 +2998,6 @@
 !ObjectFileLoader class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libcomp/ObjectFileLoader.st,v 1.70 1995-12-23 00:22:50 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libcomp/ObjectFileLoader.st,v 1.71 1995-12-26 18:43:21 cg Exp $'
 ! !
 ObjectFileLoader initialize!