--- a/ExternalFunctionCallback.st Mon Feb 19 14:59:40 2018 +0100
+++ b/ExternalFunctionCallback.st Mon Feb 19 16:01:21 2018 +0100
@@ -565,6 +565,7 @@
int i;
ffi_abi __callType = FFI_DEFAULT_ABI;
int __numArgsWanted;
+#ifdef OLD_FFI
struct closurePlusCIF {
ffi_closure closure;
ffi_cif cif;
@@ -573,17 +574,33 @@
ffi_closure *pcl;
ffi_cif *cif;
ffi_type **argTypePtrs;
+#else
+ ffi_closure *closure;
+ void* codePtr;
+ ffi_cif _cif;
+ ffi_cif *cif = &_cif;
+ ffi_type *argTypes[MAX_ARGS];
+#endif
+#ifdef OLD_FFI
closurePlusCIFp = (struct closurePlusCIF *) malloc(sizeof(struct closurePlusCIF));
- cif = &(closurePlusCIFp->cif);
- argTypePtrs = closurePlusCIFp->argTypes;
- pcl = &(closurePlusCIFp->closure);
-
+ codePtr = &(closurePlusCIFp->closure);
# define __FAIL__(fcode) \
{ \
failureCode = fcode; free(closurePlusCIFp); goto getOutOfHere; \
}
+#else
+ closurePlusCIFp = (struct closurePlusCIF *) ffi_closure_alloc(sizeof(struct closurePlusCIF), &codePtr);
+# define __FAIL__(fcode) \
+ { \
+ failureCode = fcode; ffi_closure_free(closure); goto getOutOfHere; \
+ }
+#endif
+ pcl = &(closurePlusCIFp->closure);
+ cif = &(closurePlusCIFp->cif);
+ argTypePtrs = closurePlusCIFp->argTypes;
+
if (argTypeSymbols == nil) {
__numArgsWanted = 0;
} else if (__isArrayLike(argTypeSymbols)) {
@@ -770,7 +787,7 @@
__FAIL__(@symbol(UnknownArgumentType))
}
- closurePlusCIFp->argTypes[i] = thisType;
+ argTypePtrs[i] = thisType;
}
failureInfo = nil;
@@ -800,7 +817,7 @@
}
#endif
if (@global(ExternalFunctionCallback:Verbose) == true) {
- printf("prep_cif cif-ptr=%"_lx_"\n", (INT)cif);
+ printf("prep_cif callType:%d cif-ptr=%p\n", __callType, (INT)cif);
}
if (ffi_prep_cif(cif, __callType, __numArgsWanted, __returnType, argTypePtrs) != FFI_OK) {
@@ -811,9 +828,15 @@
printf("closure is 0x%"_lx_" (%d bytes)\n", (INT)pcl, (int)sizeof(ffi_closure));
printf("index is %"_ld_"\n", __intVal(callBackIndex));
}
+#ifdef OLD_FFI
if (ffi_prep_closure(pcl, cif, ExternalFunctionCallback__closure_wrapper_fn, (void *)(__intVal(callBackIndex)) /* userdata */) != FFI_OK) {
__FAIL__(@symbol(FFIPrepareClosureFailed))
}
+#else
+ if (ffi_prep_closure_loc(pcl, cif, ExternalFunctionCallback__closure_wrapper_fn, (void *)(__intVal(callBackIndex), codePtr)) != FFI_OK) {
+ __FAIL__(@symbol(FFIPrepareClosureFailed))
+ }
+#endif
if (@global(ExternalFunctionCallback:Verbose) == true) {
printf("pcl->cif is 0x%"_lx_"\n", (INT)(pcl->cif));
printf("pcl->fun is 0x%"_lx_"\n", (INT)(pcl->fun));