Skip to content

Commit f0cc3d0

Browse files
authored
[embind] Fix signature for 64 bit types. (#22930)
Long longs were incorrectly being mapped to int for the signature. Fixes #22928
1 parent 4a4e165 commit f0cc3d0

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

system/include/emscripten/bind.h

+9
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,13 @@ struct SignatureCode<size_t> {
607607
}
608608
};
609609

610+
template<>
611+
struct SignatureCode<long long> {
612+
static constexpr char get() {
613+
return 'j';
614+
}
615+
};
616+
610617
#ifdef __wasm64__
611618
template<>
612619
struct SignatureCode<long> {
@@ -629,6 +636,8 @@ template<> struct SignatureTranslator<double> { using type = double; };
629636
#ifdef __wasm64__
630637
template<> struct SignatureTranslator<long> { using type = long; };
631638
#endif
639+
template<> struct SignatureTranslator<long long> { using type = long long; };
640+
template<> struct SignatureTranslator<unsigned long long> { using type = long long; };
632641
template<> struct SignatureTranslator<size_t> { using type = size_t; };
633642
template<typename PtrType>
634643
struct SignatureTranslator<PtrType*> { using type = void*; };

test/embind/test_embind_long_long.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <cstdint>
2+
#include <emscripten.h>
3+
#include <emscripten/bind.h>
4+
5+
int64_t getInt64() {
6+
return 1000000000000;
7+
}
8+
9+
uint64_t getUint64() {
10+
return -1000000000000;
11+
}
12+
13+
int main() {
14+
EM_ASM(
15+
console.log(Module.getInt64());
16+
console.log(Module.getUint64());
17+
);
18+
}
19+
20+
EMSCRIPTEN_BINDINGS(my_module) {
21+
emscripten::function("getInt64", &getInt64);
22+
emscripten::function("getUint64", &getUint64);
23+
}

test/test_other.py

+8
Original file line numberDiff line numberDiff line change
@@ -3320,6 +3320,14 @@ def test_embind_return_value_policy(self):
33203320

33213321
self.do_runf('embind/test_return_value_policy.cpp')
33223322

3323+
@parameterized({
3324+
'': [[]],
3325+
'asyncify': [['-sASYNCIFY=1']]
3326+
})
3327+
def test_embind_long_long(self, args):
3328+
self.do_runf('embind/test_embind_long_long.cpp', '1000000000000n\n-1000000000000n',
3329+
emcc_args=['-lembind', '-sWASM_BIGINT'] + args)
3330+
33233331
@requires_jspi
33243332
@parameterized({
33253333
'': [['-sJSPI_EXPORTS=async*']],

0 commit comments

Comments
 (0)