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

stderr is buffered when using some prerr functions #7177

Closed
vicuna opened this issue Mar 11, 2016 · 3 comments
Closed

stderr is buffered when using some prerr functions #7177

vicuna opened this issue Mar 11, 2016 · 3 comments

Comments

@vicuna
Copy link

vicuna commented Mar 11, 2016

Original bug ID: 7177
Reporter: sbleazard
Assigned to: @alainfrisch
Status: resolved (set by @alainfrisch on 2017-02-20T10:46:26Z)
Resolution: duplicate
Priority: normal
Severity: minor
Platform: Dell
OS: CentOS
OS Version: 6.6
Version: 4.02.3
Target version: undecided
Category: standard library
Duplicate of: #6973
Monitored by: @diml @hcarty

Bug description

stderr is buffered when using some prerr.. functions. This appears to be the opposite to the normal expectation for stderr

Steps to reproduce

let () =
prerr_endline "foo";
prerr_string "foobar\n";
Unix.sleep 5

foo will print out but foobar will not until after the sleep. The C version works, printing foofoobar before the sleep:

#include <stdio.h>

main(int argc, char **argv)
{
fprintf(stderr, "foo");
fprintf(stderr, "foobar\n");
sleep(5);
}

@vicuna
Copy link
Author

vicuna commented Mar 19, 2016

Comment author: junsli

So which one do you propose: stderr should not be buffered?

stderr is not buffered on Linux. stdout is buffered until it finds '\n'.

Regarding OCaml, The manual does not mention its stderr is buffered, but it does mention that prerr_endline and prerr_newline flush the buffer. So I would take it as a design choice that ocaml buffers string (even string with \n) in stderr and provides two functions for you to flush the buffer.

@vicuna
Copy link
Author

vicuna commented Mar 21, 2016

Comment author: sbleazard

In general I think there is an expectation among programmers that an output named stderr is unbuffered. I think this is reasonable given the use cases for stderr.

Also, the buffered nature of stderr is bubbling up to the other library functions including Jane Street's eprintf. As a result I have to force a flush on every write when using stderr for the commonest use cases.

Based on this I would make stderr unbuffered in the same way as c, c++ and python

@vicuna
Copy link
Author

vicuna commented Mar 24, 2016

Comment author: @damiendoligez

Sounds reasonable.

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

No branches or pull requests

2 participants