Skip to content

Comments

paste: avoid unbounded buffering for single input#11060

Open
mattsu2020 wants to merge 4 commits intouutils:mainfrom
mattsu2020:paste_11024_pr_a
Open

paste: avoid unbounded buffering for single input#11060
mattsu2020 wants to merge 4 commits intouutils:mainfrom
mattsu2020:paste_11024_pr_a

Conversation

@mattsu2020
Copy link
Contributor

@mattsu2020 mattsu2020 commented Feb 23, 2026

Summary

Notes

  • this PR intentionally excludes the EINTR-related follow-up commits

Test

  • cargo test --test tests test_paste:: -- --nocapture

- Refactored paste() to handle single input sources directly without buffering
- Added paste_single_input_source() function for efficient streaming
- Implemented InputSource::read() method for unified reading interface
- Added tests for edge cases with /dev/zero and broken pipes
- Improved performance by avoiding unnecessary line buffering for single inputs
@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/tail/inotify-dir-recreate (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/pr/bounded-memory (passes in this run but fails in the 'main' branch)

The test for handling broken pipes with /dev/zero was incorrectly expecting success. Updated to use `fails_silently()` to properly handle the expected failure when writing to a broken pipe.
Reordered the imports in paste.rs to group standard library imports together and maintain consistent ordering across the codebase. This improves code readability and follows the project's import organization conventions.
@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/tail/inotify-dir-recreate (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tail/symlink (fails in this run but passes in the 'main' branch)

Ok(())
}

fn paste_single_input_source(mut input_source: InputSource, line_ending_byte: u8) -> UResult<()> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fn paste_single_input_source(mut input_source: InputSource, line_ending_byte: u8) -> UResult<()> {
fn write_single_input_source(writer: &mut impl Write, mut input_source: InputSource, line_ending_byte: u8) -> UResult<()> {

then we can do let mut stdout = stdout().lock() once?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks nicer.

Extracted the single input source handling logic from `paste_single_input_source` into a new `write_single_input_source` function that accepts a writer parameter. This allows the function to be more flexible and reusable, while also enabling the main `paste` function to maintain a single stdout lock for better performance. The change maintains the same functionality while improving code organization and performance.
@github-actions
Copy link

GNU testsuite comparison:

GNU test failed: tests/date/date-locale-hour. tests/date/date-locale-hour is passing on 'main'. Maybe you have to rebase?
Skip an intermittent issue tests/pr/bounded-memory (fails in this run but passes in the 'main' branch)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants