ExternalLibraryFunction.st
changeset 24451 0aa7d8be211f
parent 24338 9516492f8920
child 24825 363db976dea9
--- a/ExternalLibraryFunction.st	Mon Jul 22 01:16:09 2019 +0200
+++ b/ExternalLibraryFunction.st	Mon Jul 22 07:25:53 2019 +0200
@@ -1,5 +1,3 @@
-"{ Encoding: utf8 }"
-
 "
  COPYRIGHT (c) 2004 by eXept Software AG
 	      All Rights Reserved
@@ -205,7 +203,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
@@ -1195,61 +1193,67 @@
 
 linkToModule
     "link this function to the external module.
-     I.e. retrieve the module handle and the code pointer."
+     I.e. retrieve the module handle and the code pointer.
+     The name of the DLL is retrieved either from the primitive declaration or
+     the owning instance or its class" 
 
     |handle moduleNameUsed functionName|
 
     name isNumber ifTrue:[
-	self isCPPFunction ifTrue:[
-	    "/ no need to load a dll.
-	    ^ self
-	]
+        self isCPPFunction ifTrue:[
+            "/ no need to load a dll.
+            ^ self
+        ]
     ].
     self isObjectiveC ifTrue:[
-	"/ no need for a library - we will get the receiver
-	^ self.
+        "/ no need for a library - we will get the receiver
+        ^ self.
     ].
 
     "/ in some other smalltalks, there is no moduleName in the ffi-spec;
     "/ instead, the class provides the libraryName...
     (moduleNameUsed := moduleName) isNil ifTrue:[
-	owningClass notNil ifTrue:[
-	    moduleNameUsed := owningClass theNonMetaclass perform:#libraryName ifNotUnderstood:nil.
-	].
-	moduleNameUsed isNil ifTrue:[
-	    self error:'Missing shared library name'.
-	].
-	moduleNameUsed := moduleNameUsed asSymbol.
+        owningClass notNil ifTrue:[
+            moduleNameUsed := owningClass theNonMetaclass perform:#libraryName ifNotUnderstood:nil.
+            moduleNameUsed isNil ifTrue:[
+                moduleNameUsed := owningClass theMetaclass perform:#libraryName ifNotUnderstood:nil.
+            ].
+        ].
+        moduleNameUsed isNil ifTrue:[
+            self error:'Missing shared library name'.
+        ].
+        moduleNameUsed := moduleNameUsed asSymbol.
     ].
     moduleHandle isNil ifTrue:[
-	"/ speedup. in 95% of all calls, the same moduleName is resolved here
-	(LastModuleHandleHolder isNil
-	or:[ (handle := LastModuleHandleHolder at:1) isNil
-	or:[ handle == -1
-	or:[ LastModuleHandleName ~= moduleNameUsed ]]]) ifTrue:[
-
-	    handle := self loadLibrary:moduleNameUsed.
-	    LastModuleHandleHolder := WeakArray with:handle.
-	    LastModuleHandleName := moduleNameUsed.
-	].
-	self assert:(handle isInteger not).
-	moduleHandle := handle.
+        "/ speedup. in 95% of all calls, the same moduleName is resolved here
+        (LastModuleHandleHolder isNil
+        or:[ (handle := LastModuleHandleHolder at:1) isNil
+        or:[ handle == -1
+        or:[ LastModuleHandleName ~= moduleNameUsed ]]]) ifTrue:[
+
+            handle := self loadLibrary:moduleNameUsed.
+            LastModuleHandleHolder := WeakArray with:handle.
+            LastModuleHandleName := moduleNameUsed.
+        ].
+        self assert:(handle isInteger not).
+        moduleHandle := handle.
     ].
     name isNumber ifFalse:[
-	functionName := name.
-	(moduleHandle getFunctionAddress:functionName into:self) isNil ifTrue:[
-	    (moduleHandle getFunctionAddress:('_', functionName) into:self) isNil ifTrue:[
-		moduleHandle := nil.
-		LastModuleHandleHolder := LastModuleHandleName := nil.
-		ObjectFileLoader::ObjectFileLoadError raiseRequestErrorString:'Missing function: "', name, '" in shared library: "', moduleNameUsed, '"'.
-	    ].
-	].
+        functionName := name.
+        (moduleHandle getFunctionAddress:functionName into:self) isNil ifTrue:[
+            (moduleHandle getFunctionAddress:('_', functionName) into:self) isNil ifTrue:[
+                moduleHandle := nil.
+                LastModuleHandleHolder := LastModuleHandleName := nil.
+                ObjectFileLoader::ObjectFileLoadError raiseRequestErrorString:'Missing function: "', name, '" in shared library: "', moduleNameUsed, '"'.
+            ].
+        ].
     ].
 
     "Modified: / 04-08-2017 / 20:10:41 / cg"
     "Modified: / 11-05-2018 / 12:18:14 / stefan"
     "Modified: / 22-07-2018 / 15:16:19 / Stefan Vogel"
-    "Modified: / 04-03-2019 / 11:42:56 / Claus Gittinger"
+    "Modified: / 22-07-2019 / 01:24:00 / Claus Gittinger"
+    "Modified (comment): / 22-07-2019 / 07:23:36 / Claus Gittinger"
 !
 
 loadLibrary:dllName