Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0007177OCamlstandard librarypublic2016-03-11 17:252017-02-20 11:46
Assigned Tofrisch 
PlatformDellOSCentOSOS Version6.6
Product Version4.02.3 
Target VersionundecidedFixed in Version 
Summary0007177: stderr is buffered when using some prerr functions
Descriptionstderr is buffered when using some prerr.. functions. This appears to be the opposite to the normal expectation for stderr
Steps To Reproducelet () =
  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");
TagsNo tags attached.
Attached Files

- Relationships
duplicate of 0006973acknowledged Provide functionality to set Pervasive's stderr to unbuffered bahaviour (Unix-like behaviour) 

-  Notes
junsli (reporter)
2016-03-19 03:38

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.
sbleazard (reporter)
2016-03-21 08:30

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
doligez (administrator)
2016-03-24 17:23

Sounds reasonable.

- Issue History
Date Modified Username Field Change
2016-03-11 17:25 sbleazard New Issue
2016-03-19 03:38 junsli Note Added: 0015550
2016-03-21 08:30 sbleazard Note Added: 0015556
2016-03-24 17:23 doligez Note Added: 0015604
2016-03-24 17:23 doligez Status new => confirmed
2016-03-24 17:23 doligez Target Version => 4.03.1+dev
2017-02-16 14:01 doligez Target Version 4.03.1+dev => undecided
2017-02-17 15:58 frisch Relationship added related to 0006973
2017-02-20 11:46 frisch Relationship replaced duplicate of 0006973
2017-02-20 11:46 frisch Status confirmed => resolved
2017-02-20 11:46 frisch Resolution open => duplicate
2017-02-20 11:46 frisch Assigned To => frisch
2017-02-23 16:43 doligez Category OCaml standard library => standard library

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker