Skip to content

Return streams from getStdOut, getStdIn, and getStdErr #3823

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

Open
jayschwa opened this issue Dec 1, 2019 · 1 comment
Open

Return streams from getStdOut, getStdIn, and getStdErr #3823

jayschwa opened this issue Dec 1, 2019 · 1 comment
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@jayschwa
Copy link
Contributor

jayschwa commented Dec 1, 2019

In the Zig codebase (and in my own, what little that is), almost every call to these functions immediately performs [in|out]Stream().stream. If getStdOut and friends just returned the streams directly, that would probably DRY a lot of code. Perhaps getStdOutFile could be added for less common use-cases.

Exceptions I found in Zig codebase:

  • stdout_file.write() in a couple places, but OutStream has write too.
  • cat_file in a test takes fs.Files, but it looks like it's implementation is only concerned with a read and write method on its arguments, and would probably not be hard to change.
@andrewrk andrewrk added proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. standard library This issue involves writing Zig code for the standard library. labels Dec 1, 2019
@andrewrk andrewrk added this to the 0.6.0 milestone Dec 1, 2019
@andrewrk
Copy link
Member

andrewrk commented Dec 1, 2019

If we provided global storage for stdio streams, it should probably be a buffered one, with a mutex protecting it. And then we'd probably want some hook to detect unflushed data after main(). This would match stdin, stdout, stderr from libc. My only concern with this is that an application generally should be in control of its own standard I/O streams, and I don't want this to be an invitation to libraries to start dumping garbage into stdio. That's what #2586 is for.

And then the buffering and the mutex might not actually be necessary, depending on how the application is structured. The code to detect unflushed data after main() would be nonzero cost, and nontrivial to figure out how to do it in all situations, e.g. a static library that does not link libc. The boilerplate is annoying, but it makes it clear that it's up to the application how it wants to deal with stdio.

@andrewrk andrewrk modified the milestones: 0.6.0, 0.7.0 Mar 4, 2020
@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Oct 27, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 May 19, 2021
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 Nov 23, 2021
@andrewrk andrewrk modified the milestones: 0.10.0, 0.11.0 Apr 16, 2022
@andrewrk andrewrk modified the milestones: 0.11.0, 0.12.0 Apr 9, 2023
@andrewrk andrewrk modified the milestones: 0.13.0, 0.12.0 Jul 9, 2023
@andrewrk andrewrk modified the milestones: 0.14.0, 0.16.0 Feb 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

No branches or pull requests

2 participants