#REFACTORING by stefan
authorStefan Vogel <sv@exept.de>
Mon, 23 Jul 2018 11:16:42 +0200
changeset 23228 63b599c0c272
parent 23227 7fa1f7a52a26
child 23229 b4629be3e498
#REFACTORING by stefan class: ExternalLibraryFunction changed: #loadLibrary: class: ExternalLibraryFunction class changed: #removeFromDllPath:
ExternalLibraryFunction.st
--- a/ExternalLibraryFunction.st	Sun Jul 22 15:24:11 2018 +0200
+++ b/ExternalLibraryFunction.st	Mon Jul 23 11:16:42 2018 +0200
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
 "
  COPYRIGHT (c) 2004 by eXept Software AG
 	      All Rights Reserved
@@ -202,7 +204,7 @@
   Synchronous vs. Asynchronous calls:
 
     by default, foreign function calls are synchronous, effectively blocking the whole ST/X system
-    (that is by purpose,´because most C-code is not prepared for being interrupted, and also, normal
+    (that is by purpose,´because most C-code is not prepared for being interrupted, and also, normal
      code is not prepared for a garbage collector to move objects around, while another C thread might
      access the data...).
     Therefore, the following will block all ST/X activity for 10 seconds
@@ -438,16 +440,21 @@
 
     oldPath := self dllPath.
     oldPath notNil ifTrue:[
-        self dllPath:(oldPath asOrderedCollection copyWithout:aDirectoryPathName)
+        self dllPath:(oldPath copyWithout:aDirectoryPathName)
     ].
 
     "
-     self dllPath.
+     |prevDllPath|
+
+     prevDllPath := self dllPath.
+     self removeFromDllPath:'C:\aaa\bbb'.
      self addToDllPath:'C:\aaa\bbb'.
-     self dllPath.
+     self assert:self dllPath size = (prevDllPath size + 1).
      self removeFromDllPath:'C:\aaa\bbb'.
-     self dllPath.
+     self assert:self dllPath size = (prevDllPath size).
     "
+
+    "Modified (comment): / 23-07-2018 / 11:16:26 / Stefan Vogel"
 ! !
 
 !ExternalLibraryFunction class methodsFor:'constants'!
@@ -1051,7 +1058,7 @@
      This is useful, if some code has a hardcoded dll-name in it, which needs to be changed,
      but you do not want or cannot recompile the methods (i.e. no source avail)"
 
-    |handle nameString filename dllPaths|
+    |handle nameString filename dllPaths hasSuffix|
 
     ObjectFileLoader isNil ifTrue:[
         "no libcomp loaded"
@@ -1069,46 +1076,55 @@
     ].
 
     filename := filename asFilename.
-    nameString := filename name.
 
     "try to load, maybe the system knows where to find the dll"
     handle := ObjectFileLoader loadDynamicObject:filename.
-    handle notNil ifTrue:[^ handle ].
-
-    filename isAbsolute ifFalse:[
+    handle notNil ifTrue:[
+        ^ handle
+    ].
+
+    nameString := filename name.
+    hasSuffix := filename suffix notEmpty.
+
+    filename isAbsolute ifTrue:[
+        hasSuffix ifFalse:[
+            "/ try again with the OS-specific dll-extension
+            ObjectFileLoader sharedLibrarySuffixes do:[:eachPossibleSuffix |
+                handle := ObjectFileLoader loadDynamicObject:(filename withSuffix:eachPossibleSuffix).
+                handle notNil ifTrue:[
+                    ^ handle
+                ].
+            ].    
+        ].
+    ] ifFalse:[
         "First ask the class defining the ExternalFunction for the location of the dlls ..."
         dllPaths := #().
         owningClass notNil ifTrue:[
-            dllPaths := owningClass dllPath ? #().
+            dllPaths := owningClass dllPath.
         ].
-        ".. then ask the system"
-        dllPaths := dllPaths, (self class dllPath ? #()).
-        ".. and the settings"
-        dllPaths := dllPaths,(UserPreferences current dllPath ? #()).
+        ".. then ask the system .. and the settings"
+        dllPaths := dllPaths, self class dllPath, UserPreferences current dllPath.
 
         dllPaths do:[:eachDirectory |
             |libraryName|
 
             libraryName := eachDirectory asFilename construct:nameString.
-            libraryName suffix isEmpty ifTrue:[
+            hasSuffix ifTrue:[
+                handle := ObjectFileLoader loadDynamicObject:libraryName.
+                handle notNil ifTrue:[
+                    ^ handle
+                ].
+            ] ifFalse:[        
                 ObjectFileLoader sharedLibrarySuffixes do:[:eachPossibleSuffix |
                     handle := ObjectFileLoader loadDynamicObject:(libraryName withSuffix:eachPossibleSuffix).
-                    handle notNil ifTrue:[^ handle].
+                    handle notNil ifTrue:[
+                        ^ handle
+                    ].
                 ].    
-            ] ifFalse:[        
-                handle := ObjectFileLoader loadDynamicObject:libraryName.
-                handle notNil ifTrue:[^ handle ].
             ].
         ].
     ].
 
-    filename suffix isEmpty ifTrue:[
-        "/ try again with the OS-specific dll-extension
-        ObjectFileLoader sharedLibrarySuffixes do:[:eachPossibleSuffix |
-            handle := self loadLibrary:(filename withSuffix:eachPossibleSuffix).
-            handle notNil ifTrue:[^ handle].
-        ].    
-    ].
 
     "/ check for: the dll-path in:
     "/      - owningClass dllPath
@@ -1123,7 +1139,7 @@
     ^ nil
 
     "Modified: / 13-02-2017 / 01:14:05 / cg"
-    "Modified: / 22-07-2018 / 15:18:33 / Stefan Vogel"
+    "Modified: / 22-07-2018 / 16:34:24 / Stefan Vogel"
 !
 
 prepareInvoke