D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7374 - stdin.byLine() throws AssertError on empty input
Summary: stdin.byLine() throws AssertError on empty input
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86_64 Linux
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-01-26 12:16 UTC by hsteoh
Modified: 2012-02-24 11:11 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description hsteoh 2012-01-26 12:16:45 UTC
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).
Comment 1 Andrei Alexandrescu 2012-02-23 16:23:00 UTC
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.
Comment 2 hsteoh 2012-02-24 10:52:15 UTC
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.