--- a/ExternalLibraryFunction.st Tue Apr 25 16:18:18 2006 +0200
+++ b/ExternalLibraryFunction.st Tue Apr 25 17:57:26 2006 +0200
@@ -25,23 +25,6 @@
# define MAX_ARGS 128
-# define STX_FFI_TYPE_VOID 0
-# define STX_FFI_TYPE_INT 1
-# define STX_FFI_TYPE_FLOAT 2
-# define STX_FFI_TYPE_DOUBLE 3
-# define STX_FFI_TYPE_LONGDOUBLE 4
-# define STX_FFI_TYPE_UINT8 5
-# define STX_FFI_TYPE_SINT8 6
-# define STX_FFI_TYPE_UINT16 7
-# define STX_FFI_TYPE_SINT16 8
-# define STX_FFI_TYPE_UINT32 9
-# define STX_FFI_TYPE_SINT32 10
-# define STX_FFI_TYPE_UINT64 11
-# define STX_FFI_TYPE_SINT64 12
-# define STX_FFI_TYPE_STRUCT 0x10000 /* + size */
-# define STX_FFI_TYPE_STRUCT_SIZE_MASK 0x0FFFF /* size mask */
-# define STX_FFI_TYPE_POINTER 13
-
%}
! !
@@ -178,7 +161,7 @@
%{ /* STACK: 32000 */
ffi_cif __cif;
ffi_type *__argTypes[MAX_ARGS];
- ffi_type *__returnType;
+ ffi_type *__returnType = NULL;
union {
int iVal;
} __argValues[MAX_ARGS];
@@ -188,6 +171,8 @@
int i;
ffi_abi __callType = FFI_DEFAULT_ABI;
+printf("uint type2: %x\n", __get_ffi_type_uint());
+
if (arguments == nil) {
__numArgs = 0;
if (argTypeSymbols != nil) {
@@ -210,23 +195,35 @@
goto error;
}
- for (i=-1; i<__numArgs; i++) {
+ if (returnTypeSymbol == @symbol(int)) {
+printf("ret int\n");
+ __returnType = __get_ffi_type_sint();
+ } else if (returnTypeSymbol == @symbol(uint)) {
+printf("ret uint\n");
+ __returnType = __get_ffi_type_uint();
+ } else if (returnTypeSymbol == @symbol(boolean)) {
+printf("ret boolean\n");
+ __returnType = __get_ffi_type_uint();
+ } else if (returnTypeSymbol == @symbol(void)) {
+printf("void\n");
+ __returnType = __get_ffi_type_void();
+ } else {
+ failureCode = @symbol(UnknownReturnType);
+ goto error;
+ }
+
+ for (i=0; i<__numArgs; i++) {
ffi_type *thisType;
void *argValuePtr;
OBJ typeSymbol;
OBJ arg;
- if (i == -1) {
- typeSymbol = returnTypeSymbol;
- } else {
- typeSymbol = __ArrayInstPtr(argTypeSymbols)->a_element[i];
- arg = __ArrayInstPtr(arguments)->a_element[i];
- }
+printf("arg%d\n", i);
+ typeSymbol = __ArrayInstPtr(argTypeSymbols)->a_element[i];
+ arg = __ArrayInstPtr(arguments)->a_element[i];
if (typeSymbol == @symbol(int)) {
- thisType = &ffi_type_sint;
- if (i == -1) break;
-
+ thisType = __get_ffi_type_sint();
if (__isSmallInteger(arg)) {
__argValues[i].iVal = __intVal(arg);
} else {
@@ -238,8 +235,8 @@
}
argValuePtr = &(__argValues[i].iVal);
} else if (typeSymbol == @symbol(uint)) {
- thisType = &ffi_type_uint;
- if (i == -1) break;
+printf("uint\n");
+ thisType = __get_ffi_type_uint();
if (__isSmallInteger(arg)) {
__argValues[i].iVal = __intVal(arg);
@@ -252,13 +249,12 @@
}
argValuePtr = &(__argValues[i].iVal);
} else if (typeSymbol == @symbol(void)) {
- thisType = &ffi_type_void;
- if (i == -1) break;
-
+printf("void\n");
+ thisType = __get_ffi_type_void();
argValuePtr = &null;
} else if (typeSymbol == @symbol(boolean)) {
- thisType = &ffi_type_uint;
- if (i == -1) break;
+printf("boolean\n");
+ thisType = __get_ffi_type_uint();
if (arg == true) {
__argValues[i].iVal = 1;
@@ -275,20 +271,13 @@
}
argValuePtr = &(__argValues[i].iVal);
} else {
- if (i == -1) {
- failureCode = @symbol(UnknownReturnType);
- } else {
- failureCode = @symbol(UnknownArgumentType);
- }
+ failureCode = @symbol(UnknownArgumentType);
goto error;
}
- if (i == -1) {
- __returnType = thisType;
- } else {
- __argTypes[i] = thisType;
- __argValuePointers[i] = argValuePtr;
- }
+ __argTypes[i] = thisType;
+ __argValuePointers[i] = argValuePtr;
+printf("__argType[%d]: %x\n", i, thisType);
}
if (__INST(callType) == @symbol(callTypeC)) {
@@ -306,6 +295,14 @@
goto error;
}
+printf("return type: %x\n", __returnType);
+printf("return type size: %x\n", __returnType->size);
+printf("return type alignment: %x\n", __returnType->alignment);
+
+printf("arg type: %x\n", __argTypes[0]);
+printf("arg type size: %x\n", __argTypes[0]->size);
+printf("arg type alignment: %x\n", __argTypes[0]->alignment);
+
if (ffi_prep_cif(&__cif, __callType, __numArgs, __returnType, __argTypes) != FFI_OK) {
failureCode = @symbol(FFIPrepareFailed);
goto error;
@@ -409,5 +406,5 @@
!ExternalLibraryFunction class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/ExternalLibraryFunction.st,v 1.8 2006-04-25 14:18:18 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/ExternalLibraryFunction.st,v 1.9 2006-04-25 15:57:26 cg Exp $'
! !