emscripten-core / emscripten-core/emscripten
WebIDL Binder does not support the full range of values for unsigned integers
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
Is it possible to opt-in to representing an unsigned int using HEAPU32 with the webidl binder?
When using the webidl binder and binding an attribute or function that uses `unsigned int`, the max unsigned int value `0xffffffff` is returned as `-1` in javascript.
It appears this is because unsigned integers are treated as signed integers.
This behaviour can be seen in the webidl binder tests: https://github.com/emscripten-core/emscripten/blob/bb220d85c65bace41918d4ba5b84e264cb88de4a/test/webidl/test_ALL.out#L85
Looking at some past commits, it appears this behaviour is intentional for performance reasons: https://github.com/emscripten-core/emscripten/commit/f1c42f42fdb10ece326ebdae985da017ceaab803
> Looking now, it worked fine except for one HEAPU32 which should be HEAP32 (for performance; there is never a point to using the unsigned 32 bit heap unless you really really must).
I am using the webidl binder to create bindings for a library which uses `0xffffffff` as a constant with a special meaning. Right now to work around this issue, in javascript I check for the value `-1`. This is a fine workaround for my case but feels like a hack, and would stop working if I needed to check for other values in the upper unsupported range.
---
**Version of emscripten/emsdk:**
```
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.61 (67fa4c16496b157a7fc3377afd69ee0445e8a6e3)
clang version 19.0.0git (https:/github.com/llvm/llvm-project 7cfffe74eeb68fbb3fb9706ac7071f8caeeb6520)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /Users/isaacmason/Development/emsdk/upstream/bin
```
Contributor guide
Assessment
This issue has not been assessed yet.