Skip to content

[WasmFS] Fix standalone wasm printing, newline instead of 0 #16076

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

Merged
merged 5 commits into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ jobs:
- run-tests:
# also add a little select testing for wasm2js in -O3
# also add a little select wasmfs testing
test_targets: "core3 wasm2js3.test_memorygrowth_2 wasmfs.test_hello_world wasmfs.test_hello_world_standalone wasmfs.test_unistd_links*"
test_targets: "core3 wasm2js3.test_memorygrowth_2 wasmfs.test_hello_world wasmfs.test_hello_world_standalone wasmfs.test_unistd_links* wasmfs.test_atexit_standalone"
test-wasm2js1:
executor: bionic
steps:
Expand Down
17 changes: 10 additions & 7 deletions system/lib/standalone/standalone.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,17 @@ imported__wasi_fd_write(__wasi_fd_t fd,
size_t iovs_len,
__wasi_size_t* nwritten);

static void wasi_write(__wasi_fd_t fd, char* buffer) {
struct __wasi_ciovec_t iov;
iov.buf = (uint8_t*)buffer;
iov.buf_len = strlen(buffer) + 1;
// Write a buffer + a newline.
static void wasi_writeln(__wasi_fd_t fd, char* buffer) {
struct __wasi_ciovec_t iovs[2];
iovs[0].buf = (uint8_t*)buffer;
iovs[0].buf_len = strlen(buffer);
iovs[1].buf = (uint8_t*)"\n";
iovs[1].buf_len = 1;
__wasi_size_t nwritten;
imported__wasi_fd_write(fd, &iov, 1, &nwritten);
imported__wasi_fd_write(fd, iovs, 2, &nwritten);
}

void _emscripten_out(char* text) { wasi_write(1, text); }
void _emscripten_out(char* text) { wasi_writeln(1, text); }

void _emscripten_err(char* text) { wasi_write(2, text); }
void _emscripten_err(char* text) { wasi_writeln(2, text); }