From 91269cf351ed9b25b6c5e82351c6a93b437e13e3 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Sun, 27 May 2018 13:13:49 -0700 Subject: [PATCH] i64 marshalling; fix for floats in asm.js mode note the test suite currently ends up running in asm.js mode instead of wasm, and floats get promoted to doubles in the asm.js abi but not in the wasm abi. Confusing! --- src/wasm32/ffi.c | 17 ++++++++++++++--- testsuite/lib/libffi.exp | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/wasm32/ffi.c b/src/wasm32/ffi.c index dac2ae625..789131425 100644 --- a/src/wasm32/ffi.c +++ b/src/wasm32/ffi.c @@ -64,6 +64,7 @@ ffi_call (ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue) // via name here... var args = [fn]; var sig = ''; + var sigFloat = Module['usingWasm'] ? 'f' : 'd'; var rtype = HEAPU16[(cif_rtype + 6 /* rtype->type*/ ) >> 1]; //console.error('rtype is', rtype); @@ -79,7 +80,7 @@ ffi_call (ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue) rtype === /* FFI_TYPE_POINTER */ 14) { sig = 'i'; } else if (rtype === /* FFI_TYPE_FLOAT */ 2) { - sig = 'f'; + sig = sigFloat; } else if (rtype === /* FFI_TYPE_DOUBLE */ 3 || rtype === /* FFI_TYPE_LONGDOUBLE */ 4) { sig = 'd'; @@ -107,7 +108,7 @@ ffi_call (ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue) sig += 'i'; } else if (typ === /* FFI_TYPE_FLOAT */ 2) { args.push(HEAPF32[ptr >> 2]); - sig += 'f'; + sig += sigFloat; } else if (typ === /* FFI_TYPE_DOUBLE */ 3 || typ === /* FFI_TYPE_LONGDOUBLE */ 4) { args.push(HEAPF64[ptr >> 3]); sig += 'd'; @@ -146,7 +147,17 @@ ffi_call (ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue) var func = Module['dynCall_' + sig]; //console.error('func is', func); //console.error('args is', args); - var result = func.apply(null, args); + if (func) { + var result = func.apply(null, args); + } else { + console.error('fn is', fn); + console.error('sig is', sig); + console.error('args is', args); + for (var x in Module) { + console.error('-- ' + x); + } + throw new Error('invalid function pointer in ffi_call'); + } //console.error('result is',result); if (rtype === 0) { diff --git a/testsuite/lib/libffi.exp b/testsuite/lib/libffi.exp index c92de6a08..9893ba51e 100644 --- a/testsuite/lib/libffi.exp +++ b/testsuite/lib/libffi.exp @@ -395,7 +395,7 @@ proc check-flags { args } { # compare them to the actual options. if { [string compare [lindex $args 2] "*"] == 0 && [string compare [lindex $args 3] "" ] == 0 } { - set result 1 + set result 1 } else { # The target list might be an effective-target keyword, so replace # the original list with "*-*-*", since we already know it matches.