Skip to content

Commit 7a55a1d

Browse files
authored
[wasm64] Fix ccall for MEMORY64 (#16930)
Split out from #16922
1 parent d864146 commit 7a55a1d

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ jobs:
381381
executor: bionic
382382
steps:
383383
- run-tests-linux:
384-
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"
384+
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"
385385
test-other:
386386
executor: bionic
387387
steps:

src/preamble.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ function getCFunc(ident) {
103103
function ccall(ident, returnType, argTypes, args, opts) {
104104
// For fast lookup of conversion functions
105105
var toC = {
106+
#if MEMORY64
107+
'pointer': (p) => {{{ to64('p') }}},
108+
#endif
106109
'string': function(str) {
107110
var ret = 0;
108111
if (str !== null && str !== undefined && str !== 0) { // null string
@@ -111,17 +114,23 @@ function ccall(ident, returnType, argTypes, args, opts) {
111114
ret = stackAlloc(len);
112115
stringToUTF8(str, ret, len);
113116
}
114-
return ret;
117+
return {{{ to64('ret') }}};
115118
},
116119
'array': function(arr) {
117120
var ret = stackAlloc(arr.length);
118121
writeArrayToMemory(arr, ret);
119-
return ret;
122+
return {{{ to64('ret') }}};
120123
}
121124
};
122125

123126
function convertReturnValue(ret) {
124-
if (returnType === 'string') return UTF8ToString(ret);
127+
if (returnType === 'string') {
128+
{{{ from64('ret') }}}
129+
return UTF8ToString(ret);
130+
}
131+
#if MEMORY64
132+
if (returnType === 'pointer') return Number(ret);
133+
#endif
125134
if (returnType === 'boolean') return Boolean(ret);
126135
return ret;
127136
}

0 commit comments

Comments
 (0)