Skip to content

Commit

Permalink
i64 marshalling; fix for floats in asm.js mode
Browse files Browse the repository at this point in the history
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!
  • Loading branch information
bvibber committed May 27, 2018
1 parent 60776e7 commit 91269cf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
17 changes: 14 additions & 3 deletions src/wasm32/ffi.c
Expand Up @@ -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);
Expand All @@ -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';
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion testsuite/lib/libffi.exp
Expand Up @@ -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.
Expand Down

0 comments on commit 91269cf

Please sign in to comment.