www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9776] New: Make raw write mode the default

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9776

           Summary: Make raw write mode the default
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: cbkbbejeap mailinator.com



07:55:05 PDT ---
On Windows, the "write*" functions automatically convert \n to \r\n. This is
both error-prone and completely unnecessary on all versions of windows that
DMD/Phobos supports (ie, at *least* as far back as XP).

On all such versions of Windows, the command line, BATch files and code editors
all handle \n perfectly fine. If there are any obscure situations where \r\n is
still expected, they are more properly handled as-needed as special cases.

The big-prone nature of non-raw write is demonstrated in this straightforward
code:

--------------------------------------
import std.file;
import std.stdio;

void transform(string str)
{
    /+ ...perform some modification of 'str'... +/
    return str;
}

void main()
{
    auto str = cast(string) read(args[1]);
    str = transform(str);
    write(str);
}
--------------------------------------

That simple code is *wrong*:

It works correctly for all input on Unix: Output newlines match input newlines.
Always. The code never asks for newlines to be messed with, and therefore they
never are.

But on Windows the behavior is just plain weird: Unix-style newlines in the
input are silently and forcefully converted to Windows-style newlines behind
the user's back. And even worse yet, *Windows*-style newlines on the input are
converted to a bizarre "Mac9 plus Windows-style" combination of "\r\r\n" (not
only is that wrong period, but this sequence is often interpreted as two
newlines which makes it even worse). Using rawWrite fixes the problem, and
creates *no* problem.

People have been caught by that bug on various occasions, such as:
https://github.com/repeatedly/mustache-d/issues/3

See also the discussion on this matter on the D newsgroup:
http://forum.dlang.org/post/20130320103418.00005416 unknown

Various people have agreed, and so far, there hasn't been anyone arguing to
keep the current behavior.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 21 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9776


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com



11:20:06 PDT ---
*** Issue 11087 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 21 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9776




11:20:33 PDT ---
Simple test-case from Issue 11087:

-----
import std.file;
import std.stdio;

void main()
{
    std.file.write("test1.txt", "a\nb");

    auto file2 = File("test2.txt", "w");
    file2.write("a\nb");
    file2.close();

    auto res1 = cast(byte[])std.file.read("test1.txt");
    auto res2 = cast(byte[])std.file.read("test2.txt");

    writeln(res1);  // writes [97, 10, 98]
    writeln(res2);  // writes [97, 13, 10, 98]
}
-----

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 21 2013