www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - foreach(line; f.byLine) produces

reply Andrwe Brown <aabrown24 hotmail.com> writes:
Hi,

I'm trying to read a file line by line, and I get a 
core.exception.InvalidMemoryOperationError (0), even after 
reducing the program to:

import std.stdio;

void main()
{
   File f = File("testfile");
   foreach(line; f.byLine)
   {
   }
}

The file is a simple table of ascii characters, 811 columns and 
it fails on the second line. Taking any subset of the columns and 
the program runs fine so I don't think it can by any particular 
file corruption.

In this simple example I can get it to work by changing:

foreach(line; f.byLine)

to

foreach(char[] line; f.byLine)

but in my more complicated program this still fails with the same 
error:

foreach (char[] lineVar; inFile.byLine)
{
   lineVar.split.indexed(places).joiner("\t").writeln;
}

(as does the range version I originally wrote:
inFile.byLine.map!(a => 
a.split.indexed(places).joiner("\t")).joiner("\n").writeln;)

Is this a bug, gdc on version 2.066 seems to have no problems 
with it? I'd be happy to fill in a bug report, but I can't share 
the file as it's sensitive genetic data and I haven't been able 
to reduce it to anything innocuous.

This has me very puzzled, any suggestions would be much 
appreciated.

Thanks very much

Andrew
Sep 15 2015
next sibling parent Martin Krejcirik <mk-junk i-line.cz> writes:
On Tuesday, 15 September 2015 at 13:56:37 UTC, Andrwe Brown wrote:
 I'm trying to read a file line by line, and I get a 
 core.exception.InvalidMemoryOperationError (0), even after
https://issues.dlang.org/show_bug.cgi?id=13856 Try DMD 2.068, it has got fixed byLine implementation.
Sep 15 2015
prev sibling next sibling parent reply Daniel =?UTF-8?B?S296w6Fr?= via Digitalmars-d-learn writes:
On Tue, 15 Sep 2015 13:56:36 +0000
Andrwe Brown via Digitalmars-d-learn
<digitalmars-d-learn puremagic.com> wrote:

 Hi,
 
 I'm trying to read a file line by line, and I get a 
 core.exception.InvalidMemoryOperationError (0), even after 
 reducing the program to:
 
 import std.stdio;
 
 void main()
 {
    File f = File("testfile");
    foreach(line; f.byLine)
    {
    }
 }
 
 The file is a simple table of ascii characters, 811 columns and 
 it fails on the second line. Taking any subset of the columns and 
 the program runs fine so I don't think it can by any particular 
 file corruption.
 
 In this simple example I can get it to work by changing:
 
 foreach(line; f.byLine)
 
 to
 
 foreach(char[] line; f.byLine)
 
 but in my more complicated program this still fails with the same 
 error:
 
 foreach (char[] lineVar; inFile.byLine)
 {
    lineVar.split.indexed(places).joiner("\t").writeln;
 }
 
 (as does the range version I originally wrote:
 inFile.byLine.map!(a => 
 a.split.indexed(places).joiner("\t")).joiner("\n").writeln;)
 
 Is this a bug, gdc on version 2.066 seems to have no problems 
 with it? I'd be happy to fill in a bug report, but I can't share 
 the file as it's sensitive genetic data and I haven't been able 
 to reduce it to anything innocuous.
 
 This has me very puzzled, any suggestions would be much 
 appreciated.
 
 Thanks very much
 
 Andrew
Which OS?
Sep 15 2015
parent Andrew Brown <aabrown24 hotmail.com> writes:
On Tuesday, 15 September 2015 at 14:19:13 UTC, Daniel Kozák wrote:
 Which OS?
It's CentOS release 6.5 (Final), I tried dmd 2.068.1 and the problem has disappeared. Thanks very much for the advice, I can stick to old gdc for speed until ldc catches up to 2.068. Best Andrew
Sep 15 2015
prev sibling parent reply Martin Krejcirik <mk-junk i-line.cz> writes:
For reference, it was this PR:
https://github.com/D-Programming-Language/phobos/pull/3089
which fixed the same issue for me.
Sep 15 2015
parent reply Andrew Brown <aabrown24 hotmail.com> writes:
On Tuesday, 15 September 2015 at 14:55:42 UTC, Martin Krejcirik 
wrote:
 For reference, it was this PR:
 https://github.com/D-Programming-Language/phobos/pull/3089
 which fixed the same issue for me.
A very naive question: would it be possible in this case to backport it into gdc/ldc by copying the pull request and building the compiler from source, or would this get me into a world of pain?
Sep 15 2015
parent reply Martin Krejcirik <mk-junk i-line.cz> writes:
On Tuesday, 15 September 2015 at 15:28:23 UTC, Andrew Brown wrote:
 A very naive question: would it be possible in this case to 
 backport it into gdc/ldc by copying the pull request and 
 building the compiler from source, or would this get me into a 
 world of pain?
Cherry-picking should work and merge cleanly. I have done it for DMD 2.067. I don't know how difficult it is to recompile Phobos and Druntime with LDC/GDC though.
Sep 15 2015
parent Andrew Brown <aabrown24 hotmail.com> writes:
Thanks very much for your help, it seemed to work a treat (I hope 
:))! Compiling ldc wasn't too bad, make the changes to 
runtime/phobos/std/stdio.d and then just building as normal was 
no problem. Unittests are passing and it handles that file 
perfectly.

On Tuesday, 15 September 2015 at 16:11:06 UTC, Martin Krejcirik 
wrote:
 On Tuesday, 15 September 2015 at 15:28:23 UTC, Andrew Brown 
 wrote:
 A very naive question: would it be possible in this case to 
 backport it into gdc/ldc by copying the pull request and 
 building the compiler from source, or would this get me into a 
 world of pain?
Cherry-picking should work and merge cleanly. I have done it for DMD 2.067. I don't know how difficult it is to recompile Phobos and Druntime with LDC/GDC though.
Sep 15 2015