Skip to content
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

Document existence of buffer for in_channels, and related scenarios #10817

Closed
wants to merge 0 commits into from
Closed

Document existence of buffer for in_channels, and related scenarios #10817

wants to merge 0 commits into from

Conversation

tomjridge
Copy link

In particular, that the buffer isn't updated automatically when the
underlying file data changes.

Copy link
Member

@dra27 dra27 left a comment

Choose a reason for hiding this comment

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

Thanks for this - it's definitely good to correct, especially given that the Unix module already has a warning about in_channel being buffered. A few things (bizarrely, for one paragraph!):

  • The information needs to go in the new In_channel module as well. I don't think it should be specifically on open_in_gen - it could be an isolated paragraph immediately below the heading in Stdlib and as part of the opening text in In_channel (you'll have to check what the HTML output looks like - I can't remember what ocamldoc does with paragraphs in the middle of modules)
  • It's nice to mention the alternative for the user who needs unbuffered input:

@@ -1080,7 +1080,11 @@ val open_in_gen : open_flag list -> int -> string -> in_channel
as described above. The extra arguments
[mode] and [perm] specify the opening mode and file permissions.
{!Stdlib.open_in} and {!Stdlib.open_in_bin} are special
cases of this function. *)
cases of this function.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
cases of this function.
cases of this function.

For there to be a newline, ocamldoc needs a blank line following (assuming that was what you intended)?

@xavierleroy
Copy link
Contributor

The information needs to go in the new In_channel module as well. I don't think it should be specifically on open_in_gen - it could be an isolated paragraph immediately below the heading in Stdlib and as part of the opening text in In_channel

Detailed information should go in In_channel with at most a brief mention in Stdlib. Let's not duplicate things.

@xavierleroy
Copy link
Contributor

This said, buffered I/O behaves pretty much the same in any language (e.g. stdio.h streams in C, BufferedInputStream in Java, and in_channel in OCaml), so I'm not quite sure what needs to be documented specifically in OCaml.

@tomjridge
Copy link
Author

I removed my comment from stdlib and added another to in_channel.mli. I also noticed that the Unix module has a lot of these "Beware that input channels are buffered" warnings, but they don't do any harm I suppose.

I can rebase/squash the changes against current trunk to tidy things if that would help.

Regarding having an unbuffered input channel #10538, I think my use case is probably better handled by normal Unix.openfile etc.

@tomjridge tomjridge closed this Nov 16, 2022
@tomjridge
Copy link
Author

tomjridge commented Nov 16, 2022

Not worth keeping open, so closing. I think I was pondering whether buffered I/O could be more "intelligent" i.e. noticing concurrent updates to a file by another process and then refreshing the buffer (or something along those lines). But this isn't the standard behaviour as Xavier says. Sorry for the noise. And thanks to David for the feedback.

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

Successfully merging this pull request may close these issues.

None yet

3 participants