ExternalFunctionCallback.st
branchjv
changeset 18011 deb0c3355881
parent 17911 a99f15c5efa5
parent 14659 410089913ca1
child 18026 fa8a879502cb
--- a/ExternalFunctionCallback.st	Thu Dec 20 11:48:59 2012 +0000
+++ b/ExternalFunctionCallback.st	Sat Jan 19 01:30:00 2013 +0000
@@ -27,6 +27,22 @@
 # include <ffi.h>
 # define MAX_ARGS    128
 
+# ifdef USE_STANDARD_FFI
+#  define __get_ffi_type_sint() &ffi_type_sint
+#  define __get_ffi_type_sint8() &ffi_type_sint8
+#  define __get_ffi_type_sint16() &ffi_type_sint16
+#  define __get_ffi_type_sint32() &ffi_type_sint32
+#  define __get_ffi_type_sint64() &ffi_type_sint64
+#  define __get_ffi_type_uint() &ffi_type_uint
+#  define __get_ffi_type_uint8() &ffi_type_uint8
+#  define __get_ffi_type_uint16() &ffi_type_uint16
+#  define __get_ffi_type_uint32() &ffi_type_uint32
+#  define __get_ffi_type_uint64() &ffi_type_uint64
+#  define __get_ffi_type_float() &ffi_type_float
+#  define __get_ffi_type_double() &ffi_type_double
+#  define __get_ffi_type_void() &ffi_type_void
+#  define __get_ffi_type_pointer() &ffi_type_pointer
+# else
 extern ffi_type *__get_ffi_type_sint();
 extern ffi_type *__get_ffi_type_sint8();
 extern ffi_type *__get_ffi_type_sint16();
@@ -41,6 +57,7 @@
 extern ffi_type *__get_ffi_type_double();
 extern ffi_type *__get_ffi_type_void();
 extern ffi_type *__get_ffi_type_pointer();
+# endif
 
 #endif
 
@@ -56,7 +73,7 @@
 void
 ExternalFunctionCallback__closure_wrapper_fn(ffi_cif* cif, void* resp, void** args, void* userdata)
 {
-    int actionIndex = (int)userdata;
+    INT actionIndex = (INT)userdata;
     int i;
     OBJ st_argVector = nil;
     OBJ st_actionVector, st_callBack = nil, st_result;
@@ -68,7 +85,7 @@
     double doubleResult;
 
     if (@global(ExternalFunctionCallback:Verbose) == true) {
-	fprintf(stderr, "ExternalFunctionCallback(wrapper): actionIndex=%d resp*=%x\n", actionIndex, resp);
+	fprintf(stderr, "ExternalFunctionCallback(wrapper): actionIndex=%"_ld_" resp*=%"_lx_"\n", actionIndex, (INT)resp);
 	fflush(stderr);
 	fprintf(stderr, "ExternalFunctionCallback(wrapper): nargs=%d\n", cif->nargs);
 	fflush(stderr);
@@ -107,14 +124,14 @@
 	    st_arg = __MKEXTERNALADDRESS( *(void **)(args[i]) );
 	} else {
 	    if (@global(ExternalFunctionCallback:Verbose) == true) {
-		fprintf(stderr, "ExternalFunctionCallback(wrapper): invalid argument type %d - arg %d\n", argType, i);
+		fprintf(stderr, "ExternalFunctionCallback(wrapper): invalid argument type %"_lx_" - arg %d\n", (INT)argType, i);
 	    }
 	}
 
 	__UNPROTECT__(st_argVector);
 
 	if (@global(ExternalFunctionCallback:Verbose) == true) {
-	    fprintf(stderr, "ExternalFunctionCallback(wrapper): st-arg for %x is %x\n", *(unsigned int *)(args[i]), st_arg);
+	    fprintf(stderr, "ExternalFunctionCallback(wrapper): st-arg for %"_lx_" is %"_lx_"\n", *(unsigned INT *)(args[i]), (INT)st_arg);
 	}
 	__ArrayInstPtr(st_argVector)->a_element[i] = st_arg; __STORE(st_argVector, st_arg);
     }
@@ -144,11 +161,11 @@
 	static struct inlineCache value_snd = _DUMMYILC1;
 
 	if (@global(ExternalFunctionCallback:Verbose) == true) {
-	    fprintf(stderr, "ExternalFunctionCallback(wrapper): sending value: to %x..\n", st_callBack);
+	    fprintf(stderr, "ExternalFunctionCallback(wrapper): sending value: to %"_lx_"..\n", (INT)st_callBack);
 	}
 	st_result = _SEND1(st_callBack, @symbol(callFromCWith:), nil, &value_snd, st_argVector);
 	if (@global(ExternalFunctionCallback:Verbose) == true) {
-	    fprintf(stderr, "ExternalFunctionCallback(wrapper): result is %x\n", st_result);
+	    fprintf(stderr, "ExternalFunctionCallback(wrapper): result is %"_lx_"\n", (INT)st_result);
 	}
     }
 
@@ -205,7 +222,7 @@
 	*(void **)resp = (void *)__externalAddressVal( st_result );
     } else {
 	if (@global(ExternalFunctionCallback:Verbose) == true) {
-	    fprintf(stderr, "ExternalFunctionCallback(wrapper): invalid result type %d\n", retType, i);
+	    fprintf(stderr, "ExternalFunctionCallback(wrapper): invalid result type %"_ld_"\n", (INT)retType);
 	}
 	*(void **)resp = 0;
     }
@@ -214,11 +231,11 @@
 void
 ExternalFunctionCallback__test_call_closure(INTFUNC f)
 {
-    int result = 0;
+    INT result = 0;
 
-    printf("doCall_closure: calling closure %x(123)...\n", f);
+    printf("doCall_closure: calling closure %"_lx_"(123)...\n", (INT)f);
     result = (*f)(123);
-    printf("doCall_closure: back; result is %x...\n", result);
+    printf("doCall_closure: back; result is %"_lx_"...\n", (INT)result);
 }
 #endif /* HAVE_FFI */
 
@@ -411,9 +428,9 @@
 	} else
 	    goto badArg;
     }
-    fprintf(stderr, "ExternalFunctionCallback: calling callBack %x(%x, %x)\n", f, c_args[0], c_args[1]);
+    fprintf(stderr, "ExternalFunctionCallback: calling callBack %"_lx_"(%"_lx_", %"_lx_")\n", (INT)f, (INT)(c_args[0]), (INT)(c_args[1]));
     result = (*f)(c_args[0], c_args[1], c_args[2], c_args[3], c_args[4]);
-    fprintf(stderr, "ExternalFunctionCallback: result from callBack is %x\n", result);
+    fprintf(stderr, "ExternalFunctionCallback: result from callBack is %"_lx_"\n", (INT)result);
     RETURN(true);
 
 badArg: ;
@@ -493,7 +510,7 @@
 
 code
     self hasCode ifFalse:[
-        self generateClosure
+	self generateClosure
     ].
     ^ super code
 
@@ -765,7 +782,7 @@
     }
 
     if (@global(ExternalFunctionCallback:Verbose) == true) {
-	printf("prep_cif cif-ptr=%x\n", cif);
+	printf("prep_cif cif-ptr=%"_lx_"\n", (INT)cif);
     }
 
     if (ffi_prep_cif(cif, __callType, __numArgsWanted, __returnType, argTypePtrs) != FFI_OK) {
@@ -773,22 +790,22 @@
     }
 
     if (@global(ExternalFunctionCallback:Verbose) == true) {
-	printf("closure is 0x%x (%d bytes)\n", pcl, sizeof(ffi_closure));
-	printf("index is %d\n", __intVal(callBackIndex));
+	printf("closure is 0x%"_lx_" (%d bytes)\n", (INT)pcl, (int)sizeof(ffi_closure));
+	printf("index is %"_ld_"\n", __intVal(callBackIndex));
     }
     if (ffi_prep_closure(pcl, cif, ExternalFunctionCallback__closure_wrapper_fn, (void *)(__intVal(callBackIndex)) /* userdata */) != FFI_OK) {
 	__FAIL__(@symbol(FFIPrepareClosureFailed))
     }
     if (@global(ExternalFunctionCallback:Verbose) == true) {
-	printf("pcl->cif is 0x%x\n", pcl->cif);
-	printf("pcl->fun is 0x%x\n", pcl->fun);
-	printf("pcl code at %x is:\n", pcl);
+	printf("pcl->cif is 0x%"_lx_"\n", (INT)(pcl->cif));
+	printf("pcl->fun is 0x%"_lx_"\n", (INT)(pcl->fun));
+	printf("pcl code at %"_lx_" is:\n", (INT)pcl);
 	printf("  %02x %02x %02x %02x\n", ((unsigned char *)pcl)[0],((unsigned char *)pcl)[1],((unsigned char *)pcl)[2],((unsigned char *)pcl)[3]);
 	printf("  %02x %02x %02x %02x\n", ((unsigned char *)pcl)[4],((unsigned char *)pcl)[5],((unsigned char *)pcl)[6],((unsigned char *)pcl)[7]);
 	printf("  %02x %02x %02x %02x\n", ((unsigned char *)pcl)[8],((unsigned char *)pcl)[9],((unsigned char *)pcl)[10],((unsigned char *)pcl)[11]);
 	printf("  %02x %02x %02x %02x\n", ((unsigned char *)pcl)[12],((unsigned char *)pcl)[13],((unsigned char *)pcl)[14],((unsigned char *)pcl)[15]);
     }
-    __INST(code_) = pcl;
+    __INST(code_) = (OBJ)pcl;
 
 #if 0
     ExternalFunctionCallback__test_call_closure((INTFUNC)pcl);
@@ -829,17 +846,9 @@
 !ExternalFunctionCallback class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/ExternalFunctionCallback.st,v 1.18 2011/12/12 19:30:09 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ExternalFunctionCallback.st,v 1.21 2013-01-16 12:20:15 cg Exp $'
 !
 
 version_CVS
-    ^ 'Header: /cvs/stx/stx/libbasic/ExternalFunctionCallback.st,v 1.18 2011/12/12 19:30:09 cg Exp '
-!
-
-version_SVN
-    ^ '$Id: ExternalFunctionCallback.st 10761 2012-01-19 11:46:00Z vranyj1 $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ExternalFunctionCallback.st,v 1.21 2013-01-16 12:20:15 cg Exp $'
 ! !
-
-
-
-