DenialAdams opened issue #3303:
I recently updated my local version of wasmtime and noticed that the behavior of
fd_write
seems to have changed. I am supplying two strings to print: a supplied string, and a newline character. This used to print the newline character, which is what I expect, but seems to no longer do so. I bisected the behavior change back to PR #2444, but I didn't see this behavior change explicitly called out.Basically, I'm wondering:
1) Is this new behavior intended, or a bug?
2) If this new behavior is intended, what am I doing wrong in the example program?Thanks for reading!
Test Case
(module (import "wasi_unstable" "fd_write" (func $fd_write (param i32 i32 i32 i32) (result i32))) (memory 1) (export "memory" (memory 0)) (data 0 (i32.const 16) "\n") (data 0 (i32.const 18) "world on a new line!") (data 0 (i32.const 47) "Hello,") (global $mem_address (mut i32) (i32.const 0)) (func $print (param i32) (param i32) (i32.store (i32.const 0) (local.get 0)) (i32.store (i32.const 4) (local.get 1)) (i32.store (i32.const 8) (i32.const 16)) (i32.store (i32.const 12) (i32.const 1)) (call $fd_write (i32.const 1) (i32.const 0) (i32.const 2) (i32.const 0)) drop ) (func $main (export "_start") i32.const 47 i32.const 6 call $print i32.const 18 i32.const 20 call $print ) )
Steps to Reproduce
1)
wasmtime repro.wast
(contents above)
2) Observe that the newline is not printedExpected Results
Hello, world on a new line!
Actual Results
Hello,world on a new line!
Versions and Environment
I first observed this behavior on wasmtime 0.29.0. I bisected the issue back to PR #2444, which seems to be where the behavior changed.
Operating system: Windows 10
Architecture: x86
DenialAdams labeled issue #3303:
I recently updated my local version of wasmtime and noticed that the behavior of
fd_write
seems to have changed. I am supplying two strings to print: a supplied string, and a newline character. This used to print the newline character, which is what I expect, but seems to no longer do so. I bisected the behavior change back to PR #2444, but I didn't see this behavior change explicitly called out.Basically, I'm wondering:
1) Is this new behavior intended, or a bug?
2) If this new behavior is intended, what am I doing wrong in the example program?Thanks for reading!
Test Case
(module (import "wasi_unstable" "fd_write" (func $fd_write (param i32 i32 i32 i32) (result i32))) (memory 1) (export "memory" (memory 0)) (data 0 (i32.const 16) "\n") (data 0 (i32.const 18) "world on a new line!") (data 0 (i32.const 47) "Hello,") (global $mem_address (mut i32) (i32.const 0)) (func $print (param i32) (param i32) (i32.store (i32.const 0) (local.get 0)) (i32.store (i32.const 4) (local.get 1)) (i32.store (i32.const 8) (i32.const 16)) (i32.store (i32.const 12) (i32.const 1)) (call $fd_write (i32.const 1) (i32.const 0) (i32.const 2) (i32.const 0)) drop ) (func $main (export "_start") i32.const 47 i32.const 6 call $print i32.const 18 i32.const 20 call $print ) )
Steps to Reproduce
1)
wasmtime repro.wast
(contents above)
2) Observe that the newline is not printedExpected Results
Hello, world on a new line!
Actual Results
Hello,world on a new line!
Versions and Environment
I first observed this behavior on wasmtime 0.29.0. I bisected the issue back to PR #2444, which seems to be where the behavior changed.
Operating system: Windows 10
Architecture: x86
DenialAdams edited issue #3303:
I recently updated my local version of wasmtime and noticed that the behavior of
fd_write
seems to have changed. I am supplying two strings to print: a supplied string, and a newline character. This used to print the newline character, which is what I expect, but seems to no longer do so. I bisected the behavior change back to PR #2444, but I didn't see this behavior change explicitly called out.Basically, I'm wondering:
1) Is this new behavior intended, or a bug?
2) If this new behavior is intended, what am I doing wrong in the example program?Thanks for reading!
Test Case
(module (import "wasi_unstable" "fd_write" (func $fd_write (param i32 i32 i32 i32) (result i32))) (memory 1) (export "memory" (memory 0)) (data 0 (i32.const 16) "\n") (data 0 (i32.const 18) "world on a new line!") (data 0 (i32.const 47) "Hello,") (func $print (param i32) (param i32) (i32.store (i32.const 0) (local.get 0)) (i32.store (i32.const 4) (local.get 1)) (i32.store (i32.const 8) (i32.const 16)) (i32.store (i32.const 12) (i32.const 1)) (call $fd_write (i32.const 1) (i32.const 0) (i32.const 2) (i32.const 0)) drop ) (func $main (export "_start") i32.const 47 i32.const 6 call $print i32.const 18 i32.const 20 call $print ) )
Steps to Reproduce
1)
wasmtime repro.wast
(contents above)
2) Observe that the newline is not printedExpected Results
Hello, world on a new line!
Actual Results
Hello,world on a new line!
Versions and Environment
I first observed this behavior on wasmtime 0.29.0. I bisected the issue back to PR #2444, which seems to be where the behavior changed.
Operating system: Windows 10
Architecture: x86
bjorn3 commented on issue #3303:
fd_write
returns the amount of bytes written. You have to call it in a loop until all bytes are written. This matches the posixwrite
syscall. From the man page of thewrite
syscall:The number of bytes written may be less than count if, for example, there is insufficient space on the underlying physical medium, or the RLIMIT_FSIZE resource limit is encountered (see setrlimit(2)), or the call was interrupted by a signal handler after having written less than count bytes. (See also pipe(7).)
Higher level api's generally do this loop for you.
DenialAdams commented on issue #3303:
fd_write
returns the amount of bytes written. You have to call it in a loop until all bytes are written. This matches the posixwrite
syscall. From the man page of thewrite
syscall:The number of bytes written may be less than count if, for example, there is insufficient space on the underlying physical medium, or the RLIMIT_FSIZE resource limit is encountered (see setrlimit(2)), or the call was interrupted by a signal handler after having written less than count bytes. (See also pipe(7).)
Higher level api's generally do this loop for you.
Thank you, this makes a lot of sense! Sorry for the false report
DenialAdams closed issue #3303:
I recently updated my local version of wasmtime and noticed that the behavior of
fd_write
seems to have changed. I am supplying two strings to print: a supplied string, and a newline character. This used to print the newline character, which is what I expect, but seems to no longer do so. I bisected the behavior change back to PR #2444, but I didn't see this behavior change explicitly called out.Basically, I'm wondering:
1) Is this new behavior intended, or a bug?
2) If this new behavior is intended, what am I doing wrong in the example program?Thanks for reading!
Test Case
(module (import "wasi_unstable" "fd_write" (func $fd_write (param i32 i32 i32 i32) (result i32))) (memory 1) (export "memory" (memory 0)) (data 0 (i32.const 16) "\n") (data 0 (i32.const 18) "world on a new line!") (data 0 (i32.const 47) "Hello,") (func $print (param i32) (param i32) (i32.store (i32.const 0) (local.get 0)) (i32.store (i32.const 4) (local.get 1)) (i32.store (i32.const 8) (i32.const 16)) (i32.store (i32.const 12) (i32.const 1)) (call $fd_write (i32.const 1) (i32.const 0) (i32.const 2) (i32.const 0)) drop ) (func $main (export "_start") i32.const 47 i32.const 6 call $print i32.const 18 i32.const 20 call $print ) )
Steps to Reproduce
1)
wasmtime repro.wast
(contents above)
2) Observe that the newline is not printedExpected Results
Hello, world on a new line!
Actual Results
Hello,world on a new line!
Versions and Environment
I first observed this behavior on wasmtime 0.29.0. I bisected the issue back to PR #2444, which seems to be where the behavior changed.
Operating system: Windows 10
Architecture: x86
Last updated: Nov 22 2024 at 17:03 UTC