Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ jobs:
executor: bionic
steps:
- run-tests-linux:
test_targets: "wasm64.test_hello_world wasm64l.test_hello_world wasm64l.test_mmap wasm64l.test_unistd_* skip:wasm64l.test_unistd_sysconf wasm64l.test_mmap_file"
test_targets: "wasm64.test_hello_world wasm64.test_ccall wasm64l.test_hello_world wasm64l.test_mmap wasm64l.test_unistd_* skip:wasm64l.test_unistd_sysconf wasm64l.test_mmap_file wasm64l.test_ccall"
test-other:
executor: bionic
steps:
Expand Down
15 changes: 12 additions & 3 deletions src/preamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ function getCFunc(ident) {
function ccall(ident, returnType, argTypes, args, opts) {
// For fast lookup of conversion functions
var toC = {
#if MEMORY64
'pointer': (p) => {{{ to64('p') }}},
#endif
'string': function(str) {
var ret = 0;
if (str !== null && str !== undefined && str !== 0) { // null string
Expand All @@ -111,17 +114,23 @@ function ccall(ident, returnType, argTypes, args, opts) {
ret = stackAlloc(len);
stringToUTF8(str, ret, len);
}
return ret;
return {{{ to64('ret') }}};
},
'array': function(arr) {
var ret = stackAlloc(arr.length);
writeArrayToMemory(arr, ret);
return ret;
return {{{ to64('ret') }}};
}
};

function convertReturnValue(ret) {
if (returnType === 'string') return UTF8ToString(ret);
if (returnType === 'string') {
{{{ from64('ret') }}}
return UTF8ToString(ret);
}
#if MEMORY64
if (returnType === 'pointer') return Number(ret);
#endif
if (returnType === 'boolean') return Boolean(ret);
return ret;
}
Expand Down