Skip to content

-s MAIN_MODULE=1 + upstream + function pointer calls using i64 => TypeError: cannot pass i64 to or from JS #9562

@gl84

Description

@gl84

Hi everybody! I'm starting to learn emscripten and ran in the following problem when reading from a preloaded file (input.txt)

#include <cstdio>

int main() {
    FILE* file_ = std::fopen("input.txt","rb");
    printf("file pointer %p\n",(void*)file_);
    if (file_) {
        std::fseek(file_, 0l, SEEK_END);
        std::fclose(file_);
    }
    return 0;
}

when using
emcc main.cpp -g -s MAIN_MODULE=1 --preload-file input.txt -o main.html -s EXPORTED_FUNCTIONS=['_main']

on the latest upstream version (atm 1.38.46 (commit 41adfea)).

The runtime error on fseek in firefox is

exception thrown: TypeError: cannot pass i64 to or from JS,@http://0.0.0.0:8002/main.js line 1015 > WebAssembly.Module:wasm-function[0]:0x0
__fseeko_unlocked@http://0.0.0.0:8002/main.js line 2316 > WebAssembly.instantiate:wasm-function[1072]:0x33216
__fseeko@http://0.0.0.0:8002/main.js line 2316 > WebAssembly.instantiate:wasm-function[1073]:0x3324f
fseek@http://0.0.0.0:8002/main.js line 2316 > WebAssembly.instantiate:wasm-function[1074]:0x3327f
__original_main@http://0.0.0.0:8002/main.js line 2316 > WebAssembly.instantiate:wasm-function[163]:0x6dec
main@http://0.0.0.0:8002/main.js line 2316 > WebAssembly.instantiate:wasm-function[164]:0x6e19
Module._main@http://0.0.0.0:8002/main.js:40295:32
callMain@http://0.0.0.0:8002/main.js:49234:22
doRun@http://0.0.0.0:8002/main.js:49294:23
run/<@http://0.0.0.0:8002/main.js:49305:7

In Chromium I get a similar TypeError...

Compiling with -s MAIN_MODULE=0
emcc main.cpp -g -s MAIN_MODULE=0 --preload-file input.txt -o main.html -s EXPORTED_FUNCTIONS=['_main']
works as expected.

Anybody any ideas?

Thanks!

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions