From 2308587a85de571844e71e574fcc63c7955d6012 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 2 May 2014 13:48:11 -0700 Subject: [PATCH] handle floats in jsCall properly; fixes asm2f.test_embind_2 --- emscripten.py | 3 ++- tools/shared.py | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/emscripten.py b/emscripten.py index 835b1ec97..bf55ee43f 100755 --- a/emscripten.py +++ b/emscripten.py @@ -1076,8 +1076,9 @@ def emscript_fast(infile, settings, outfile, libraries=[], compiler_engine=None, } ''' % (sig, ',' if len(sig) > 1 else '', args, arg_coercions, ret)) + ffi_args = ','.join([shared.JS.make_coercion('a' + str(i), sig[i], settings, ffi_arg=True) for i in range(1, len(sig))]) for i in range(settings['RESERVED_FUNCTION_POINTERS']): - jsret = ('return ' if sig[0] != 'v' else '') + shared.JS.make_coercion('jsCall(%d%s%s)' % (i, ',' if coerced_args else '', coerced_args), sig[0], settings) + jsret = ('return ' if sig[0] != 'v' else '') + shared.JS.make_coercion('jsCall(%d%s%s)' % (i, ',' if ffi_args else '', ffi_args), sig[0], settings, ffi_result=True) function_tables_impls.append(''' function jsCall_%s_%s(%s) { %s diff --git a/tools/shared.py b/tools/shared.py index 82bdd98b9..826baa832 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -1650,12 +1650,17 @@ class JS: return '+0' @staticmethod - def make_coercion(value, sig, settings=None): + def make_coercion(value, sig, settings=None, ffi_arg=False, ffi_result=False): settings = settings or Settings if sig == 'i': return value + '|0' elif sig == 'f' and settings.get('PRECISE_F32'): - return 'Math_fround(' + value + ')' + if ffi_arg: + return '+Math_fround(' + value + ')' + elif ffi_result: + return 'Math_fround(+(' + value + '))' + else: + return 'Math_fround(' + value + ')' elif sig == 'd' or sig == 'f': return '+' + value else: