-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
uucore/echo:handle ControlFlow result #7881
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
uucore/echo:handle ControlFlow result #7881
Conversation
This commit explicitly handles the result of the `write` function and allows an early stop when a `ControlFlow::Break` is received. It seems that currently only writing `EscapedChar::End` will trigger a break. In all other cases, `ControlFlow::Continue` is returned.
This commit analyzes the return value of the `write` function and stops the echo when a break is received. It allows: - simplifying the function's logic. Now, we don't rely on the item type and only analyze the return value. - avoiding compiler warnings about the unused `ControlFlow` result (nightly only). Since a break can only be triggered by `EscapedChar::End`, the old and new versions should be equivalent.
GNU testsuite comparison:
|
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.
Looks good, thanks! I confirmed that GNU echo
indeed has this behaviour. Could you add a test for it?
@tertsdiepraam Thanks. I’ve added a test for the Ctrl-C sequence |
GNU testsuite comparison:
|
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.
Great! Thanks!
…ments uucore/echo:handle ControlFlow result
About
Issue 7736
Hello Everyone,
This PR introduces analysis of returned
ControlFlow
values, helping to eliminate compiler warnings about unused return values on nightly toolchains. It also adds the ability to exit early when encounteringEscapedCharacter::End
, which seems like the correct behavior in that case. [1]While working on this, I noticed that the
printf
utility already relies onControlFlow
results. So this change also helps unify the approaches and code betweenprintf
andecho
.Please note: these are initial changes, intended for review, discussion, and testing on real examples. Any feedback or observations are highly appreciated.
Thank you
[1] Output of GNU Coreutils (9.7) and uutils/coreutils
GNU coreutils
uutils/coreutils