ExternalLibraryFunction.st
changeset 22141 d5c9d544447f
parent 22140 f80e2cfc6cbf
child 22142 e2452d90f7ab
equal deleted inserted replaced
22140:f80e2cfc6cbf 22141:d5c9d544447f
   934 	argumentTypes := argumentTypes collect:[:argType | self class ffiTypeSymbolForType:argType].
   934 	argumentTypes := argumentTypes collect:[:argType | self class ffiTypeSymbolForType:argType].
   935     ].
   935     ].
   936     returnType := self class ffiTypeSymbolForType:returnType.
   936     returnType := self class ffiTypeSymbolForType:returnType.
   937 !
   937 !
   938 
   938 
       
   939 convertArgument:arg
       
   940     "a chance to convert arguments to one of the primitive (native) types."
       
   941     
       
   942     CDatum notNil ifTrue:[
       
   943         arg isCDatum ifTrue:[
       
   944             arg offset == 0 ifTrue:[
       
   945                 ^ (arg data)
       
   946             ].
       
   947             arg data isExternalBytes ifTrue:[
       
   948                 ^ ExternalAddress newAddress:(arg data address + arg offset).
       
   949             ].    
       
   950         ].
       
   951     ].
       
   952     ^ arg.
       
   953 
       
   954     "Created: / 01-08-2017 / 14:00:45 / cg"
       
   955 !
       
   956 
   939 linkToModule
   957 linkToModule
   940     "link this function to the external module.
   958     "link this function to the external module.
   941      I.e. retrieve the module handle and the code pointer."
   959      I.e. retrieve the module handle and the code pointer."
   942 
   960 
   943     |handle moduleNameUsed functionName|
   961     |handle moduleNameUsed functionName|
  1118     ^ self invokeFFIwithArguments:arguments forCPPInstance:nil
  1136     ^ self invokeFFIwithArguments:arguments forCPPInstance:nil
  1119 
  1137 
  1120     "Modified: / 01-08-2006 / 13:55:35 / cg"
  1138     "Modified: / 01-08-2006 / 13:55:35 / cg"
  1121 !
  1139 !
  1122 
  1140 
  1123 invokeFFIwithArguments:argumentsOrNil forCPPInstance:aReceiverOrNil
  1141 invokeFFIwithArguments:argumentsOrNilIn forCPPInstance:aReceiverOrNil
  1124     "basic invoke mechanism. Calls the function represented by the receiver with argumentsOrNil.
  1142     "basic invoke mechanism. Calls the function represented by the receiver with argumentsOrNil.
  1125      For cplusplus, aReceiverOrNil is required to be an externalStructure like object;
  1143      For cplusplus, aReceiverOrNil is required to be an externalStructure like object;
  1126      for objectiveC, it must be an ObjectiveC object"
  1144      for objectiveC, it must be an ObjectiveC object"
  1127 
  1145 
  1128     |argTypeSymbols returnTypeSymbol failureCode failureArgNr failureInfo returnValue stClass vtOffset
  1146     |argTypeSymbols returnTypeSymbol failureCode failureArgNr failureInfo returnValue stClass vtOffset
  1129      virtual objectiveC async unlimitedStack callTypeNumber returnValueClass argValueClass
  1147      virtual objectiveC async unlimitedStack callTypeNumber returnValueClass argValueClass
  1130      oldReturnType oldArgumentTypes mustFreeRetVal alreadyFreed|
  1148      oldReturnType oldArgumentTypes mustFreeRetVal alreadyFreed argumentsOrNil|
  1131 
  1149 
       
  1150     argumentsOrNil := argumentsOrNilIn. 
  1132     argTypeSymbols := argumentTypes.
  1151     argTypeSymbols := argumentTypes.
  1133     returnTypeSymbol := returnType.
  1152     returnTypeSymbol := returnType.
  1134 
  1153 
  1135     virtual := self isVirtualCPP.
  1154     virtual := self isVirtualCPP.
  1136     objectiveC := self isObjectiveC.
  1155     objectiveC := self isObjectiveC.
  1170     unlimitedStack := self isUnlimitedStack.
  1189     unlimitedStack := self isUnlimitedStack.
  1171     callTypeNumber := self callTypeNumber.
  1190     callTypeNumber := self callTypeNumber.
  1172     mustFreeRetVal := self mustFreeReturnValue.
  1191     mustFreeRetVal := self mustFreeReturnValue.
  1173     alreadyFreed := false.
  1192     alreadyFreed := false.
  1174 
  1193 
       
  1194     argumentsOrNil size > 0 ifTrue:[
       
  1195         argumentsOrNil := argumentsOrNil collect:[:arg | self convertArgument:arg]
       
  1196     ].
       
  1197     
  1175     "/ Transcript show:name; show:' async:'; showCR:async.
  1198     "/ Transcript show:name; show:' async:'; showCR:async.
  1176 
  1199 
  1177 %{  /* STACK: 100000 */
  1200 %{  /* STACK: 100000 */
  1178 
  1201 
  1179 #define VERBOSE
  1202 #define VERBOSE
  2717 
  2740 
  2718     ^ returnValue
  2741     ^ returnValue
  2719 
  2742 
  2720     "Created: / 01-08-2006 / 13:56:23 / cg"
  2743     "Created: / 01-08-2006 / 13:56:23 / cg"
  2721     "Modified: / 15-05-2017 / 19:48:52 / mawalch"
  2744     "Modified: / 15-05-2017 / 19:48:52 / mawalch"
  2722     "Modified: / 01-08-2017 / 13:54:46 / cg"
  2745     "Modified: / 01-08-2017 / 14:03:52 / cg"
  2723 !
  2746 !
  2724 
  2747 
  2725 tryAgainWithAsyncSafeArguments:argumentsOrNil forCPPInstance:aReceiverOrNil
  2748 tryAgainWithAsyncSafeArguments:argumentsOrNil forCPPInstance:aReceiverOrNil
  2726     "invoked by the call primitive, iff GC-unsave arguments where passed to the call.
  2749     "invoked by the call primitive, iff GC-unsave arguments where passed to the call.
  2727      Here, allocate non-movable blocks of memory and copy the arguments into them,
  2750      Here, allocate non-movable blocks of memory and copy the arguments into them,