#BUGFIX by cg
authorClaus Gittinger <cg@exept.de>
Tue, 01 Aug 2017 14:06:29 +0200
changeset 22141 d5c9d544447f
parent 22140 f80e2cfc6cbf
child 22142 e2452d90f7ab
#BUGFIX by cg class: ExternalLibraryFunction care for CDatum arguments. added: #convertArgument: changed: #invokeFFIwithArguments:forCPPInstance:
ExternalLibraryFunction.st
--- a/ExternalLibraryFunction.st	Tue Aug 01 13:55:36 2017 +0200
+++ b/ExternalLibraryFunction.st	Tue Aug 01 14:06:29 2017 +0200
@@ -936,6 +936,24 @@
     returnType := self class ffiTypeSymbolForType:returnType.
 !
 
+convertArgument:arg
+    "a chance to convert arguments to one of the primitive (native) types."
+    
+    CDatum notNil ifTrue:[
+        arg isCDatum ifTrue:[
+            arg offset == 0 ifTrue:[
+                ^ (arg data)
+            ].
+            arg data isExternalBytes ifTrue:[
+                ^ ExternalAddress newAddress:(arg data address + arg offset).
+            ].    
+        ].
+    ].
+    ^ arg.
+
+    "Created: / 01-08-2017 / 14:00:45 / cg"
+!
+
 linkToModule
     "link this function to the external module.
      I.e. retrieve the module handle and the code pointer."
@@ -1120,15 +1138,16 @@
     "Modified: / 01-08-2006 / 13:55:35 / cg"
 !
 
-invokeFFIwithArguments:argumentsOrNil forCPPInstance:aReceiverOrNil
+invokeFFIwithArguments:argumentsOrNilIn forCPPInstance:aReceiverOrNil
     "basic invoke mechanism. Calls the function represented by the receiver with argumentsOrNil.
      For cplusplus, aReceiverOrNil is required to be an externalStructure like object;
      for objectiveC, it must be an ObjectiveC object"
 
     |argTypeSymbols returnTypeSymbol failureCode failureArgNr failureInfo returnValue stClass vtOffset
      virtual objectiveC async unlimitedStack callTypeNumber returnValueClass argValueClass
-     oldReturnType oldArgumentTypes mustFreeRetVal alreadyFreed|
+     oldReturnType oldArgumentTypes mustFreeRetVal alreadyFreed argumentsOrNil|
 
+    argumentsOrNil := argumentsOrNilIn. 
     argTypeSymbols := argumentTypes.
     returnTypeSymbol := returnType.
 
@@ -1172,6 +1191,10 @@
     mustFreeRetVal := self mustFreeReturnValue.
     alreadyFreed := false.
 
+    argumentsOrNil size > 0 ifTrue:[
+        argumentsOrNil := argumentsOrNil collect:[:arg | self convertArgument:arg]
+    ].
+    
     "/ Transcript show:name; show:' async:'; showCR:async.
 
 %{  /* STACK: 100000 */
@@ -2719,7 +2742,7 @@
 
     "Created: / 01-08-2006 / 13:56:23 / cg"
     "Modified: / 15-05-2017 / 19:48:52 / mawalch"
-    "Modified: / 01-08-2017 / 13:54:46 / cg"
+    "Modified: / 01-08-2017 / 14:03:52 / cg"
 !
 
 tryAgainWithAsyncSafeArguments:argumentsOrNil forCPPInstance:aReceiverOrNil