www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7374] New: stdin.byLine() throws AssertError on empty input

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

           Summary: stdin.byLine() throws AssertError on empty input
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: hsteoh quickfur.ath.cx



Here's the test program:

import std.stdio;
void main() {
        foreach (line; stdin.byLine()) {
                writeln("Got input line: ", line);
        }
}

When the program is run on an empty input (e.g., running 'echo -n | program' in
the shell, or hitting ctrl-D once the program starts up, or piping an empty
file to the program), an assertion fails:

core.exception.AssertError /usr/include/d2/4.6/std/stdio.d(989): Bug in
File.readln

It appears that the problem is caused by one of two things:

(1) ByLine.empty() assuming that as long as a file is open it will have at
least 1 line, but this is not true when the input is 0 bytes.

(2) stdin.readln() returns null if the input has 0 bytes, instead of a line of
0 length (which is what it does at EOF if the input is *not* empty).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 26 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7374


Andrei Alexandrescu <andrei metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrei metalanguage.com



16:23:00 PST ---
I think
https://github.com/D-Programming-Language/phobos/commit/94b21d38d16e075d7c44b53015eb1113854424d0
fixes this, could you please double-check? On OSX the test program works as
expected.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 23 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7374




I couldn't figure out how to make git phobos work with gdc, but I managed to
build latest git dmd/druntime/phobos and run the test program on it, now it
seems to work. So this bug can probably be closed.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 24 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7374


Andrei Alexandrescu <andrei metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 24 2012