-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Ensure that stdin/stdout/stderr are not mapped 1:1 under NODERAWFS #18163
Conversation
Is this really the behaviour we want though? Doesn't NODERAWFS imply that you do want write directly the stdin/stdout of the node process? |
Good point, it looks like this was included in the initial implementation (see #6008), so perhaps there should be some discussion about it first. Writing directly to $ node -v
v14.18.2
$ node -e "console.warn('hello, world\!')" > /dev/null
hello, world!
$ emcc test/module/test_stdin.c -sNODERAWFS -sFORCE_FILESYSTEM -sEXIT_RUNTIME
$ echo 'hello, world!' | node a.out.js
hello, world!
eof This PR also unifies its behavior with the other file systems (e.g. WasmFS also uses |
19a437d
to
a369c4f
Compare
I've marked this PR as ready for review. I think issue #16755 should be addressed separately and not block this one. |
Previously, when linking with -sNODERAWFS, the stdin, stdout and stderr streams were respectively attached to file descriptors 0, 1 and 2 of the running Node process. This implicitly means that overriding the print, printErr, stdin, stdout and stderr handlers on the incoming module wasn't possible. This commit ensures that stdin/stdout/stderr uses the library_tty.js implementation for its printing, which leverages the console object, whenever the above handlers weren't overriden. This matches what is done when filesystem support isn't included. Resolves: emscripten-core#17688. Resolves: emscripten-core#22264.
4cb3b78
to
f927a00
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Landing as is since the browser test failures are unrelated (and fixed on main already)
It looks like this is breaking on windows sadly. I guess we don't have any noderawfs tests tagged as On the emscripten-releases roller I'm seeing lots of failures: https://logs.chromium.org/logs/emscripten-releases/buildbucket/cr-buildbucket/8740021917817007009/+/u/Emscripten_testsuite__other_/stdout The all looks like this:
Which means I think the issue is with createStandardStreams, which is no longer overridden here: Lines 1431 to 1434 in bd8b894
|
I think we should perhaps revert, and at the same time add |
PR #22372 addresses the issue by preventing that Line 1033 in cd097fb
$ node -p "require('node:path/win32').normalize('/dev/stdin')"
\dev\stdin
$ node -p "require('node:path/posix').normalize('/dev/stdin')"
/dev/stdin This ensures that the split here works as intended: Lines 194 to 195 in cd097fb
|
Avoids mangling `C:/tmp` to `C:\tmp`. Should be safe, the underlying Windows API can accept either the backslash or slash to separate directory and file components of a path. See: https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file Ensures `NODERAWFS` compatibility on Windows that was regressed since emscripten-core#18163.
Without this the decorated function doesn't mirror properties of the underlying tests, which was breaking things like `@crossplatform`. See emscripten-core#18163
Avoids mangling `C:/tmp` to `C:\tmp`. Should be safe, the underlying Windows API can accept either the backslash or slash to separate directory and file components of a path. See: https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file Ensures `NODERAWFS` compatibility on Windows that was regressed since #18163.
Without this the decorated function doesn't mirror properties of the underlying tests, which was breaking things like `@crossplatform`. See emscripten-core#18163
Without this the decorated function doesn't mirror properties of the underlying tests, which was breaking things like `@crossplatform`. See emscripten-core#18163
This is also breaking the |
With a very small reproducer like
You can see differences in outputting 0-valued bytes, and when the counter rolls from 0x7f to 0x80, i.e. out of the ASCII range. So presumably because stdout is open in text mode, there may be a difference in how that gets handled, relative to what the test expects (and it's possible that it's relying on something it shouldn't). But I would still like to understand what's happening here, e.g. is this a behavior difference in the emscripten runtime or node, etc. |
Fixes a regression that occurred since emscripten-core#18163.
@dschuff Sorry for the breakage, looks like
Hmm, I was also able to reproduce this without emscripten/src/library_strings.js Line 81 in eb4d36d
|
FWIW, here's a standalone reproducer for that ASCII issue: Expected behavior: $ curl -LO https://github.com/llvm/llvm-test-suite/raw/main/SingleSource/Benchmarks/Misc-C++/Large/ray.cpp
$ em++ -O3 -sEXIT_RUNTIME ray.cpp -o ray.js
$ node ray.js > x.ppm
$ sha256sum x.ppm
cd6fa6fa75b4ba29077f7e4e531b96f17ff0b82f3c70df526c36f748d6a38c5c x.ppm
$ vips copy x.ppm x.png Current/actual behavior: $ em++ -O3 -sEXIT_RUNTIME ray.cpp -o ray.js
$ node ray.js > x.ppm
$ sha256sum x.ppm
acaa1db08ee30dafda03b41c77466b1435fe8ffdd4d88e5a5876e87dff126f58 x.ppm
$ vips copy x.ppm x.png
VipsImage: memory area too small --- should be 262144 bytes, you passed 79485 |
Fixes a regression that occurred since emscripten-core#18163.
... I just revised PR #22393 to avoid Of course, the bug still occurs without |
This reverts commit c614fa5. --- Here's a standalone reproducer: Before: ```console $ curl -LO https://github.com/llvm/llvm-test-suite/raw/main/SingleSource/Benchmarks/Misc-C++/Large/ray.cpp $ em++ -O3 -sEXIT_RUNTIME -sNODERAWFS ray.cpp -o ray.js $ node ray.js > x.ppm $ sha256sum x.ppm acaa1db08ee30dafda03b41c77466b1435fe8ffdd4d88e5a5876e87dff126f58 x.ppm $ vips copy x.ppm x.png VipsImage: memory area too small --- should be 262144 bytes, you passed 79485 ``` After: ```console $ em++ -O3 -sEXIT_RUNTIME -sNODERAWFS ray.cpp -o ray.js $ node ray.js > x.ppm $ sha256sum x.ppm cd6fa6fa75b4ba29077f7e4e531b96f17ff0b82f3c70df526c36f748d6a38c5c x.ppm $ vips copy x.ppm x.png ``` <details> <summary>x.png</summary> ![x](https://github.com/user-attachments/assets/832af0bc-17af-4919-9c3c-72f0683079b8) </details>
Previously, when linking with -sNODERAWFS, the stdin, stdout and stderr streams were respectively attached to file descriptors 0, 1 and 2 of the running Node process.
emscripten/src/library_noderawfs.js
Lines 47 to 52 in 52e3805
This implicitly means that overriding the print, printErr, stdin, stdout and stderr handlers on the incoming module wasn't possible.
emscripten/src/shell.js
Lines 431 to 432 in 52e3805
emscripten/src/library_fs.js
Lines 1496 to 1499 in 52e3805
This commit ensures that stdin/stdout/stderr uses the library_tty.js implementation for its printing, which leverages the console object, whenever the above handlers weren't overriden. This matches what is done when filesystem support isn't included.
Resolves: #17688.
Resolves: #22264.