diff --git a/src/lib/libccall.js b/src/lib/libccall.js index 4d40b8dbf884c..273d34e0de912 100644 --- a/src/lib/libccall.js +++ b/src/lib/libccall.js @@ -146,7 +146,7 @@ addToLibrary({ // When the function takes numbers and returns a number, we can just return // the original function var numericArgs = !argTypes || argTypes.every((type) => type === 'number' || type === 'boolean'); - var numericRet = returnType !== 'string'; + var numericRet = returnType !== 'string' && returnType !== 'boolean'; if (numericRet && numericArgs && !opts) { return getCFunc(ident); } diff --git a/test/test_core.py b/test/test_core.py index 045c5dc1fe477..841f78c0f6b53 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -7097,10 +7097,14 @@ def test_ccall_cwrap_fast_path(self): create_file('post.js', ''' var printBool = Module['cwrap']('print_bool', null, ['boolean']); out(Module['_print_bool'] === printBool); // the function should be the exact raw function in the module rather than a wrapped one + var getBool = Module['cwrap']('get_bool', 'boolean'); + out(Module['_get_bool'] !== getBool); // boolean return must not use the fast path so the result is coerced to a JS boolean + var ret = getBool(); + out([typeof ret, ret].join(',')); ''') - self.set_setting('EXPORTED_FUNCTIONS', ['_print_bool']) - self.do_runf('core/test_ccall.cpp', 'true', cflags=['--post-js=post.js', '-Wno-return-stack-address']) + self.set_setting('EXPORTED_FUNCTIONS', ['_print_bool', '_get_bool']) + self.do_runf('core/test_ccall.cpp', 'true\ntrue\nboolean,true\n', cflags=['--post-js=post.js', '-Wno-return-stack-address']) @no_modularize_instance('ccall is not yet compatible with MODULARIZE=instance') def test_ccall_return_pointer(self):