ExternalLibraryFunction.st
branchjv
changeset 18563 de37550dc3dd
parent 18261 22bdfc405bca
child 18609 af1c36c18e24
--- a/ExternalLibraryFunction.st	Tue Jul 07 14:47:09 2015 +0100
+++ b/ExternalLibraryFunction.st	Tue Jul 07 22:31:05 2015 +0100
@@ -11,6 +11,8 @@
 "
 "{ Package: 'stx:libbasic' }"
 
+"{ NameSpace: Smalltalk }"
+
 ExternalFunction subclass:#ExternalLibraryFunction
 	instanceVariableNames:'flags moduleName returnType argumentTypes owningClass'
 	classVariableNames:'DLLPATH FLAG_VIRTUAL FLAG_NONVIRTUAL FLAG_OBJECTIVEC FLAG_ASYNC
@@ -391,6 +393,14 @@
     "Created: / 01-08-2006 / 13:56:44 / cg"
 !
 
+beObjectiveC
+    "specify this as an objective-c message send"
+
+    flags := (flags ? 0) bitOr: FLAG_OBJECTIVEC.
+
+    "Created: / 01-08-2006 / 13:56:48 / cg"
+!
+
 beUnlimitedStack
     "let this execute on the c-stack (as opposed to the thread-stack)
      for unlimited auto-sized-stack under unix/linux.
@@ -409,14 +419,6 @@
     "Created: / 01-08-2006 / 13:56:48 / cg"
 !
 
-beObjectiveC
-    "specify this as an objective-c message send"
-
-    flags := (flags ? 0) bitOr: FLAG_OBJECTIVEC.
-
-    "Created: / 01-08-2006 / 13:56:48 / cg"
-!
-
 callTypeNumber
     ^ (flags ? 0) bitAnd: CALLTYPE_MASK.
 
@@ -439,12 +441,6 @@
     "Created: / 01-08-2006 / 13:56:54 / cg"
 !
 
-isObjectiveC
-    "is this an objective-C message?"
-
-    ^ (flags ? 0) bitTest: FLAG_OBJECTIVEC.
-!
-
 isCallTypeAPI
     ^ ((flags ? 0) bitAnd: CALLTYPE_MASK) == CALLTYPE_API.
 
@@ -480,6 +476,12 @@
     "Created: / 01-08-2006 / 13:56:51 / cg"
 !
 
+isObjectiveC
+    "is this an objective-C message?"
+
+    ^ (flags ? 0) bitTest: FLAG_OBJECTIVEC.
+!
+
 isUnlimitedStack
     "will this execute on the c-stack (as opposed to the thread-stack)
      for unlimited auto-sized-stack under unix/linux.
@@ -630,10 +632,13 @@
 !ExternalLibraryFunction methodsFor:'private'!
 
 adjustTypes
+
     argumentTypes notNil ifTrue:[
-	argumentTypes := argumentTypes collect:[:argType | self ffiTypeSymbolForType:argType].
+        argumentTypes := argumentTypes collect:[:argType | self ffiTypeSymbolForType:argType].
     ].
     returnType := self ffiTypeSymbolForType:returnType.
+
+    "Modified: / 07-07-2015 / 22:18:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 linkToModule
@@ -868,41 +873,49 @@
      oldReturnType oldArgumentTypes|
 
     argTypeSymbols := argumentTypes.
+
     returnTypeSymbol := returnType.
+    returnTypeSymbol isSymbol ifTrue:[ 
+        | returnValueClass0 |
 
+        returnValueClass0 := Smalltalk at: returnTypeSymbol.
+        returnValueClass0 isBehavior ifTrue:[
+            returnValue := returnValueClass0 basicNew.
+        ] 
+    ].
     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 isKindOf:ExternalStructure) ifFalse:[
-	    self primitiveFailed.
-	].
-	virtual ifTrue:[
-	    vtOffset := name.
-	    (vtOffset between:0 and:10000) ifFalse:[
-		self primitiveFailed.
-	    ]
-	].
+        "/ and it must be a kind of ExternalStructure !!
+        (aReceiverOrNil isKindOf:ExternalStructure) ifFalse:[
+            self primitiveFailed.
+        ].
+        virtual ifTrue:[
+            vtOffset := name.
+            (vtOffset between:0 and:10000) ifFalse:[
+                self primitiveFailed.
+            ]
+        ].
     ] 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.
+            ]
+        ].
     ].
     async := self isAsync.
     unlimitedStack := self isUnlimitedStack.
@@ -927,17 +940,17 @@
     ffi_type *__returnType = NULL;
 
     union u {
-	INT iVal;
-	float fVal;
-	double dVal;
-	void *pointerVal;
+        INT iVal;
+        float fVal;
+        double dVal;
+        void *pointerVal;
 # if defined(HAS_LONGLONG)
-	long long longLongVal;
+        long long longLongVal;
 # else
 #  ifdef HAS_INT64
-	__int64__ longLongVal;
+        __int64__ longLongVal;
 #  else
-	struct ll { long low; long hi; } longLongVal;
+        struct ll { long low; long hi; } longLongVal;
 #  endif
 # endif
     };
@@ -956,29 +969,29 @@
 
 #   define __FAIL__(fcode) \
     { \
-	failureCode = fcode; goto getOutOfHere; \
+        failureCode = fcode; 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 (argTypeSymbols == nil) {
-	__numArgsWanted = 0;
+        __numArgsWanted = 0;
     } else if (__isArray(argTypeSymbols)) {
-	__numArgsWanted = __arraySize(argTypeSymbols);
+        __numArgsWanted = __arraySize(argTypeSymbols);
     } else {
-	__FAIL__(@symbol(BadArgumentTypeVector))
+        __FAIL__(@symbol(BadArgumentTypeVector))
     }
 
     if (__numArgs != __numArgsWanted) {
-	__FAIL__(@symbol(ArgumentCountMismatch))
+        __FAIL__(@symbol(ArgumentCountMismatch))
     }
     if (__numArgs > MAX_ARGS) {
-	__FAIL__(@symbol(TooManyArguments))
+        __FAIL__(@symbol(TooManyArguments))
     }
 
     /*
@@ -987,130 +1000,130 @@
     __returnValuePointer = &__returnValue;
 
     if (returnTypeSymbol == @symbol(voidPointer)) {
-	returnTypeSymbol = @symbol(handle);
+        returnTypeSymbol = @symbol(handle);
     }
 
     if (returnTypeSymbol == @symbol(int)) {
-	__returnType = __get_ffi_type_sint();
+        __returnType = __get_ffi_type_sint();
     } else if (returnTypeSymbol == @symbol(uint)) {
-	__returnType = __get_ffi_type_uint();
+        __returnType = __get_ffi_type_uint();
     } else if (returnTypeSymbol == @symbol(uint8)) {
-	__returnType = __get_ffi_type_uint8();
+        __returnType = __get_ffi_type_uint8();
     } else if (returnTypeSymbol == @symbol(uint16)) {
-	__returnType = __get_ffi_type_uint16();
+        __returnType = __get_ffi_type_uint16();
     } else if (returnTypeSymbol == @symbol(uint32)) {
-	__returnType = __get_ffi_type_uint32();
+        __returnType = __get_ffi_type_uint32();
     } else if (returnTypeSymbol == @symbol(uint64)) {
-	__returnType = __get_ffi_type_uint64();
+        __returnType = __get_ffi_type_uint64();
 
     } else if (returnTypeSymbol == @symbol(sint)) {
-	__returnType = __get_ffi_type_sint();
+        __returnType = __get_ffi_type_sint();
     } else if (returnTypeSymbol == @symbol(sint8)) {
-	__returnType = __get_ffi_type_sint8();
+        __returnType = __get_ffi_type_sint8();
     } else if (returnTypeSymbol == @symbol(sint16)) {
-	__returnType = __get_ffi_type_sint16();
+        __returnType = __get_ffi_type_sint16();
     } else if (returnTypeSymbol == @symbol(sint32)) {
-	__returnType = __get_ffi_type_sint32();
+        __returnType = __get_ffi_type_sint32();
     } else if (returnTypeSymbol == @symbol(sint64)) {
-	__returnType = __get_ffi_type_sint64();
+        __returnType = __get_ffi_type_sint64();
 
     } else if (returnTypeSymbol == @symbol(long)) {
-	if (sizeof(long) == 4) {
-	   returnTypeSymbol = @symbol(sint32);
-	   __returnType = __get_ffi_type_sint32();
-	} else if (sizeof(long) == 8) {
-	   returnTypeSymbol = @symbol(sint64);
-	   __returnType = __get_ffi_type_sint64();
-	} else {
-	    __FAIL__(@symbol(UnknownReturnType))
-	}
+        if (sizeof(long) == 4) {
+           returnTypeSymbol = @symbol(sint32);
+           __returnType = __get_ffi_type_sint32();
+        } else if (sizeof(long) == 8) {
+           returnTypeSymbol = @symbol(sint64);
+           __returnType = __get_ffi_type_sint64();
+        } else {
+            __FAIL__(@symbol(UnknownReturnType))
+        }
 
     } else if (returnTypeSymbol == @symbol(ulong)) {
-	if (sizeof(long) == 4) {
-	   returnTypeSymbol = @symbol(uint32);
-	   __returnType = __get_ffi_type_uint32();
-	}else if (sizeof(long) == 8) {
-	   returnTypeSymbol = @symbol(uint64);
-	   __returnType = __get_ffi_type_uint64();
-	} else {
-	    __FAIL__(@symbol(UnknownReturnType))
-	}
+        if (sizeof(long) == 4) {
+           returnTypeSymbol = @symbol(uint32);
+           __returnType = __get_ffi_type_uint32();
+        }else if (sizeof(long) == 8) {
+           returnTypeSymbol = @symbol(uint64);
+           __returnType = __get_ffi_type_uint64();
+        } else {
+            __FAIL__(@symbol(UnknownReturnType))
+        }
 
     } else if (returnTypeSymbol == @symbol(bool)) {
-	__returnType = __get_ffi_type_uint();
+        __returnType = __get_ffi_type_uint();
 
     } else if (returnTypeSymbol == @symbol(float)) {
-	__returnType = __get_ffi_type_float();
+        __returnType = __get_ffi_type_float();
     } else if (returnTypeSymbol == @symbol(double)) {
-	__returnType = __get_ffi_type_double();
+        __returnType = __get_ffi_type_double();
 
     } else if (returnTypeSymbol == @symbol(void)) {
-	__returnType = __get_ffi_type_void();
-	__returnValuePointer = NULL;
+        __returnType = __get_ffi_type_void();
+        __returnValuePointer = NULL;
     } else if ((returnTypeSymbol == @symbol(pointer))
-	       || (returnTypeSymbol == @symbol(handle))
-	       || (returnTypeSymbol == @symbol(charPointer))
-	       || (returnTypeSymbol == @symbol(bytePointer))
-	       || (returnTypeSymbol == @symbol(floatPointer))
-	       || (returnTypeSymbol == @symbol(doublePointer))
-	       || (returnTypeSymbol == @symbol(intPointer))
-	       || (returnTypeSymbol == @symbol(shortPointer))
-	       || (returnTypeSymbol == @symbol(wcharPointer))) {
-	__returnType = __get_ffi_type_pointer();
+               || (returnTypeSymbol == @symbol(handle))
+               || (returnTypeSymbol == @symbol(charPointer))
+               || (returnTypeSymbol == @symbol(bytePointer))
+               || (returnTypeSymbol == @symbol(floatPointer))
+               || (returnTypeSymbol == @symbol(doublePointer))
+               || (returnTypeSymbol == @symbol(intPointer))
+               || (returnTypeSymbol == @symbol(shortPointer))
+               || (returnTypeSymbol == @symbol(wcharPointer))) {
+        __returnType = __get_ffi_type_pointer();
     } else {
-	if (__isSymbol(returnTypeSymbol)
-	 && ((returnValueClass = __GLOBAL_GET(returnTypeSymbol)) != nil)) {
-	    if (! __isBehaviorLike(returnValueClass)) {
-		__FAIL__(@symbol(NonBehaviorReturnType))
-	    }
-	    if (! __qIsSubclassOfExternalAddress(returnValueClass)) {
-		__FAIL__(@symbol(NonExternalAddressReturnType))
-	    }
-	    __returnType = __get_ffi_type_pointer();
-	    returnTypeSymbol = @symbol(pointer);
-	} else {
-	    __FAIL__(@symbol(UnknownReturnType))
-	}
+        if (__isSymbol(returnTypeSymbol)
+         && ((returnValueClass = __GLOBAL_GET(returnTypeSymbol)) != nil)) {
+            if (! __isBehaviorLike(returnValueClass)) {
+                __FAIL__(@symbol(NonBehaviorReturnType))
+            }
+            if (! __qIsSubclassOfExternalAddress(returnValueClass)) {
+                __FAIL__(@symbol(NonExternalAddressReturnType))
+            }
+            __returnType = __get_ffi_type_pointer();
+            returnTypeSymbol = @symbol(pointer);
+        } else {
+            __FAIL__(@symbol(UnknownReturnType))
+        }
     }
 
     /*
      * 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))
-	}
-	__argValues[0].pointerVal = inst;
-	__argValuePointersIncludingThis[0] = &(__argValues[0]);
-	__argTypes[0] = __get_ffi_type_pointer();
+        if (__isExternalAddressLike(aReceiverOrNil)) {
+            inst = (void *)(__externalAddressVal(aReceiverOrNil));
+        } else if (__isExternalBytesLike(aReceiverOrNil)) {
+            inst = (void *)(__externalBytesVal(aReceiverOrNil));
+        } else {
+            __FAIL__(@symbol(InvalidInstance))
+        }
+        __argValues[0].pointerVal = inst;
+        __argValuePointersIncludingThis[0] = &(__argValues[0]);
+        __argTypes[0] = __get_ffi_type_pointer();
 
-	__argValuePointers = &__argValuePointersIncludingThis[1];
-	__argTypes = &__argTypesIncludingThis[1];
-	__argValues = &__argValuesIncludingThis[1];
-	__numArgsIncludingThis = __numArgs + 1;
+        __argValuePointers = &__argValuePointersIncludingThis[1];
+        __argTypes = &__argTypesIncludingThis[1];
+        __argValues = &__argValuesIncludingThis[1];
+        __numArgsIncludingThis = __numArgs + 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
-	    printf("virtual codeAddress: %x\n", codeAddress);
+            printf("virtual codeAddress: %x\n", codeAddress);
 # endif
-	}
+        }
     } else {
-	__numArgsIncludingThis = __numArgs;
+        __numArgsIncludingThis = __numArgs;
 # ifdef VERBOSE
-	printf("codeAddress: %x\n", codeAddress);
+        printf("codeAddress: %x\n", codeAddress);
 # endif
     }
 
@@ -1118,339 +1131,339 @@
      * validate all arg types and setup arg-buffers
      */
     for (i=0; i<__numArgs; i++) {
-	ffi_type *thisType;
-	void *argValuePtr;
-	OBJ typeSymbol;
-	OBJ arg;
+        ffi_type *thisType;
+        void *argValuePtr;
+        OBJ typeSymbol;
+        OBJ arg;
 
-	failureInfo = __mkSmallInteger(i+1);   /* in case there is one */
+        failureInfo = __mkSmallInteger(i+1);   /* in case there is one */
 
-	typeSymbol = __ArrayInstPtr(argTypeSymbols)->a_element[i];
-	arg = __ArrayInstPtr(argumentsOrNil)->a_element[i];
+        typeSymbol = __ArrayInstPtr(argTypeSymbols)->a_element[i];
+        arg = __ArrayInstPtr(argumentsOrNil)->a_element[i];
 
-	if (typeSymbol == @symbol(handle)) {
-	    typeSymbol = @symbol(pointer);
-	} else if (typeSymbol == @symbol(voidPointer)) {
-	    typeSymbol = @symbol(pointer);
-	}
+        if (typeSymbol == @symbol(handle)) {
+            typeSymbol = @symbol(pointer);
+        } else if (typeSymbol == @symbol(voidPointer)) {
+            typeSymbol = @symbol(pointer);
+        }
 
-	if (typeSymbol == @symbol(long)) {
-	    if (sizeof(long) == sizeof(int)) {
-		typeSymbol = @symbol(sint);
-	    } else {
-		if (sizeof(long) == 4) {
-		    typeSymbol = @symbol(sint32);
-		} else if (sizeof(long) == 8) {
-		    typeSymbol = @symbol(sint64);
-		}
-	    }
-	}
-	if (typeSymbol == @symbol(ulong)) {
-	    if (sizeof(unsigned long) == sizeof(unsigned int)) {
-		typeSymbol = @symbol(uint);
-	    } else {
-		if (sizeof(long) == 4) {
-		    typeSymbol = @symbol(uint32);
-		} else if (sizeof(long) == 8) {
-		    typeSymbol = @symbol(uint64);
-		}
-	    }
-	}
+        if (typeSymbol == @symbol(long)) {
+            if (sizeof(long) == sizeof(int)) {
+                typeSymbol = @symbol(sint);
+            } else {
+                if (sizeof(long) == 4) {
+                    typeSymbol = @symbol(sint32);
+                } else if (sizeof(long) == 8) {
+                    typeSymbol = @symbol(sint64);
+                }
+            }
+        }
+        if (typeSymbol == @symbol(ulong)) {
+            if (sizeof(unsigned long) == sizeof(unsigned int)) {
+                typeSymbol = @symbol(uint);
+            } else {
+                if (sizeof(long) == 4) {
+                    typeSymbol = @symbol(uint32);
+                } else if (sizeof(long) == 8) {
+                    typeSymbol = @symbol(uint64);
+                }
+            }
+        }
 
-	if (typeSymbol == @symbol(int) || typeSymbol == @symbol(sint)) {
-	    thisType = __get_ffi_type_sint();
-	    if (__isSmallInteger(arg)) {
-		__argValues[i].iVal = __intVal(arg);
-	    } else {
-		__argValues[i].iVal = __signedLongIntVal(arg);
-		if (__argValues[i].iVal == 0) {
-		    __FAIL__(@symbol(InvalidArgument))
-		}
-	    }
-	    argValuePtr = &(__argValues[i].iVal);
+        if (typeSymbol == @symbol(int) || typeSymbol == @symbol(sint)) {
+            thisType = __get_ffi_type_sint();
+            if (__isSmallInteger(arg)) {
+                __argValues[i].iVal = __intVal(arg);
+            } else {
+                __argValues[i].iVal = __signedLongIntVal(arg);
+                if (__argValues[i].iVal == 0) {
+                    __FAIL__(@symbol(InvalidArgument))
+                }
+            }
+            argValuePtr = &(__argValues[i].iVal);
 
-	} else if (typeSymbol == @symbol(uint)) {
-	    thisType = __get_ffi_type_uint();
+        } else if (typeSymbol == @symbol(uint)) {
+            thisType = __get_ffi_type_uint();
 
-	    if (__isSmallInteger(arg)) {
-		__argValues[i].iVal = __intVal(arg);
-	    } else {
-		__argValues[i].iVal = __unsignedLongIntVal(arg);
-		if (__argValues[i].iVal == 0) {
-		    __FAIL__(@symbol(InvalidArgument))
-		}
-	    }
-	    argValuePtr = &(__argValues[i].iVal);
+            if (__isSmallInteger(arg)) {
+                __argValues[i].iVal = __intVal(arg);
+            } else {
+                __argValues[i].iVal = __unsignedLongIntVal(arg);
+                if (__argValues[i].iVal == 0) {
+                    __FAIL__(@symbol(InvalidArgument))
+                }
+            }
+            argValuePtr = &(__argValues[i].iVal);
 
-	} else if (typeSymbol == @symbol(uint8)) {
-	    thisType = __get_ffi_type_uint8();
-	    if (! __isSmallInteger(arg)) {
-		__FAIL__(@symbol(InvalidArgument))
-	    }
-	    __argValues[i].iVal = __intVal(arg);
-	    if (((unsigned)(__argValues[i].iVal)) > 0xFF) {
-		__FAIL__(@symbol(InvalidArgument))
-	    }
-	    argValuePtr = &(__argValues[i].iVal);
+        } else if (typeSymbol == @symbol(uint8)) {
+            thisType = __get_ffi_type_uint8();
+            if (! __isSmallInteger(arg)) {
+                __FAIL__(@symbol(InvalidArgument))
+            }
+            __argValues[i].iVal = __intVal(arg);
+            if (((unsigned)(__argValues[i].iVal)) > 0xFF) {
+                __FAIL__(@symbol(InvalidArgument))
+            }
+            argValuePtr = &(__argValues[i].iVal);
 
-	} else if (typeSymbol == @symbol(sint8)) {
-	    thisType = __get_ffi_type_sint8();
-	    if (! __isSmallInteger(arg)) {
-		__FAIL__(@symbol(InvalidArgument))
-	    }
-	    __argValues[i].iVal = __intVal(arg);
-	    if (((__argValues[i].iVal) < -0x80) || ((__argValues[i].iVal) > 0x7F))  {
-		__FAIL__(@symbol(InvalidArgument))
-	    }
-	    argValuePtr = &(__argValues[i].iVal);
+        } else if (typeSymbol == @symbol(sint8)) {
+            thisType = __get_ffi_type_sint8();
+            if (! __isSmallInteger(arg)) {
+                __FAIL__(@symbol(InvalidArgument))
+            }
+            __argValues[i].iVal = __intVal(arg);
+            if (((__argValues[i].iVal) < -0x80) || ((__argValues[i].iVal) > 0x7F))  {
+                __FAIL__(@symbol(InvalidArgument))
+            }
+            argValuePtr = &(__argValues[i].iVal);
 
-	} else if (typeSymbol == @symbol(uint16)) {
-	    thisType = __get_ffi_type_uint16();
-	    if (! __isSmallInteger(arg)) {
-		__FAIL__(@symbol(InvalidArgument))
-	    }
-	    __argValues[i].iVal = __intVal(arg);
-	    if (((unsigned)(__argValues[i].iVal)) > 0xFFFF) {
-		__FAIL__(@symbol(InvalidArgument))
-	    }
-	    argValuePtr = &(__argValues[i].iVal);
+        } else if (typeSymbol == @symbol(uint16)) {
+            thisType = __get_ffi_type_uint16();
+            if (! __isSmallInteger(arg)) {
+                __FAIL__(@symbol(InvalidArgument))
+            }
+            __argValues[i].iVal = __intVal(arg);
+            if (((unsigned)(__argValues[i].iVal)) > 0xFFFF) {
+                __FAIL__(@symbol(InvalidArgument))
+            }
+            argValuePtr = &(__argValues[i].iVal);
 
-	} else if (typeSymbol == @symbol(sint16)) {
-	    thisType = __get_ffi_type_sint16();
-	    if (! __isSmallInteger(arg)) {
-		__FAIL__(@symbol(InvalidArgument))
-	    }
-	    __argValues[i].iVal = __intVal(arg);
-	    if (((__argValues[i].iVal) < -0x8000) || ((__argValues[i].iVal) > 0x7FFF))  {
-		__FAIL__(@symbol(InvalidArgument))
-	    }
-	    argValuePtr = &(__argValues[i].iVal);
+        } else if (typeSymbol == @symbol(sint16)) {
+            thisType = __get_ffi_type_sint16();
+            if (! __isSmallInteger(arg)) {
+                __FAIL__(@symbol(InvalidArgument))
+            }
+            __argValues[i].iVal = __intVal(arg);
+            if (((__argValues[i].iVal) < -0x8000) || ((__argValues[i].iVal) > 0x7FFF))  {
+                __FAIL__(@symbol(InvalidArgument))
+            }
+            argValuePtr = &(__argValues[i].iVal);
 
-	} else if ((typeSymbol == @symbol(uint32)) || (typeSymbol == @symbol(sint32))) {
-	    thisType = __get_ffi_type_uint32();
-	    if (__isSmallInteger(arg)) {
-		__argValues[i].iVal = __intVal(arg);
-	    } else {
-		__argValues[i].iVal = __unsignedLongIntVal(arg);
-		if (__argValues[i].iVal == 0) {
-		    __FAIL__(@symbol(InvalidArgument))
-		}
-	    }
-	    argValuePtr = &(__argValues[i].iVal);
+        } else if ((typeSymbol == @symbol(uint32)) || (typeSymbol == @symbol(sint32))) {
+            thisType = __get_ffi_type_uint32();
+            if (__isSmallInteger(arg)) {
+                __argValues[i].iVal = __intVal(arg);
+            } else {
+                __argValues[i].iVal = __unsignedLongIntVal(arg);
+                if (__argValues[i].iVal == 0) {
+                    __FAIL__(@symbol(InvalidArgument))
+                }
+            }
+            argValuePtr = &(__argValues[i].iVal);
 
-	} else if (typeSymbol == @symbol(float)) {
-	    thisType = __get_ffi_type_float();
-	    if (__isSmallInteger(arg)) {
-		__argValues[i].fVal = (float)(__intVal(arg));
-	    } else if (__isFloat(arg)) {
-		__argValues[i].fVal = (float)(__floatVal(arg));
-	    } else if (__isShortFloat(arg)) {
-		__argValues[i].fVal = (float)(__shortFloatVal(arg));
-	    } else {
-		__FAIL__(@symbol(InvalidArgument))
-	    }
-	    argValuePtr = &(__argValues[i].fVal);
+        } else if (typeSymbol == @symbol(float)) {
+            thisType = __get_ffi_type_float();
+            if (__isSmallInteger(arg)) {
+                __argValues[i].fVal = (float)(__intVal(arg));
+            } else if (__isFloat(arg)) {
+                __argValues[i].fVal = (float)(__floatVal(arg));
+            } else if (__isShortFloat(arg)) {
+                __argValues[i].fVal = (float)(__shortFloatVal(arg));
+            } else {
+                __FAIL__(@symbol(InvalidArgument))
+            }
+            argValuePtr = &(__argValues[i].fVal);
 
-	} else if (typeSymbol == @symbol(double)) {
-	    thisType = __get_ffi_type_double();
-	    if (__isSmallInteger(arg)) {
-		__argValues[i].dVal = (double)(__intVal(arg));
-	    } else if (__isFloat(arg)) {
-		__argValues[i].dVal = (double)(__floatVal(arg));
-	    } else if (__isShortFloat(arg)) {
-		__argValues[i].dVal = (double)(__shortFloatVal(arg));
-	    } else {
-		__FAIL__(@symbol(InvalidArgument))
-	    }
-	    argValuePtr = &(__argValues[i].dVal);
+        } else if (typeSymbol == @symbol(double)) {
+            thisType = __get_ffi_type_double();
+            if (__isSmallInteger(arg)) {
+                __argValues[i].dVal = (double)(__intVal(arg));
+            } else if (__isFloat(arg)) {
+                __argValues[i].dVal = (double)(__floatVal(arg));
+            } else if (__isShortFloat(arg)) {
+                __argValues[i].dVal = (double)(__shortFloatVal(arg));
+            } else {
+                __FAIL__(@symbol(InvalidArgument))
+            }
+            argValuePtr = &(__argValues[i].dVal);
 
-	} else if (typeSymbol == @symbol(void)) {
-	    thisType = __get_ffi_type_void();
-	    argValuePtr = &null;
+        } else if (typeSymbol == @symbol(void)) {
+            thisType = __get_ffi_type_void();
+            argValuePtr = &null;
 
-	} else if (typeSymbol == @symbol(charPointer)) {
-	    thisType = __get_ffi_type_pointer();
-	    if (__isStringLike(arg)) {
-		if (async == true) goto badArgForAsyncCall;
-		__argValues[i].pointerVal = (void *)(__stringVal(arg));
-	    } else if (__isBytes(arg)) {
-		if (async == true) goto badArgForAsyncCall;
-		__argValues[i].pointerVal = (void *)(__byteArrayVal(arg));
-	    } else if (__isExternalAddressLike(arg)) {
-		__argValues[i].pointerVal = (void *)(__externalAddressVal(arg));
-	    } else if (__isExternalBytesLike(arg)) {
-		__argValues[i].pointerVal = (void *)(__externalBytesVal(arg));
-	    } else {
-		if (arg == nil) {
-		    __argValues[i].pointerVal = (void *)0;
-		} else {
-		    __FAIL__(@symbol(InvalidArgument))
-		}
-	    }
-	    argValuePtr = &(__argValues[i].pointerVal);;
+        } else if (typeSymbol == @symbol(charPointer)) {
+            thisType = __get_ffi_type_pointer();
+            if (__isStringLike(arg)) {
+                if (async == true) goto badArgForAsyncCall;
+                __argValues[i].pointerVal = (void *)(__stringVal(arg));
+            } else if (__isBytes(arg)) {
+                if (async == true) goto badArgForAsyncCall;
+                __argValues[i].pointerVal = (void *)(__byteArrayVal(arg));
+            } else if (__isExternalAddressLike(arg)) {
+                __argValues[i].pointerVal = (void *)(__externalAddressVal(arg));
+            } else if (__isExternalBytesLike(arg)) {
+                __argValues[i].pointerVal = (void *)(__externalBytesVal(arg));
+            } else {
+                if (arg == nil) {
+                    __argValues[i].pointerVal = (void *)0;
+                } else {
+                    __FAIL__(@symbol(InvalidArgument))
+                }
+            }
+            argValuePtr = &(__argValues[i].pointerVal);;
 
-	} else if (typeSymbol == @symbol(wcharPointer)) {
-	    thisType = __get_ffi_type_pointer();
-	    if (__isUnicode16String(arg)) {
-		if (async == true) goto badArgForAsyncCall;
-		__argValues[i].pointerVal = (void *)(__unicode16StringVal(arg));
-	    } else if (__isBytes(arg)) {
-		if (async == true) goto badArgForAsyncCall;
-		__argValues[i].pointerVal = (void *)(__byteArrayVal(arg));
-	    } else if (__isExternalAddressLike(arg)) {
-		__argValues[i].pointerVal = (void *)(__externalAddressVal(arg));
-	    } else if (__isExternalBytesLike(arg)) {
-		__argValues[i].pointerVal = (void *)(__externalBytesVal(arg));
-	    } else {
-		if (arg == nil) {
-		    __argValues[i].pointerVal = (void *)0;
-		} else {
-		    __FAIL__(@symbol(InvalidArgument))
-		}
-	    }
-	    argValuePtr = &(__argValues[i].pointerVal);;
+        } else if (typeSymbol == @symbol(wcharPointer)) {
+            thisType = __get_ffi_type_pointer();
+            if (__isUnicode16String(arg)) {
+                if (async == true) goto badArgForAsyncCall;
+                __argValues[i].pointerVal = (void *)(__unicode16StringVal(arg));
+            } else if (__isBytes(arg)) {
+                if (async == true) goto badArgForAsyncCall;
+                __argValues[i].pointerVal = (void *)(__byteArrayVal(arg));
+            } else if (__isExternalAddressLike(arg)) {
+                __argValues[i].pointerVal = (void *)(__externalAddressVal(arg));
+            } else if (__isExternalBytesLike(arg)) {
+                __argValues[i].pointerVal = (void *)(__externalBytesVal(arg));
+            } else {
+                if (arg == nil) {
+                    __argValues[i].pointerVal = (void *)0;
+                } else {
+                    __FAIL__(@symbol(InvalidArgument))
+                }
+            }
+            argValuePtr = &(__argValues[i].pointerVal);;
 
-	} else if (typeSymbol == @symbol(floatPointer)) {
-	    thisType = __get_ffi_type_pointer();
-	    if (__isBytes(arg)) {
-		if (async == true) goto badArgForAsyncCall;
-		__argValues[i].pointerVal = (void *)(__byteArrayVal(arg));
-	    } else if (__isExternalAddressLike(arg)) {
-		__argValues[i].pointerVal = (void *)(__externalAddressVal(arg));
-	    } else if (__isExternalBytesLike(arg)) {
-		__argValues[i].pointerVal = (void *)(__externalBytesVal(arg));
-	    } else if (__isFloats(arg)) {
-		char *p = (char *)(__FloatArrayInstPtr(arg)->f_element);
-		int nInstBytes;
-		OBJ cls;
+        } else if (typeSymbol == @symbol(floatPointer)) {
+            thisType = __get_ffi_type_pointer();
+            if (__isBytes(arg)) {
+                if (async == true) goto badArgForAsyncCall;
+                __argValues[i].pointerVal = (void *)(__byteArrayVal(arg));
+            } else if (__isExternalAddressLike(arg)) {
+                __argValues[i].pointerVal = (void *)(__externalAddressVal(arg));
+            } else if (__isExternalBytesLike(arg)) {
+                __argValues[i].pointerVal = (void *)(__externalBytesVal(arg));
+            } else if (__isFloats(arg)) {
+                char *p = (char *)(__FloatArrayInstPtr(arg)->f_element);
+                int nInstBytes;
+                OBJ cls;
 
-		if (async == true) goto badArgForAsyncCall;
-		cls = __qClass(arg);
-		nInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
-		p = p + nInstBytes;
-		__argValues[i].pointerVal = p;
-	    } else {
-		if (arg == nil) {
-		    __argValues[i].pointerVal = (void *)0;
-		} else {
-		    __FAIL__(@symbol(InvalidArgument))
-		}
-	    }
-	    argValuePtr = &(__argValues[i].pointerVal);;
+                if (async == true) goto badArgForAsyncCall;
+                cls = __qClass(arg);
+                nInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+                p = p + nInstBytes;
+                __argValues[i].pointerVal = p;
+            } else {
+                if (arg == nil) {
+                    __argValues[i].pointerVal = (void *)0;
+                } else {
+                    __FAIL__(@symbol(InvalidArgument))
+                }
+            }
+            argValuePtr = &(__argValues[i].pointerVal);;
 
-	} else if (typeSymbol == @symbol(doublePointer)) {
-	    thisType = __get_ffi_type_pointer();
-	    if (__isBytes(arg)) {
-		if (async == true) goto badArgForAsyncCall;
-		__argValues[i].pointerVal = (void *)(__byteArrayVal(arg));
-	    } else if (__isExternalAddressLike(arg)) {
-		__argValues[i].pointerVal = (void *)(__externalAddressVal(arg));
-	    } else if (__isExternalBytesLike(arg)) {
-		__argValues[i].pointerVal = (void *)(__externalBytesVal(arg));
-	    } else if (__isDoubles(arg)) {
-		char *p = (char *)(__DoubleArrayInstPtr(arg)->d_element);
-		int nInstBytes;
-		OBJ cls;
+        } else if (typeSymbol == @symbol(doublePointer)) {
+            thisType = __get_ffi_type_pointer();
+            if (__isBytes(arg)) {
+                if (async == true) goto badArgForAsyncCall;
+                __argValues[i].pointerVal = (void *)(__byteArrayVal(arg));
+            } else if (__isExternalAddressLike(arg)) {
+                __argValues[i].pointerVal = (void *)(__externalAddressVal(arg));
+            } else if (__isExternalBytesLike(arg)) {
+                __argValues[i].pointerVal = (void *)(__externalBytesVal(arg));
+            } else if (__isDoubles(arg)) {
+                char *p = (char *)(__DoubleArrayInstPtr(arg)->d_element);
+                int nInstBytes;
+                OBJ cls;
 
-		if (async == true) goto badArgForAsyncCall;
-		cls = __qClass(arg);
-		nInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
-		p = p + nInstBytes;
+                if (async == true) goto badArgForAsyncCall;
+                cls = __qClass(arg);
+                nInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+                p = p + nInstBytes;
 # ifdef __NEED_DOUBLE_ALIGN
-		if ((INT)(__DoubleArrayInstPtr(arg)->d_element) & (__DOUBLE_ALIGN-1)) {
-		    int delta = __DOUBLE_ALIGN - ((INT)p & (__DOUBLE_ALIGN-1));
+                if ((INT)(__DoubleArrayInstPtr(arg)->d_element) & (__DOUBLE_ALIGN-1)) {
+                    int delta = __DOUBLE_ALIGN - ((INT)p & (__DOUBLE_ALIGN-1));
 
-		    p += delta;
-		}
+                    p += delta;
+                }
 # endif
-		__argValues[i].pointerVal = p;
-	    } else {
-		if (arg == nil) {
-		    __argValues[i].pointerVal = (void *)0;
-		} else {
-		    __FAIL__(@symbol(InvalidArgument))
-		}
-	    }
-	    argValuePtr = &(__argValues[i].pointerVal);;
+                __argValues[i].pointerVal = p;
+            } else {
+                if (arg == nil) {
+                    __argValues[i].pointerVal = (void *)0;
+                } else {
+                    __FAIL__(@symbol(InvalidArgument))
+                }
+            }
+            argValuePtr = &(__argValues[i].pointerVal);;
 
-	} else if (typeSymbol == @symbol(pointer)) {
+        } else if (typeSymbol == @symbol(pointer)) {
 commonPointerTypeArg: ;
-	    thisType = __get_ffi_type_pointer();
-	    if (arg == nil) {
-		__argValues[i].pointerVal = NULL;
-	    } else if (__isExternalAddressLike(arg)) {
-		__argValues[i].pointerVal = (void *)(__externalAddressVal(arg));
-	    } else if (__isExternalBytesLike(arg)) {
-		__argValues[i].pointerVal = (void *)(__externalBytesVal(arg));
-	    } else if (__isByteArrayLike(arg)) {
-		if (async == true) goto badArgForAsyncCall;
-		__argValues[i].pointerVal = (void *)(__byteArrayVal(arg));
-	    } else if (__isWordArray(arg) || __isSignedWordArray(arg)
-		    || __isIntegerArray(arg) || __isSignedIntegerArray(arg)) {
-		if (async == true) goto badArgForAsyncCall;
-		__argValues[i].pointerVal = (void *)(__integerArrayVal(arg));
-	    } else if (__isFloatArray(arg)) {
-		if (async == true) goto badArgForAsyncCall;
-		__argValues[i].pointerVal = (void *)(__FloatArrayInstPtr(arg)->f_element);
-	    } else if (__isDoubleArray(arg)) {
-		if (async == true) goto badArgForAsyncCall;
-		__argValues[i].pointerVal = (void *)(__DoubleArrayInstPtr(arg)->d_element);
-	    } else if (__isStringLike(arg)) {
-		if (async == true) {
+            thisType = __get_ffi_type_pointer();
+            if (arg == nil) {
+                __argValues[i].pointerVal = NULL;
+            } else if (__isExternalAddressLike(arg)) {
+                __argValues[i].pointerVal = (void *)(__externalAddressVal(arg));
+            } else if (__isExternalBytesLike(arg)) {
+                __argValues[i].pointerVal = (void *)(__externalBytesVal(arg));
+            } else if (__isByteArrayLike(arg)) {
+                if (async == true) goto badArgForAsyncCall;
+                __argValues[i].pointerVal = (void *)(__byteArrayVal(arg));
+            } else if (__isWordArray(arg) || __isSignedWordArray(arg)
+                    || __isIntegerArray(arg) || __isSignedIntegerArray(arg)) {
+                if (async == true) goto badArgForAsyncCall;
+                __argValues[i].pointerVal = (void *)(__integerArrayVal(arg));
+            } else if (__isFloatArray(arg)) {
+                if (async == true) goto badArgForAsyncCall;
+                __argValues[i].pointerVal = (void *)(__FloatArrayInstPtr(arg)->f_element);
+            } else if (__isDoubleArray(arg)) {
+                if (async == true) goto badArgForAsyncCall;
+                __argValues[i].pointerVal = (void *)(__DoubleArrayInstPtr(arg)->d_element);
+            } else if (__isStringLike(arg)) {
+                if (async == true) {
 badArgForAsyncCall: ;
-		    __FAIL__(@symbol(BadArgForAsyncCall))
-		}
-		__argValues[i].pointerVal = (void *)(__stringVal(arg));
-	    } else if (__isBytes(arg) || __isWords(arg) || __isLongs(arg)) {
-		char *p = (char *)(__byteArrayVal(arg));
-		int nInstBytes;
-		OBJ cls;
+                    __FAIL__(@symbol(BadArgForAsyncCall))
+                }
+                __argValues[i].pointerVal = (void *)(__stringVal(arg));
+            } else if (__isBytes(arg) || __isWords(arg) || __isLongs(arg)) {
+                char *p = (char *)(__byteArrayVal(arg));
+                int nInstBytes;
+                OBJ cls;
 
-		if (async == true) goto badArgForAsyncCall;
-		cls = __qClass(arg);
-		nInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
-		__argValues[i].pointerVal = p + nInstBytes;
-	    } else {
-		__FAIL__(@symbol(InvalidArgument))
-	    }
-	    argValuePtr = &(__argValues[i].pointerVal);;
+                if (async == true) goto badArgForAsyncCall;
+                cls = __qClass(arg);
+                nInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+                __argValues[i].pointerVal = p + nInstBytes;
+            } else {
+                __FAIL__(@symbol(InvalidArgument))
+            }
+            argValuePtr = &(__argValues[i].pointerVal);;
 
-	} else if (typeSymbol == @symbol(bool)) {
-	    thisType = __get_ffi_type_uint();
+        } else if (typeSymbol == @symbol(bool)) {
+            thisType = __get_ffi_type_uint();
 
-	    if (arg == true) {
-		__argValues[i].iVal = 1;
-	    } else if (arg == false) {
-		__argValues[i].iVal = 0;
-	    } else if (__isSmallInteger(arg)) {
-		__argValues[i].iVal = __intVal(arg);
-	    } else {
-		__argValues[i].iVal = __unsignedLongIntVal(arg);
-		if (__argValues[i].iVal == 0) {
-		    __FAIL__(@symbol(InvalidArgument))
-		}
-	    }
-	    argValuePtr = &(__argValues[i].iVal);
-	} else {
-	    if (__isSymbol(typeSymbol)
-	     && ((argValueClass = __GLOBAL_GET(typeSymbol)) != nil)) {
-		if (! __isBehaviorLike(argValueClass)) {
-		    __FAIL__(@symbol(NonBehaviorArgumentType))
-		}
-		if (! __qIsSubclassOfExternalAddress(argValueClass)) {
-		    __FAIL__(@symbol(NonExternalAddressArgumentType))
-		}
-		goto commonPointerTypeArg; /* sorry */
-	    } else {
-		__FAIL__(@symbol(UnknownArgumentType))
-	    }
-	}
+            if (arg == true) {
+                __argValues[i].iVal = 1;
+            } else if (arg == false) {
+                __argValues[i].iVal = 0;
+            } else if (__isSmallInteger(arg)) {
+                __argValues[i].iVal = __intVal(arg);
+            } else {
+                __argValues[i].iVal = __unsignedLongIntVal(arg);
+                if (__argValues[i].iVal == 0) {
+                    __FAIL__(@symbol(InvalidArgument))
+                }
+            }
+            argValuePtr = &(__argValues[i].iVal);
+        } else {
+            if (__isSymbol(typeSymbol)
+             && ((argValueClass = __GLOBAL_GET(typeSymbol)) != nil)) {
+                if (! __isBehaviorLike(argValueClass)) {
+                    __FAIL__(@symbol(NonBehaviorArgumentType))
+                }
+                if (! __qIsSubclassOfExternalAddress(argValueClass)) {
+                    __FAIL__(@symbol(NonExternalAddressArgumentType))
+                }
+                goto commonPointerTypeArg; /* sorry */
+            } else {
+                __FAIL__(@symbol(UnknownArgumentType))
+            }
+        }
 
-	__argTypes[i] = thisType;
-	__argValuePointers[i] = argValuePtr;
+        __argTypes[i] = thisType;
+        __argValuePointers[i] = argValuePtr;
 
 # ifdef VERBOSE
-	printf("arg%d: %x\n", i, __argValues[i].iVal);
+        printf("arg%d: %x\n", i, __argValues[i].iVal);
 # endif
     }
     failureInfo = nil;
@@ -1459,53 +1472,53 @@
 
 # ifdef CALLTYPE_FFI_STDCALL
     if (callTypeNumber == @global(CALLTYPE_API)) {
-	__callType = CALLTYPE_FFI_STDCALL;
+        __callType = CALLTYPE_FFI_STDCALL;
     }
 # endif
 # ifdef CALLTYPE_FFI_V8
     if (callTypeNumber == @global(CALLTYPE_V8)) {
-	__callType = CALLTYPE_FFI_V8;
+        __callType = CALLTYPE_FFI_V8;
     }
 # endif
 # ifdef CALLTYPE_FFI_V9
     if (callTypeNumber == @global(CALLTYPE_V9)) {
-	__callType = CALLTYPE_FFI_V9;
+        __callType = CALLTYPE_FFI_V9;
     }
 # endif
 # ifdef CALLTYPE_FFI_UNIX64
     if (callTypeNumber == @global(CALLTYPE_UNIX64)) {
-	__callType = CALLTYPE_FFI_UNIX64;
+        __callType = CALLTYPE_FFI_UNIX64;
     }
 # endif
 
     if (ffi_prep_cif(&__cif, __callType, __numArgsIncludingThis, __returnType, __argTypesIncludingThis) != FFI_OK) {
-	__FAIL__(@symbol(FFIPrepareFailed))
+        __FAIL__(@symbol(FFIPrepareFailed))
     }
     if (async == true) {
 # ifdef VERBOSE
-	printf("async call 0x%x\n", codeAddress);
+        printf("async call 0x%x\n", codeAddress);
 # endif
 # ifdef WIN32
-	__STX_C_CALL4( "ffi_call", ffi_call, &__cif, codeAddress, __returnValuePointer, __argValuePointersIncludingThis);
+        __STX_C_CALL4( "ffi_call", ffi_call, &__cif, codeAddress, __returnValuePointer, __argValuePointersIncludingThis);
 # else
-	__BEGIN_INTERRUPTABLE__
-	ffi_call(&__cif, codeAddress, __returnValuePointer, __argValuePointersIncludingThis);
-	__END_INTERRUPTABLE__
+        __BEGIN_INTERRUPTABLE__
+        ffi_call(&__cif, codeAddress, __returnValuePointer, __argValuePointersIncludingThis);
+        __END_INTERRUPTABLE__
 # endif
     } else {
-	if (unlimitedStack == true) {
+        if (unlimitedStack == true) {
 # ifdef VERBOSE
-	    printf("UNLIMITEDSTACKCALL call 0x%x\n", codeAddress);
+            printf("UNLIMITEDSTACKCALL call 0x%x\n", codeAddress);
 # endif
 # if 0
-	    __UNLIMITEDSTACKCALL__(ffi_call, &__cif, codeAddress, __returnValuePointer, __argValuePointersIncludingThis);
+            __UNLIMITEDSTACKCALL__(ffi_call, &__cif, codeAddress, __returnValuePointer, __argValuePointersIncludingThis);
 # endif
-	} else {
+        } else {
 # ifdef VERBOSE
-	    printf("call 0x%x\n", codeAddress);
+            printf("call 0x%x\n", codeAddress);
 # endif
-	    ffi_call(&__cif, codeAddress, __returnValuePointer, __argValuePointersIncludingThis);
-	}
+            ffi_call(&__cif, codeAddress, __returnValuePointer, __argValuePointersIncludingThis);
+        }
     }
 # ifdef VERBOSE
     printf("retval is %d (0x%x)\n", __returnValue.iVal, __returnValue.iVal);
@@ -1515,54 +1528,64 @@
      || (returnTypeSymbol == @symbol(sint8))
      || (returnTypeSymbol == @symbol(sint16))
      || (returnTypeSymbol == @symbol(sint32))) {
-	RETURN ( __MKINT(__returnValue.iVal) );
+        RETURN ( __MKINT(__returnValue.iVal) );
     }
     if ((returnTypeSymbol == @symbol(uint))
      || (returnTypeSymbol == @symbol(uint8))
      || (returnTypeSymbol == @symbol(uint16))
      || (returnTypeSymbol == @symbol(uint32))) {
-	RETURN ( __MKUINT(__returnValue.iVal) );
+        RETURN ( __MKUINT(__returnValue.iVal) );
     }
     if (returnTypeSymbol == @symbol(bool)) {
-	RETURN ( __returnValue.iVal ? true : false );
+        RETURN ( __returnValue.iVal ? true : false );
     }
     if (returnTypeSymbol == @symbol(float)) {
-	RETURN ( __MKFLOAT(__returnValue.fVal ));
+        RETURN ( __MKFLOAT(__returnValue.fVal ));
     }
     if (returnTypeSymbol == @symbol(double)) {
-	RETURN ( __MKFLOAT(__returnValue.dVal ));
+        RETURN ( __MKFLOAT(__returnValue.dVal ));
     }
     if (returnTypeSymbol == @symbol(void)) {
-	RETURN ( nil );
+        RETURN ( nil );
     }
     if (returnTypeSymbol == @symbol(char)) {
-	RETURN ( __MKCHARACTER(__returnValue.iVal & 0xFF) );
+        RETURN ( __MKCHARACTER(__returnValue.iVal & 0xFF) );
     }
     if (returnTypeSymbol == @symbol(wchar)) {
-	RETURN ( __MKUCHARACTER(__returnValue.iVal & 0xFFFF) );
+        RETURN ( __MKUCHARACTER(__returnValue.iVal & 0xFFFF) );
     }
     if (returnTypeSymbol == @symbol(sint64)) {
-	RETURN ( __MKINT64(&__returnValue.longLongVal) );
+        RETURN ( __MKINT64(&__returnValue.longLongVal) );
     }
     if (returnTypeSymbol == @symbol(uint64)) {
-	RETURN ( __MKUINT64(&__returnValue.longLongVal) );
+        RETURN ( __MKUINT64(&__returnValue.longLongVal) );
     }
 
 # ifdef VERBOSE
     printf("%x\n", __returnValue.pointerVal);
 # endif
     if (returnTypeSymbol == @symbol(handle)) {
-	returnValue = __MKEXTERNALADDRESS(__returnValue.pointerVal);
+        if (returnValue != nil) {
+            __externalAddressVal(returnValue) = __returnValue.pointerVal;
+            returnValueClass = nil;
+        } else {
+            returnValue = __MKEXTERNALADDRESS(__returnValue.pointerVal);
+        }
     } else if (returnTypeSymbol == @symbol(pointer)) {
-	returnValue = __MKEXTERNALBYTES(__returnValue.pointerVal);
+        if (returnValue != nil) {        
+            __externalBytesVal(returnValue) = __returnValue.pointerVal;
+            returnValueClass = nil;
+        } else {    
+            returnValue = __MKEXTERNALBYTES(__returnValue.pointerVal);
+        }
     } else if (returnTypeSymbol == @symbol(bytePointer)) {
-	returnValue = __MKEXTERNALBYTES(__returnValue.pointerVal);
+        returnValue = __MKEXTERNALBYTES(__returnValue.pointerVal);
     } else if (returnTypeSymbol == @symbol(charPointer)) {
-	returnValue = __MKSTRING(__returnValue.pointerVal);
+        returnValue = __MKSTRING(__returnValue.pointerVal);
     } else if (returnTypeSymbol == @symbol(wcharPointer)) {
-	returnValue = __MKU16STRING(__returnValue.pointerVal);
+        returnValue = __MKU16STRING(__returnValue.pointerVal);
     } else {
-	__FAIL__(@symbol(UnknownReturnType2))
+        __FAIL__(@symbol(UnknownReturnType2))
     }
 #else /* no FFI support */
     failureCode = @symbol(FFINotSupported);
@@ -1570,55 +1593,59 @@
 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 isBehavior ifTrue:[
+        returnValue initialize.    
+        ^ returnValue
+    ].
     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
 
     "Created: / 01-08-2006 / 13:56:23 / cg"
     "Modified: / 11-06-2007 / 01:50:36 / cg"
+    "Modified: / 07-07-2015 / 22:21:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 tryAgainWithAsyncSafeArguments:argumentsOrNil forCPPInstance:aReceiverOrNil
@@ -1696,8 +1723,14 @@
     ^ '$Header: /cvs/stx/stx/libbasic/ExternalLibraryFunction.st,v 1.97 2015-04-20 10:48:54 cg Exp $'
 !
 
+version_HG
+
+    ^ '$Changeset: <not expanded> $'
+!
+
 version_SVN
     ^ '§ Id: ExternalLibraryFunction.st 10643 2011-06-08 21:53:07Z vranyj1  §'
 ! !
 
+
 ExternalLibraryFunction initialize!