Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006088OCamlOCaml standard librarypublic2013-07-26 15:222013-07-29 19:08
ReporterAltGr 
Assigned To 
PrioritynormalSeverityminorReproducibilityalways
StatusresolvedResolutionno change required 
PlatformOSWindowsOS Versionany
Product Version4.00.1 
Target VersionFixed in Version 
Summary0006088: Pervasives.input_line does'nt remove \r at end of lines
DescriptionDocumentation says: "Return the string of all characters read, without the newline character at the end."

Well, on Windows, the newline characters are two, "\r\n" ; one would expect that they are both removed, and that would avoid portability issues. Instead, the function returns strings ending with '\r'.
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0009868)
gasche (developer)
2013-07-26 18:32

Did you open the file with open_in or open_in_bin? open_in will do newline translation (removing the \r as appropriate), but not open_in_bin. Do you have a complete code example as a repro case?
(0009985)
xleroy (administrator)
2013-07-29 16:29

Gasche is right: the Windows programming model (for OCaml and most other languages) is that for in-memory strings, lines are terminated by a single "\n" character. It's only within text files that "\r\n" is used, and the conversion happens when reading or writing to/from files. So, just open your text files with "open_in" and not "open_in_bin" and input_line will work fine.
(0009992)
AltGr (reporter)
2013-07-29 18:26

Right, I suspected it was done that way for open_in (the documentation isn't completely explicit but mentions it), and I think that this is a good way to handle things. My issue then is that I was actually using "Unix.open_process_in" in that case, which has no "_bin" counterpart (and commands, typically ocaml, answer with Windows EOLs).

I am not sure what the correct behaviour would be in that case, but the current one isn't completely consistent.

(note: this is using the mingw32 version)
(0009994)
xleroy (administrator)
2013-07-29 18:57

> I was actually using "Unix.open_process_in" in that case, which has no "_bin" counterpart

Right, the open_process_* functions default to binary mode, somewhat arbitrarily. It wouldn't hurt to document this fact.

You can, however, use "set_binary_mode_in" or "set_binary_mode_out" on the returned channel to put it into text mode. These operations are no-ops under non-Windows systems, so your code remains fully portable.
(0009995)
AltGr (reporter)
2013-07-29 19:08

Seems like I somehow overlooked the "set_binary_mode_*" functions.
Thanks a lot !

- Issue History
Date Modified Username Field Change
2013-07-26 15:22 AltGr New Issue
2013-07-26 18:32 gasche Note Added: 0009868
2013-07-29 16:29 xleroy Note Added: 0009985
2013-07-29 16:29 xleroy Status new => resolved
2013-07-29 16:29 xleroy Resolution open => no change required
2013-07-29 18:26 AltGr Note Added: 0009992
2013-07-29 18:57 xleroy Note Added: 0009994
2013-07-29 19:08 AltGr Note Added: 0009995


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker