ExternalLibraryFunction.st
changeset 24825 363db976dea9
parent 24451 0aa7d8be211f
child 24826 d73b54f3c744
equal deleted inserted replaced
24824:46b44bdbc5d2 24825:363db976dea9
  1264      but you do not want or cannot recompile the methods (i.e. no source avail)"
  1264      but you do not want or cannot recompile the methods (i.e. no source avail)"
  1265 
  1265 
  1266     |handle nameString filename dllPaths hasSuffix|
  1266     |handle nameString filename dllPaths hasSuffix|
  1267 
  1267 
  1268     ObjectFileLoader isNil ifTrue:[
  1268     ObjectFileLoader isNil ifTrue:[
  1269 	"no libcomp loaded"
  1269         "no libcomp loaded"
  1270 	^ self primitiveFailed:'libcomp:ObjectFileLoader is not available'.
  1270         ^ self primitiveFailed:'libcomp:ObjectFileLoader is not available'.
  1271     ].
  1271     ].
  1272 
  1272 
  1273     (ObjectFileLoader notNil and:[ObjectFileLoader canLoadObjectFiles]) ifFalse:[
  1273     (ObjectFileLoader notNil and:[ObjectFileLoader canLoadObjectFiles]) ifFalse:[
  1274 	ObjectFileLoader::ObjectFileLoadError raiseErrorString:('ObjectFileLoader cannot load dll/module: "%1"' bindWith:nameString)e.
  1274         ObjectFileLoader::ObjectFileLoadError raiseErrorString:('ObjectFileLoader cannot load dll/module: "%1"' bindWith:nameString).
  1275 	^ nil.
  1275         ^ nil.
  1276     ].
  1276     ].
  1277 
  1277 
  1278     filename := dllName.
  1278     filename := dllName.
  1279     DllMapping notNil ifTrue:[
  1279     DllMapping notNil ifTrue:[
  1280 	filename := DllMapping at:filename ifAbsent:[ filename ]
  1280         filename := DllMapping at:dllName ifAbsent:[ filename ]
  1281     ].
  1281     ].
  1282 
  1282 
  1283     filename := filename asFilename.
  1283     filename := filename asFilename.
  1284 
  1284 
  1285     "try to load, maybe the system knows where to find the dll"
  1285     "try to load, maybe the system knows where to find the dll"
  1286     handle := ObjectFileLoader loadDynamicObject:filename.
  1286     handle := ObjectFileLoader loadDynamicObject:filename.
  1287     handle notNil ifTrue:[
  1287     handle notNil ifTrue:[
  1288 	^ handle
  1288         ^ handle
  1289     ].
  1289     ].
  1290 
  1290 
  1291     nameString := filename name.
  1291     nameString := filename name.
  1292     hasSuffix := filename suffix notEmpty.
  1292     hasSuffix := filename suffix notEmpty.
  1293 
  1293 
  1294     filename isAbsolute ifTrue:[
  1294     filename isAbsolute ifTrue:[
  1295 	hasSuffix ifFalse:[
  1295         hasSuffix ifFalse:[
  1296 	    "/ try again with the OS-specific dll-extension
  1296             "/ try again with the OS-specific dll-extension
  1297 	    ObjectFileLoader sharedLibrarySuffixes do:[:eachPossibleSuffix |
  1297             ObjectFileLoader sharedLibrarySuffixes do:[:eachPossibleSuffix |
  1298 		handle := ObjectFileLoader loadDynamicObject:(filename withSuffix:eachPossibleSuffix).
  1298                 handle := ObjectFileLoader loadDynamicObject:(filename withSuffix:eachPossibleSuffix).
  1299 		handle notNil ifTrue:[
  1299                 handle notNil ifTrue:[
  1300 		    ^ handle
  1300                     ^ handle
  1301 		].
  1301                 ].
  1302 	    ].
  1302             ].
  1303 	].
  1303         ].
  1304     ] ifFalse:[
  1304     ] ifFalse:[
  1305 	"First ask the class defining the ExternalFunction for the location of the dlls ..."
  1305         "First ask the class defining the ExternalFunction for the location of the dlls ..."
  1306 	dllPaths := #().
  1306         dllPaths := #().
  1307 	owningClass notNil ifTrue:[
  1307         owningClass notNil ifTrue:[
  1308 	    dllPaths := owningClass dllPath.
  1308             dllPaths := owningClass dllPath.
  1309 	].
  1309         ].
  1310 	".. then ask the system .. and the settings"
  1310         ".. then ask the system .. and the settings"
  1311 	dllPaths := dllPaths, self class dllPath, UserPreferences current dllPath.
  1311         dllPaths := dllPaths, self class dllPath, UserPreferences current dllPath.
  1312 
  1312 
  1313 	dllPaths do:[:eachDirectory |
  1313         dllPaths do:[:eachDirectory |
  1314 	    |libraryName|
  1314             |libraryName|
  1315 
  1315 
  1316 	    libraryName := eachDirectory asFilename construct:nameString.
  1316             libraryName := eachDirectory asFilename construct:nameString.
  1317 	    hasSuffix ifTrue:[
  1317             hasSuffix ifTrue:[
  1318 		handle := ObjectFileLoader loadDynamicObject:libraryName.
  1318                 handle := ObjectFileLoader loadDynamicObject:libraryName.
  1319 		handle notNil ifTrue:[
  1319                 handle notNil ifTrue:[
  1320 		    ^ handle
  1320                     ^ handle
  1321 		].
  1321                 ].
  1322 	    ] ifFalse:[
  1322             ] ifFalse:[
  1323 		ObjectFileLoader sharedLibrarySuffixes do:[:eachPossibleSuffix |
  1323                 ObjectFileLoader sharedLibrarySuffixes do:[:eachPossibleSuffix |
  1324 		    handle := ObjectFileLoader loadDynamicObject:(libraryName withSuffix:eachPossibleSuffix).
  1324                     handle := ObjectFileLoader loadDynamicObject:(libraryName withSuffix:eachPossibleSuffix).
  1325 		    handle notNil ifTrue:[
  1325                     handle notNil ifTrue:[
  1326 			^ handle
  1326                         ^ handle
  1327 		    ].
  1327                     ].
  1328 		].
  1328                 ].
  1329 	    ].
  1329             ].
  1330 	].
  1330         ].
  1331     ].
  1331     ].
  1332 
  1332 
  1333 
  1333 
  1334     "/ check for: the dll-path in:
  1334     "/ check for: the dll-path in:
  1335     "/      - owningClass dllPath
  1335     "/      - owningClass dllPath
  1338     "/      - DllMapping (the classVar, but accessed via self class dllMapping)
  1338     "/      - DllMapping (the classVar, but accessed via self class dllMapping)
  1339     "/        this can map both basenames and whole pathnames
  1339     "/        this can map both basenames and whole pathnames
  1340     "/ eg: self class dllMapping at:'libtesseract' put:('/opt/local/lib/libtesseract.dylib').
  1340     "/ eg: self class dllMapping at:'libtesseract' put:('/opt/local/lib/libtesseract.dylib').
  1341     "/ see also the settings dialog for external libraries.
  1341     "/ see also the settings dialog for external libraries.
  1342     ObjectFileLoader::ObjectFileLoadError
  1342     ObjectFileLoader::ObjectFileLoadError
  1343 	raiseErrorString:('Cannot find or load dll/module: "%1" (check dllPath settings)' bindWith:nameString).
  1343         raiseErrorString:('Cannot find or load dll/module: "%1" (check dllPath settings)' bindWith:nameString).
  1344     ^ nil
  1344     ^ nil
  1345 
  1345 
  1346     "Modified: / 13-02-2017 / 01:14:05 / cg"
  1346     "Modified: / 13-02-2017 / 01:14:05 / cg"
  1347     "Modified: / 22-07-2018 / 16:34:24 / Stefan Vogel"
  1347     "Modified: / 22-07-2018 / 16:34:24 / Stefan Vogel"
  1348 !
  1348 !