Skip to content

Commit 5667b03

Browse files
authored
Support boolean argument type in cwrap fast path (#17511)
1 parent 028241f commit 5667b03

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/library_ccall.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ mergeInto(LibraryManager.library, {
133133
argTypes = argTypes || [];
134134
// When the function takes numbers and returns a number, we can just return
135135
// the original function
136-
var numericArgs = argTypes.every((type) => type === 'number');
136+
var numericArgs = argTypes.every((type) => type === 'number' || type === 'boolean');
137137
var numericRet = returnType !== 'string';
138138
if (numericRet && numericArgs && !opts) {
139139
return getCFunc(ident);

test/test_core.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6990,6 +6990,20 @@ def test_ccall(self):
69906990
if self.maybe_closure():
69916991
self.do_core_test('test_ccall.cpp')
69926992

6993+
def test_ccall_cwrap_fast_path(self):
6994+
self.emcc_args.append('-Wno-return-stack-address')
6995+
self.set_setting('EXPORTED_RUNTIME_METHODS', ['ccall', 'cwrap'])
6996+
self.set_setting('WASM_ASYNC_COMPILATION', 0)
6997+
self.set_setting('ASSERTIONS', 0)
6998+
create_file('post.js', '''
6999+
var printBool = Module['cwrap']('print_bool', null, ['boolean']);
7000+
out(Module['_print_bool'] === printBool); // the function should be the exact raw function in the module rather than a wrapped one
7001+
''')
7002+
self.emcc_args += ['--post-js', 'post.js']
7003+
7004+
self.set_setting('EXPORTED_FUNCTIONS', ['_print_bool'])
7005+
self.do_runf(test_file('core/test_ccall.cpp'), 'true')
7006+
69937007
def test_EXPORTED_RUNTIME_METHODS(self):
69947008
self.set_setting('DEFAULT_LIBRARY_FUNCS_TO_INCLUDE', ['$dynCall'])
69957009
self.do_core_test('EXPORTED_RUNTIME_METHODS.c')

0 commit comments

Comments
 (0)