www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Error in std.stream

reply BCS <BCS_member pathlink.com> writes:
import std.stream;


void main()
{
Stream ins = new BufferedFile(__FILE__, FileMode.In);
assert(ins.seekable);

ulong spot = ins.position-1;
printf("peek \"%.*s\"\n", ins.readLine());
ins.seek(spot, SeekPos.Set);
ins.position = spot;
}


/*
what's wrong with this program????
compiles fine, asserts work.

when run prints:
---
peek "import std.stream;"
Error: unable to move file pointer
---

It appears that BufferedFile is seekable (the assert at least 
claims it is) but when I try to seek on it, the seek fails.
*/
Aug 04 2005
next sibling parent reply Ben Hinkle <Ben_member pathlink.com> writes:
In article <dcum8v$1ihb$1 digitaldaemon.com>, BCS says...
import std.stream;


void main()
{
Stream ins = new BufferedFile(__FILE__, FileMode.In);
assert(ins.seekable);

ulong spot = ins.position-1;
printf("peek \"%.*s\"\n", ins.readLine());
ins.seek(spot, SeekPos.Set);
ins.position = spot;
}


/*
what's wrong with this program????
compiles fine, asserts work.

when run prints:
---
peek "import std.stream;"
Error: unable to move file pointer
---

It appears that BufferedFile is seekable (the assert at least 
claims it is) but when I try to seek on it, the seek fails.
*/

I can't reproduce the error on either Windows or Linux using dmd.128 - can you give more details about your setup? Another odd detail is that I would expect to be able to reproduce it since you are asking to set the file pointer to pos = -1. The reason is that when you create a new BufferedFile the position is at 0 and so position-1 is -1. Then the code reads a line and tries to set the position to -1 cast to a ulong which is far outside the range of the actual file data. I'd have to look up the doc for each platform to see what happens when you try to do that. -Ben
Aug 04 2005
parent reply Derek Parnell <derek psych.ward> writes:
On Fri, 5 Aug 2005 03:48:22 +0000 (UTC), Ben Hinkle wrote:

 In article <dcum8v$1ihb$1 digitaldaemon.com>, BCS says...

[snip]
 I can't reproduce the error on either Windows or Linux using dmd.128

It failed for me using Windows XP and DMD 0.128 -- Derek Melbourne, Australia 5/08/2005 3:32:03 PM
Aug 04 2005
parent "Ben Hinkle" <bhinkle mathworks.com> writes:
 I can't reproduce the error on either Windows or Linux using dmd.128

It failed for me using Windows XP and DMD 0.128

OK - I got it now. I reset my dmd setup and was able to reproduce it. My phobos.lib was in a bad state.
Aug 05 2005
prev sibling parent Derek Parnell <derek psych.ward> writes:
On Fri, 5 Aug 2005 03:26:23 +0000 (UTC), BCS wrote:

 import std.stream;
 
 void main()
 {
 Stream ins = new BufferedFile(__FILE__, FileMode.In);
 assert(ins.seekable);
 
 ulong spot = ins.position-1;
 printf("peek \"%.*s\"\n", ins.readLine());
 ins.seek(spot, SeekPos.Set);
 ins.position = spot;
 }
 
 /*
 what's wrong with this program????
 compiles fine, asserts work.
 
 when run prints:
 ---
 peek "import std.stream;"
 Error: unable to move file pointer
 ---
 
 It appears that BufferedFile is seekable (the assert at least 
 claims it is) but when I try to seek on it, the seek fails.
 */

You are trying to set the file position to -1. The first position is zero though. -- Derek Melbourne, Australia 5/08/2005 3:28:40 PM
Aug 04 2005