www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6944] New: stdio.File.byLine can't handle an empty file

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

           Summary: stdio.File.byLine can't handle an empty file
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: jmdavisProg gmx.com



PST ---
This program

import std.file;
import std.stdio;

void main()
{
    std.file.write("empty.txt", "");
    auto file = File("empty.txt");

    foreach(line; file.byLine())
        writeln(line);
}


results in this output:

core.exception.AssertError std/stdio.d(946): Bug in File.readln
----------------
./q(_d_assert_msg+0x1f) [0x4595cb]
./q(void std.stdio.File.ByLine!(char, char).ByLine.popFront()+0xa6) [0x4560a2]
./q(char[] std.stdio.File.ByLine!(char, char).ByLine.front()+0x4c) [0x455fec]
./q(_Dmain+0x87) [0x455e13]
./q(extern (C) int rt.dmain2.main(int, char**).void runMain()+0x17) [0x459bd7]
./q(extern (C) int rt.dmain2.main(int, char**).void tryExec(scope void
delegate())+0x2a) [0x45977e]
./q(extern (C) int rt.dmain2.main(int, char**).void runAll()+0x42) [0x459c2a]
./q(extern (C) int rt.dmain2.main(int, char**).void tryExec(scope void
delegate())+0x2a) [0x45977e]
./q(main+0xd3) [0x45970f]
/lib/libc.so.6(__libc_start_main+0xed) [0x7ff97772817d]d


The foreach should just not run, since it's effectively iterating over an empty
range, but apparently ByLine's empty doesn't check the possibility that EOF has
already been reached - just whether the file is open or not.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 13 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6944




PST ---
The simplest workaround that I've found is to use check whether
std.file.getSize returns a value greater than 0, but I don't know if that's
technically sufficient, and even if it is, I'm not sure that that's what should
be done internall to ByLine. It _does_ allow you to avoid AssertErrors until
the problem is fixed though.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 13 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6944


Jonathan M Davis <jmdavisProg gmx.com> changed:

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



PST ---
*** Issue 6993 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: -------
Nov 22 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6944


Brad Roberts <braddr puremagic.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |braddr puremagic.com
         Resolution|                            |FIXED



---
Andrei addressed in:
  https://github.com/D-Programming-Language/phobos/pull/375

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