Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MEMORY64 and internal JS functions not working with BigInt #23486

Closed
cwoffenden opened this issue Jan 24, 2025 · 3 comments
Closed

MEMORY64 and internal JS functions not working with BigInt #23486

cwoffenden opened this issue Jan 24, 2025 · 3 comments
Labels

Comments

@cwoffenden
Copy link
Contributor

This is with the latest Emscripten 4.0.1.

Is there a plan for JS functions like stackAlloc and UTF8ToString that expect or return Numbers and not a BigInt.

As an example, passing a 64-bit pointer to UTF8ToString fails the assert:

$UTF8ToString: (ptr, maxBytesToRead) => {

It can be fudged for 4GB address with something like:

ptr = Number(BigInt.asUintN(32, url));

I came across this and others adding MEMORY64 support to audio worklets (currently a bunch of workarounds but it's running and playing audio with a 4GB heap). Is there a plan for these internal functions?

@cwoffenden
Copy link
Contributor Author

cwoffenden commented Jan 24, 2025

A small repro case is:

#include <emscripten/em_js.h>

EM_JS(void, stringTest, (const char* str), {
    console.log(UTF8ToString(str));
});

int main() {
    stringTest("Test");
}

Compile with:

emcc -sASSERTIONS=2 -sMEMORY64 -sEXPORTED_RUNTIME_METHODS=UTF8ToString string_test.c

The error given is:

Uncaught RuntimeError: Aborted(Assertion failed: UTF8ToString expects a number (got bigint))

@brendandahl
Copy link
Collaborator

EM_JS does not currently automatically convert BigInts to numbers (like library js functions). There's a similar issue filed about this for the return values #16975.

@brendandahl
Copy link
Collaborator

The better issue to link to is #23325. Which has been marked as a duplicate of the above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants