Skip to content

Commit 1488c44

Browse files
authored
Fix legalization of i64 return values in JS.legalize_sig. (#9855)
#9810 mostly fixed i64 pointers in MAIN_MODULE, but it turns out that a corner case was a function that is illegal only due to its return value. fixes #9850
1 parent e23b5c4 commit 1488c44

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

tests/test_core.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3896,12 +3896,19 @@ def test_dylink_i64_b(self):
38963896
int64_t testAdd(int64_t a) {
38973897
return a + 1;
38983898
}
3899+
int64_t testAddB(int a) {
3900+
return a + 1;
3901+
}
38993902
typedef int64_t (*testAddHandler)(int64_t);
39003903
testAddHandler h = &testAdd;
3904+
typedef int64_t (*testAddBHandler)(int);
3905+
testAddBHandler hb = &testAddB;
39013906
int main() {
39023907
printf("other says %lld.\n", sidey());
39033908
int64_t r = h(42);
39043909
printf("my fp says: %lld.\n", r);
3910+
int64_t rb = hb(42);
3911+
printf("my second fp says: %lld.\n", r);
39053912
}
39063913
''', '''
39073914
#include <stdint.h>
@@ -3911,7 +3918,7 @@ def test_dylink_i64_b(self):
39113918
x = 18 - x;
39123919
return x;
39133920
}
3914-
''', 'other says -1311768467750121224.\nmy fp says: 43.')
3921+
''', 'other says -1311768467750121224.\nmy fp says: 43.\nmy second fp says: 43.')
39153922

39163923
@needs_dlfcn
39173924
def test_dylink_class(self):

tools/shared.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3015,15 +3015,19 @@ def make_coercion(value, sig, settings=None, ffi_arg=False, ffi_result=False, co
30153015

30163016
@staticmethod
30173017
def legalize_sig(sig):
3018-
ret = [sig[0]]
3018+
legal = [sig[0]]
3019+
# a return of i64 is legalized into an i32 (and the high bits are
3020+
# accessible on the side through getTempRet0).
3021+
if legal[0] == 'j':
3022+
legal[0] = 'i'
3023+
# a parameter of i64 is legalized into i32, i32
30193024
for s in sig[1:]:
30203025
if s != 'j':
3021-
ret.append(s)
3026+
legal.append(s)
30223027
else:
3023-
# an i64 is legalized into i32, i32
3024-
ret.append('i')
3025-
ret.append('i')
3026-
return ''.join(ret)
3028+
legal.append('i')
3029+
legal.append('i')
3030+
return ''.join(legal)
30273031

30283032
@staticmethod
30293033
def is_legal_sig(sig):

0 commit comments

Comments
 (0)