gcc fixes
authorClaus Gittinger <cg@exept.de>
Sun, 08 Dec 2019 22:03:13 +0100
changeset 25087 6be980cf75e3
parent 25086 64b5d6493613
child 25088 3a9b967a1065
gcc fixes
ExternalFunctionCallback.st
ExternalLibraryFunction.st
OSXOperatingSystem.st
--- a/ExternalFunctionCallback.st	Sun Dec 08 21:03:52 2019 +0100
+++ b/ExternalFunctionCallback.st	Sun Dec 08 22:03:13 2019 +0100
@@ -36,7 +36,11 @@
 # endif
 
 #ifdef HAVE_FFI
-# include <ffi.h>
+# ifdef __osx__
+#  include <ffi/ffi.h>
+# else
+#  include <ffi.h>
+# endif
 # define MAX_ARGS    128
 
 # ifdef USE_STANDARD_FFI
@@ -407,7 +411,7 @@
 
 callbackFor:aBlock returnType:returnType argumentTypes:argumentTypes
     "generate a callback for the ErrorCallbackProc signature:
-        ErrorCallbackProc(HWND hWnd, int nErrID, LPTSTR lpErrorText)
+	ErrorCallbackProc(HWND hWnd, int nErrID, LPTSTR lpErrorText)
      which, can be given to an external API call and which invokes the
      three arg block when clled.
      Do not forget to eventually release the callback to avoid a memory leak."
@@ -1007,4 +1011,3 @@
 version_CVS
     ^ '$Header$'
 ! !
-
--- a/ExternalLibraryFunction.st	Sun Dec 08 21:03:52 2019 +0100
+++ b/ExternalLibraryFunction.st	Sun Dec 08 22:03:13 2019 +0100
@@ -38,7 +38,11 @@
 
 #ifdef HAVE_FFI
 
-# include <ffi.h>
+# ifdef __osx__
+#  include <ffi/ffi.h>
+# else
+#  include <ffi.h>
+# endif
 # define MAX_ARGS    128
 
 # ifdef USE_STANDARD_FFI
@@ -1195,58 +1199,58 @@
     "link this function to the external module.
      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" 
+     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:[
-                moduleNameUsed := owningClass theMetaclass 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"
@@ -1266,18 +1270,18 @@
     |handle nameString filename dllPaths hasSuffix|
 
     ObjectFileLoader isNil ifTrue:[
-        "no libcomp loaded"
-        ^ self primitiveFailed:'libcomp:ObjectFileLoader is not available'.
+	"no libcomp loaded"
+	^ self primitiveFailed:'libcomp:ObjectFileLoader is not available'.
     ].
 
     (ObjectFileLoader canLoadObjectFiles) ifFalse:[
-        ObjectFileLoader::ObjectFileLoadError raiseErrorString:('ObjectFileLoader cannot load dll/module: "%1"' bindWith:dllName).
-        ^ nil.
+	ObjectFileLoader::ObjectFileLoadError raiseErrorString:('ObjectFileLoader cannot load dll/module: "%1"' bindWith:dllName).
+	^ nil.
     ].
 
     filename := dllName.
     DllMapping notNil ifTrue:[
-        filename := DllMapping at:dllName ifAbsent:[ filename ]
+	filename := DllMapping at:dllName ifAbsent:[ filename ]
     ].
 
     filename := filename asFilename.
@@ -1285,49 +1289,49 @@
     "try to load, maybe the system knows where to find the dll"
     handle := ObjectFileLoader loadDynamicObject:filename.
     handle notNil ifTrue:[
-        ^ handle
+	^ 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
-                ].
-            ].
-        ].
+	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.
-        ].
-        ".. then ask the system .. and the settings"
-        dllPaths := dllPaths, self class dllPath, UserPreferences current dllPath.
-
-        dllPaths do:[:eachDirectory |
-            |libraryName|
-
-            libraryName := eachDirectory asFilename construct:nameString.
-            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
-                    ].
-                ].
-            ].
-        ].
+	"First ask the class defining the ExternalFunction for the location of the dlls ..."
+	dllPaths := #().
+	owningClass notNil ifTrue:[
+	    dllPaths := owningClass 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.
+	    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
+		    ].
+		].
+	    ].
+	].
     ].
 
 
@@ -1340,7 +1344,7 @@
     "/ eg: self class dllMapping at:'libtesseract' put:('/opt/local/lib/libtesseract.dylib').
     "/ see also the settings dialog for external libraries.
     ObjectFileLoader::ObjectFileLoadError
-        raiseErrorString:('Cannot find or load dll/module: "%1" (check dllPath settings)' bindWith:nameString).
+	raiseErrorString:('Cannot find or load dll/module: "%1" (check dllPath settings)' bindWith:nameString).
     ^ nil
 
     "Modified: / 13-02-2017 / 01:14:05 / cg"
--- a/OSXOperatingSystem.st	Sun Dec 08 21:03:52 2019 +0100
+++ b/OSXOperatingSystem.st	Sun Dec 08 22:03:13 2019 +0100
@@ -41,6 +41,11 @@
 # define NO_COREGRAPHICS
 #endif
 
+#ifdef __GNUC__
+# define NO_COCOA
+# define NO_COREGRAPHICS
+#endif
+
 // #include <mach/clock.h>
 // #include <mach/mach.h>
 // #include <sys/time.h>