-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Amend RFC 517: Add material for stdio #899
Conversation
Expand the section on stdin, stdout, and stderr while also adding a new section explaining the fate of the current print-related functions.
@@ -72,7 +73,6 @@ follow-up PRs against this RFC. | |||
* [TCP] | |||
* [UDP] | |||
* [Addresses] | |||
* [std::net] (stub) |
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.
Oops?
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.
I forgot to delete this when the std::net
RFC landed.
The |
Then they have to allocate memory first which is not acceptable. |
Maybe a new macro for that purpose then (e.g. |
So just |
Yeah, not sure we want to write this for each |
I think the move we made in Personally, I would suggest the following variant of the design for consistency:
Just to clarify why this kind of global design is useful, consider some alternatives:
On the other hand, of course it's important to provide all of the I don't think the RFC says where these constructors should live, but I would propose |
Also add back text for `foo_raw` and details.
I like the sound of all this. I've pushed an update which includes:
As @mahkoh mentioned these are fundamentally unable to prevent many calls to the |
BTW, I strongly suggest we land some preliminary version of this ASAP, since we need to start getting feedback on the new APIs. We can and should be very clear that none of it will be stabilized until the RFC is finalized, of course. |
I have created a PR for this RFC, but I would like to stress that it is not final at all. We need to implement these APIs to allow crates to migrate to |
Don't forget the |
This API looks really like a custom implementation of a generic file-descriptor/handle type (e.g. |
We're currently leaving that for a future RFC as it's only somewhat tangentially related to the stdio bits of this RFC.
I agree! We're just not ready at this time to commit to that kind of an API. |
More #ifdef hell for code that wants to be portable. At this point I would be content with |
|
I've pushed an update which recommends that the raw stdio primitives are not implemented or stabilized at this time. Otherwise the interface remains the same and continues to be somewhat high level. It's quite similar to what's implemented today, but a few tweaks will be necessary for the implementation. The update also revises that @mahkoh I agree there are some interesting questions around |
``` | ||
|
||
* `stdin` - returns a handle to a **globally shared** standard input of | ||
the process which is buffered as well. All operations on this handle will |
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.
Hm, it seems this 'all' isn't quite true? (Or is it referring to the internals too.)
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.
How so? (I may be missing something)
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.
There are operations other than lock
on Stdin
, meaning a user can do things with it without locking. (I'm now inclined to believe I just misread: and this sentence is saying those operations would just call lock
internally.)
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.
Ah right, yes this is just saying that all methods will call lock
internally
Hm, the windows behaviour seems to be very "fancy" to me, less minimal than we might hope for |
I agree, I'm not super comfortable about this either. I've been considering it a hard constraint though that the stdio handles must implement |
This still doesn't address writing to stderr. Having to create your own thread local variable just to do some error reporting is annoying. |
Can you clarify where this thread local variable is coming from? The new primitives are not thread local, and the |
@alexcrichton one thing I found confusing in the current text was the discussion of locking. It wasn't clear to me whether the value returned by
It may be that this text is implicitly referencing the existing API or other things with which I am unfamiliar? In general though this text sounds to me as if the locking is something the user does ("first require acquiring a lock", "relocking is not necessary", "ButRef trait will not be impemented"), but there is no coverage of what API would be offered. I am guessing that I am misinterpreting this paragraph though. |
@nikomatsakis I tried to clarify that section a bit to make it a little more explicit, but let me know if anything is off! |
Amend RFC 517: Add material for stdio
This RFC has now been merged. It is a conservative refinement of the previous incarnation of stdio handles, in particular clarifying the interaction with Windows consoles/unicode requirements. We will definitely need to revisit this topic to introduce raw handles and redirection for |
No it cannot. The RFC says that |
I'm not referring to changing the target of |
What are you thinking that you'd consider having |
Stdout/in/err are unlikely to ever become thread local again. We used that design in old_io and it didn’t work out. Now we have one a single handle and are locking for thread safety instead. Regarding |
@nagisa: How did it not work out? Why do you think that that implies that it cannot work out?
Then libraries that want to allow having their output captured cannot use writeln? And they cannot write anything to stderr? That's ridiculous. |
For example, it is a serious problem in some terminal programs that you cannot capture the output of libraries which then mess up your output. You have to hack around this by replacing fd 1 and 2 temporarily with /dev/null before library calls (e.g.). The rust stdlib should not inherit this problem. |
The previous design made it possible to redirect
Right, so I'm wondering what proposal you have in mind? A few of your comments on this thread seem to be alluding to a design, but it'd help to see it spelled out a bit more explicitly. My main point here is that the current RFC doesn't address these problems and so we need to revisit it. Depending on the precise contract we give, it should be possible to add redirection later, but in any case we can probably address it before 1.0 regardless. |
See #973 |
Expand the section on stdin, stdout, and stderr while also adding a new section
explaining the fate of the current print-related functions.
Rendered