-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Closed
Closed
Copy link
Description
Description:
It looks like Module.print
does not always work with -sNODERAWFS
. A simple printf("hello, world!\n");
program works, but when the program actually makes use of the file system (e.g. doing a fopen()
call), Module.print
is ignored and the output is directly written to the terminal. Forcing the full file system with -sFORCE_FILESYSTEM
also reproduces this with a simple printf()
call.
Reproduction:
See commit kleisauke@6dac36a for a test case, with that just run:
$ ./test/runner other.test_noderawfs_override_standard_streams -v
Or if you prefer a standalone example:
$ cat <<EOT >> pre.js
let stdout = '';
let stderr = '';
Module['print'] = function(text) {
stdout += text;
}
Module['printErr'] = function(text) {
stderr += text;
}
Module['postRun'] = function() {
assert(stderr == '', 'stderr should be empty. \\n' +
'stderr: \\n' + stderr);
assert(stdout.startsWith('hello, world!'), 'stdout should start with the famous greeting. \\n' +
'stdout: \\n' + stdout);
}
EOT
$ emcc test/hello_world.c -o hello_world.js -sNODERAWFS -sFORCE_FILESYSTEM --pre-js pre.js
$ node hello_world.js
Expected behavior:
Overriding Module.print
should work and nothing should print to the terminal.
Actual behavior:
hello, world!
/home/kleisauke/hello_world.js:162
throw ex;
^
RuntimeError: Aborted(Assertion failed: stdout should start with the famous greeting.
stdout:
)
at abort (/home/kleisauke/hello_world.js:947:11)
at assert (/home/kleisauke/hello_world.js:478:5)
at Module.postRun (/home/kleisauke/hello_world.js:35:5)
at callRuntimeCallbacks (/home/kleisauke/hello_world.js:1196:26)
at postRun (/home/kleisauke/hello_world.js:796:3)
at doRun (/home/kleisauke/hello_world.js:5324:5)
at run (/home/kleisauke/hello_world.js:5337:5)
at runCaller (/home/kleisauke/hello_world.js:5245:19)
at removeRunDependency (/home/kleisauke/hello_world.js:912:7)
at receiveInstance (/home/kleisauke/hello_world.js:1079:5)
Version of emscripten/emsdk:
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.19 (a5f7b1c9a1c74a830bebedc122d204800ce8dff9)
clang version 16.0.0 (https://github.com/llvm/llvm-project 30171e76f0e5ea8037bc4d1450dd3e12af4d9938)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /home/kleisauke/emsdk/upstream/bin
(but probably older versions also have the same bug)
Downstream issue: kleisauke/wasm-vips#23
atjn
Metadata
Metadata
Assignees
Labels
No labels