www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - stream readf keeps producing bus error on DMD 2.046 on OS X 10.5.8

reply RedZone <kilpa1kb cmich.edu> writes:
Hi,

I've been trying to use readf to read some basic text from a file... I found,
though, that readf kept producing inexplicable bus errors.  I simplified my
code and tried to use readf on just a plain character array.  No change.
Here's the code:

import std.stdio;
//import std.file;
import std.stream;

void main()
{
	string s1;
	int i;
	string s2;
	string s3;

	char[] s0 = "a 5 bc e".dup;
	auto stream = new TArrayStream!(char[])(s0);

	stream.readf("%s %d %s %s ", &s1, &i, &s2, &s3);
	writefln("%s %d %s %s", s1, i, s2, s3);

}


It doesn't matter how I change the input or what I use as the stream, readf
produces this bus error.  Compiling in release mode doesn't help either.  What
am I doing wrong?

I'm using DMD 2.046 on Mac OS X 10.5.8.
Jul 08 2010
parent reply =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
RedZone wrote:
 Hi,
 
 I've been trying to use readf to read some basic text from a file... I found,
 though, that readf kept producing inexplicable bus errors.  I simplified my
 code and tried to use readf on just a plain character array.  No change.
 Here's the code:
 
 import std.stdio;
 //import std.file;
 import std.stream;
 
 void main()
 {
 	string s1;
 	int i;
 	string s2;
 	string s3;
 
 	char[] s0 = "a 5 bc e".dup;
 	auto stream = new TArrayStream!(char[])(s0);
 
 	stream.readf("%s %d %s %s ", &s1, &i, &s2, &s3);
 	writefln("%s %d %s %s", s1, i, s2, s3);
 
 }
 
 
 It doesn't matter how I change the input or what I use as the stream, readf
 produces this bus error.  Compiling in release mode doesn't help either.  What
 am I doing wrong?
 
 I'm using DMD 2.046 on Mac OS X 10.5.8.

Reading into char arrays and dropping the format string works (tried with dmd 2.047): char[] s1; int i; char[] s2; char[] s3; char[] s0 = "a 5 bc e".dup; auto s = new TArrayStream!(char[])(s0); s.readf(&s1, &i, &s2, &s3); I hear that the streams will be (are?) deprecated. There will be std.stdio.readf which will be in the next dmd release. Ali
Jul 08 2010
next sibling parent RedZone <kilpa1kb cmich.edu> writes:
That ended up working.  Thank you!

Yeah, I've heard about stream deprecation as well.  Why are they being
deprecated,
though?
Jul 10 2010
prev sibling parent Jonathan M Davis <jmdavisprog gmail.com> writes:
On Saturday 10 July 2010 13:34:45 RedZone wrote:
 That ended up working.  Thank you!
 
 Yeah, I've heard about stream deprecation as well.  Why are they being
 deprecated, though?

A better design should be coming along as I understand it. I don't know what issues the current streams have (I haven't used them much) other than the fact that they're not range-based, but Andrei and company are looking to have a set of streams that are ranges and work directly with std.algorithm and the like. The result should be much more powerful. So, streams in the generals sense aren't going away, but the current design is. - Jonathan M Davis
Jul 10 2010