*** empty log message ***
authorClaus Gittinger <cg@exept.de>
Fri, 26 Aug 2016 01:12:20 +0200
changeset 20307 678da26adf03
parent 20306 07ff17265c6b
child 20308 9110f117d260
*** empty log message ***
ExternalFunctionCallback.st
ExternalLibraryFunction.st
SimpleExternalLibraryFunction.st
--- a/ExternalFunctionCallback.st	Fri Aug 26 01:04:45 2016 +0200
+++ b/ExternalFunctionCallback.st	Fri Aug 26 01:12:20 2016 +0200
@@ -230,7 +230,7 @@
 }
 
 void
-ExternalFunctionCallback__test_call_closure(INTFUNC f)
+ExternalFunctionCallback__test_call_closure(INTLFUNC f)
 {
     INT result = 0;
 
@@ -403,7 +403,7 @@
     "a simple test, if I can be called"
 %{
 #   define MAX_CALLBACK_ARGS 5
-    INTFUNC f = __externalAddressVal(aCallback);
+    INTLFUNC f = __externalAddressVal(aCallback);
     INT result;
     int i;
     void *c_args[MAX_CALLBACK_ARGS];
@@ -809,7 +809,7 @@
     __INST(code_) = (OBJ)pcl;
 
 #if 0
-    ExternalFunctionCallback__test_call_closure((INTFUNC)pcl);
+    ExternalFunctionCallback__test_call_closure((INTLFUNC)pcl);
 #endif
 
 #else /* no FFI support */
--- a/ExternalLibraryFunction.st	Fri Aug 26 01:04:45 2016 +0200
+++ b/ExternalLibraryFunction.st	Fri Aug 26 01:12:20 2016 +0200
@@ -73,11 +73,11 @@
    extern ffi_type *__get_ffi_type_double();
    extern ffi_type *__get_ffi_type_void();
    extern ffi_type *__get_ffi_type_pointer();
-   extern INTFUNC __get_ffi_prep_cif();
-   extern INTFUNC __get_ffi_call();
+   extern INTLFUNC __get_ffi_prep_cif();
+   extern INTLFUNC __get_ffi_call();
 #  ifdef _MINGW__
 #   define ffi_prep_cif (*(__get_ffi_prep_cif()))
-#   define ffi_call (*(__get_ffi_call()))
+#   define ffi_call     (*(__get_ffi_call()))
 #  endif
 # endif
 
@@ -298,15 +298,15 @@
 dllMappingAt:baseLibname put:aNameOrPath
     "allows for dll's to be replaced,
      for example, if you want to use the mozilla sqlite dll
-        C:\Program Files\Mozilla Firefox\mozsqlite3.dll
+	C:\Program Files\Mozilla Firefox\mozsqlite3.dll
      for the sqlite3, execute:
-        ExternalLibraryFunction
-            dllMappingAt:'sqlite3'
-            put: 'C:\Program Files\Mozilla Firefox\mozsqlite3.dll'
+	ExternalLibraryFunction
+	    dllMappingAt:'sqlite3'
+	    put: 'C:\Program Files\Mozilla Firefox\mozsqlite3.dll'
      for mingw:
-        ExternalLibraryFunction
-            dllMappingAt:'sqlite3'
-            put:'C:\mingw64\opt\bin\libsqlite3-0.dll'
+	ExternalLibraryFunction
+	    dllMappingAt:'sqlite3'
+	    put:'C:\mingw64\opt\bin\libsqlite3-0.dll'
     "
 
     self dllMapping at:baseLibname put: aNameOrPath
@@ -1130,7 +1130,7 @@
     int __numArgs, __numArgsIncludingThis;
     static INT null = 0;
     int i = -1;
-    VOIDFUNC codeAddress = (VOIDFUNC)__INST(code_);
+    voidFUNC codeAddress = (voidFUNC)__INST(code_);
     int __numArgsWanted;
 
 #   define __FAIL__(fcode) \
--- a/SimpleExternalLibraryFunction.st	Fri Aug 26 01:04:45 2016 +0200
+++ b/SimpleExternalLibraryFunction.st	Fri Aug 26 01:12:20 2016 +0200
@@ -37,33 +37,33 @@
     virtual := self isVirtualCPP.
     objectiveC := self isObjectiveC.
     (virtual "or:[self isNonVirtualCPP]") ifTrue:[
-        aReceiverOrNil isNil ifTrue:[
-            "/ must have a c++ object instance
-            self primitiveFailed.
-        ].
+	aReceiverOrNil isNil ifTrue:[
+	    "/ must have a c++ object instance
+	    self primitiveFailed.
+	].
 
-        "/ and it must be a kind of ExternalStructure !!
-        (aReceiverOrNil isExternalStructure) ifFalse:[
-            self primitiveFailed.
-        ].
-        virtual ifTrue:[
-            vtOffset := name.
-        ].
+	"/ and it must be a kind of ExternalStructure !!
+	(aReceiverOrNil isExternalStructure) ifFalse:[
+	    self primitiveFailed.
+	].
+	virtual ifTrue:[
+	    vtOffset := name.
+	].
     ] ifFalse:[
-        objectiveC ifTrue:[
-            aReceiverOrNil isNil ifTrue:[
-                "/ must have an objective-c object instance
-                self primitiveFailed.
-            ].
-            (aReceiverOrNil isObjectiveCObject) ifFalse:[
-                self primitiveFailed
-            ]
-        ] ifFalse:[
-            aReceiverOrNil notNil ifTrue:[
-                "/ must NOT have a c++/objectiveC object instance
-                self primitiveFailed.
-            ]
-        ].
+	objectiveC ifTrue:[
+	    aReceiverOrNil isNil ifTrue:[
+		"/ must have an objective-c object instance
+		self primitiveFailed.
+	    ].
+	    (aReceiverOrNil isObjectiveCObject) ifFalse:[
+		self primitiveFailed
+	    ]
+	] ifFalse:[
+	    aReceiverOrNil notNil ifTrue:[
+		"/ must NOT have a c++/objectiveC object instance
+		self primitiveFailed.
+	    ]
+	].
     ].
 
 %{  /* STACK: 100000 */
@@ -77,65 +77,65 @@
     INT retVal;
     int i = -1;
     int argIdx = 0;
-    INTFUNC codeAddress = (VOIDFUNC)__INST(code_);
+    INTLFUNC codeAddress = (voidFUNC)__INST(code_);
     int __numArgsWanted;
 
 #   define __FAIL__(fcode) \
     { \
-        failureCode = fcode; failureArgNr = __mkSmallInteger(i+1); goto getOutOfHere; \
+	failureCode = fcode; failureArgNr = __mkSmallInteger(i+1); goto getOutOfHere; \
     }
 
     if (argumentsOrNil == nil) {
-        __numArgs = 0;
+	__numArgs = 0;
     } else if (__isArray(argumentsOrNil)) {
-        __numArgs = __arraySize(argumentsOrNil);
+	__numArgs = __arraySize(argumentsOrNil);
     } else {
-        __FAIL__(@symbol(BadArgumentVector))
+	__FAIL__(@symbol(BadArgumentVector))
     }
     if (__numArgs != __numArgsWanted) {
-        __FAIL__(@symbol(ArgumentCountMismatch))
+	__FAIL__(@symbol(ArgumentCountMismatch))
     }
     if (__numArgs > MAX_ARGS) {
-        __FAIL__(@symbol(TooManyArguments))
+	__FAIL__(@symbol(TooManyArguments))
     }
 
     /*
      * validate the c++ object
      */
     if (aReceiverOrNil != nil) {
-        struct cPlusPlusInstance {
-            void **vTable;
-        };
-        struct cPlusPlusInstance *inst;
+	struct cPlusPlusInstance {
+	    void **vTable;
+	};
+	struct cPlusPlusInstance *inst;
 
-        if (__isExternalAddressLike(aReceiverOrNil)) {
-            inst = (void *)(__externalAddressVal(aReceiverOrNil));
-        } else if (__isExternalBytesLike(aReceiverOrNil)) {
-            inst = (void *)(__externalBytesVal(aReceiverOrNil));
-        } else {
-            __FAIL__(@symbol(InvalidInstance))
-        }
-        __args[0] = (INT)inst;
-        __numArgsIncludingThis = __numArgs + 1;
-        argIdx = 1;
+	if (__isExternalAddressLike(aReceiverOrNil)) {
+	    inst = (void *)(__externalAddressVal(aReceiverOrNil));
+	} else if (__isExternalBytesLike(aReceiverOrNil)) {
+	    inst = (void *)(__externalBytesVal(aReceiverOrNil));
+	} else {
+	    __FAIL__(@symbol(InvalidInstance))
+	}
+	__args[0] = (INT)inst;
+	__numArgsIncludingThis = __numArgs + 1;
+	argIdx = 1;
 
-        if (virtual == true) {
-            if (! __isSmallInteger(vtOffset)) {
-                __FAIL__(@symbol(InvalidVTableIndex))
-            }
-            codeAddress = inst->vTable[__intVal(vtOffset)];
+	if (virtual == true) {
+	    if (! __isSmallInteger(vtOffset)) {
+		__FAIL__(@symbol(InvalidVTableIndex))
+	    }
+	    codeAddress = inst->vTable[__intVal(vtOffset)];
 # ifdef VERBOSE
-            if (@global(Verbose) == true) {
-                printf("virtual %d codeAddress: %"_lx_"\n", __intVal(vtOffset), (INT)codeAddress);
-            }
+	    if (@global(Verbose) == true) {
+		printf("virtual %d codeAddress: %"_lx_"\n", __intVal(vtOffset), (INT)codeAddress);
+	    }
 # endif
-        }
+	}
     } else {
-        __numArgsIncludingThis = __numArgs;
+	__numArgsIncludingThis = __numArgs;
 # ifdef VERBOSE
-        if (@global(Verbose) == true) {
-            printf("codeAddress: %"_lx_"\n", (INT)codeAddress);
-        }
+	if (@global(Verbose) == true) {
+	    printf("codeAddress: %"_lx_"\n", (INT)codeAddress);
+	}
 # endif
     }
 
@@ -143,55 +143,55 @@
      * validate all arg types, map each to an ffi_type, and setup arg-buffers
      */
     for (i=0; i<__numArgs; i++, argIdx++) {
-        OBJ arg;
+	OBJ arg;
 
-        failureInfo = __mkSmallInteger(i+1);   /* in case there is one */
+	failureInfo = __mkSmallInteger(i+1);   /* in case there is one */
 
-        arg = __ArrayInstPtr(argumentsOrNil)->a_element[i];
+	arg = __ArrayInstPtr(argumentsOrNil)->a_element[i];
 
-        if (__isSmallInteger(arg)) {
-            __args[argIdx] = __intVal(arg);
-        } else {
-           INT iv = __signedLongIntVal(arg);
-           if (iv != 0) {
-                __args[argIdx]  = iv;
-            } else {
-                unsigned INT iv = __unsignedLongIntVal(arg);
-                if (iv != 0) {
-                    __args[argIdx] = iv;
-                } else {
-                    if (__isStringLike(arg)) {
-                        __args[argIdx] = (INT)(__stringVal(arg));
-                    } else {
-                        if (__isBytes(arg)) {
-                            __args[argIdx] = (INT)(__byteArrayVal(arg));
-                            if (arg == NULL) {
-                                __args[argIdx] = (INT)0;
-                            } else {
-                                if (__isExternalAddressLike(arg)) {
-                                    __args[argIdx] = (INT)(__externalAddressVal(arg));
-                                } else {
-                                    if (__isExternalBytesLike(arg)) {
-                                        __args[argIdx] = (INT)(__externalBytesVal(arg));
-                                    } else {
-                                        __FAIL__(@symbol(InvalidArgument))
-                                    }
-                                }
-                            }
-                        }
-                    }
-                }
-            }
-        }
+	if (__isSmallInteger(arg)) {
+	    __args[argIdx] = __intVal(arg);
+	} else {
+	   INT iv = __signedLongIntVal(arg);
+	   if (iv != 0) {
+		__args[argIdx]  = iv;
+	    } else {
+		unsigned INT iv = __unsignedLongIntVal(arg);
+		if (iv != 0) {
+		    __args[argIdx] = iv;
+		} else {
+		    if (__isStringLike(arg)) {
+			__args[argIdx] = (INT)(__stringVal(arg));
+		    } else {
+			if (__isBytes(arg)) {
+			    __args[argIdx] = (INT)(__byteArrayVal(arg));
+			    if (arg == NULL) {
+				__args[argIdx] = (INT)0;
+			    } else {
+				if (__isExternalAddressLike(arg)) {
+				    __args[argIdx] = (INT)(__externalAddressVal(arg));
+				} else {
+				    if (__isExternalBytesLike(arg)) {
+					__args[argIdx] = (INT)(__externalBytesVal(arg));
+				    } else {
+					__FAIL__(@symbol(InvalidArgument))
+				    }
+				}
+			    }
+			}
+		    }
+		}
+	    }
+	}
     }
     failureInfo = nil;
 
     retVal = (*codeAddress)(__args[0], __args[1], __args[2], __args[3], __args[4], __args[5], __args[6],
-                            __args[7], __args[8], __args[9], __args[10]);
+			    __args[7], __args[8], __args[9], __args[10]);
 
 # ifdef VERBOSE
     if (@global(Verbose) == true) {
-        printf("retval is %"_ld_" (0x%"_lx_")\n", retVal, retVal);
+	printf("retval is %"_ld_" (0x%"_lx_")\n", retVal, retVal);
     }
 # endif
 
@@ -201,100 +201,100 @@
      || (returnTypeSymbol == @symbol(sint16))
      || (returnTypeSymbol == @symbol(sint32))) {
 # ifdef VERBOSE
-        if (@global(Verbose) == true) {
-            printf("return int: %x\n", retVal);
-        }
+	if (@global(Verbose) == true) {
+	    printf("return int: %x\n", retVal);
+	}
 # endif
-        RETURN ( __MKINT(retVal) );
+	RETURN ( __MKINT(retVal) );
     }
     if ((returnTypeSymbol == @symbol(uint))
      || (returnTypeSymbol == @symbol(uint8))
      || (returnTypeSymbol == @symbol(uint16))
      || (returnTypeSymbol == @symbol(uint32))) {
 # ifdef VERBOSE
-        if (@global(Verbose) == true) {
-            printf("return uint: %x\n", retVal);
-        }
+	if (@global(Verbose) == true) {
+	    printf("return uint: %x\n", retVal);
+	}
 # endif
-        RETURN ( __MKUINT(retVal) );
+	RETURN ( __MKUINT(retVal) );
     }
     if (returnTypeSymbol == @symbol(bool)) {
-        RETURN ( retVal ? true : false );
+	RETURN ( retVal ? true : false );
     }
     if (returnTypeSymbol == @symbol(void)) {
-        RETURN ( nil );
+	RETURN ( nil );
     }
     if (returnTypeSymbol == @symbol(char)) {
-        RETURN ( __MKCHARACTER(retVal & 0xFF) );
+	RETURN ( __MKCHARACTER(retVal & 0xFF) );
     }
     if (returnTypeSymbol == @symbol(wchar)) {
-        RETURN ( __MKUCHARACTER(retVal & 0xFFFF) );
+	RETURN ( __MKUCHARACTER(retVal & 0xFFFF) );
     }
 
 # ifdef VERBOSE
     if (@global(Verbose) == true) {
-        printf("return pointer: %"_lx_"\n", (INT)(retVal));
+	printf("return pointer: %"_lx_"\n", (INT)(retVal));
     }
 # endif
     if (returnTypeSymbol == @symbol(handle)) {
-        returnValue = __MKEXTERNALADDRESS(retVal);
+	returnValue = __MKEXTERNALADDRESS(retVal);
     } else if (returnTypeSymbol == @symbol(pointer)) {
-        returnValue = __MKEXTERNALBYTES(retVal);
+	returnValue = __MKEXTERNALBYTES(retVal);
     } else if (returnTypeSymbol == @symbol(bytePointer)) {
-        returnValue = __MKEXTERNALBYTES(retVal);
+	returnValue = __MKEXTERNALBYTES(retVal);
     } else if (returnTypeSymbol == @symbol(charPointer)) {
-        returnValue = __MKSTRING(retVal);
+	returnValue = __MKSTRING(retVal);
     } else if (returnTypeSymbol == @symbol(wcharPointer)) {
-        returnValue = __MKU16STRING(retVal);
+	returnValue = __MKU16STRING(retVal);
     } else {
-        __FAIL__(@symbol(UnknownReturnType2))
+	__FAIL__(@symbol(UnknownReturnType2))
     }
 getOutOfHere: ;
 %}.
     failureCode notNil ifTrue:[
-        (failureCode == #UnknownReturnType or:[ failureCode == #UnknownArgumentType ]) ifTrue:[
-            oldReturnType := returnType.
-            oldArgumentTypes := argumentTypes.
-            self adjustTypes.
-            ((oldReturnType ~= returnType) or:[oldArgumentTypes ~= argumentTypes]) ifTrue:[
-                thisContext restart
-            ].
-        ].
-        (failureCode == #BadArgForAsyncCall) ifTrue:[
-            ^ self tryAgainWithAsyncSafeArguments:argumentsOrNil forCPPInstance:aReceiverOrNil
-        ].
-        (failureCode == #FFINotSupported) ifTrue:[
-            self primitiveFailed:'FFI support missing in this build'.
-        ].
+	(failureCode == #UnknownReturnType or:[ failureCode == #UnknownArgumentType ]) ifTrue:[
+	    oldReturnType := returnType.
+	    oldArgumentTypes := argumentTypes.
+	    self adjustTypes.
+	    ((oldReturnType ~= returnType) or:[oldArgumentTypes ~= argumentTypes]) ifTrue:[
+		thisContext restart
+	    ].
+	].
+	(failureCode == #BadArgForAsyncCall) ifTrue:[
+	    ^ self tryAgainWithAsyncSafeArguments:argumentsOrNil forCPPInstance:aReceiverOrNil
+	].
+	(failureCode == #FFINotSupported) ifTrue:[
+	    self primitiveFailed:'FFI support missing in this build'.
+	].
 
-        self primitiveFailed.   "see failureCode and failureInfo for details"
-        ^ nil
+	self primitiveFailed.   "see failureCode and failureInfo for details"
+	^ nil
     ].
 
     returnType isSymbol ifTrue:[
-        returnValueClass notNil ifTrue:[
-            self isConstReturnValue ifTrue:[
-                returnValue changeClassTo:returnValueClass.
-                ^ returnValue
-            ].
-            ^ returnValueClass fromExternalAddress:returnValue.
-        ].
+	returnValueClass notNil ifTrue:[
+	    self isConstReturnValue ifTrue:[
+		returnValue changeClassTo:returnValueClass.
+		^ returnValue
+	    ].
+	    ^ returnValueClass fromExternalAddress:returnValue.
+	].
     ] ifFalse:[
-        returnType isCPointer ifTrue:[
-            returnType baseType isCStruct ifTrue:[
-                stClass := Smalltalk classNamed:returnType baseType name.
-                stClass notNil ifTrue:[
-                    self isConstReturnValue ifTrue:[
-                        returnValue changeClassTo:returnValueClass.
-                        ^ returnValue
-                    ].
-                    ^ stClass fromExternalAddress:returnValue.
-                ].
-            ].
-            returnType baseType isCChar ifTrue:[
-                ^ returnValue stringAt:1
-            ].
-        ].
+	returnType isCPointer ifTrue:[
+	    returnType baseType isCStruct ifTrue:[
+		stClass := Smalltalk classNamed:returnType baseType name.
+		stClass notNil ifTrue:[
+		    self isConstReturnValue ifTrue:[
+			returnValue changeClassTo:returnValueClass.
+			^ returnValue
+		    ].
+		    ^ stClass fromExternalAddress:returnValue.
+		].
+	    ].
+	    returnType baseType isCChar ifTrue:[
+		^ returnValue stringAt:1
+	    ].
+	].
     ].
 
     ^ returnValue