View previous topic :: View next topic |
Author |
Message |
teqdruid
Joined: 11 May 2004 Posts: 390 Location: UMD
|
Posted: Wed Feb 23, 2005 6:21 pm Post subject: Stupid IO Issue |
|
|
I've not been having luck with D lately....
Code: | auto FileConduit mainFile = new FileConduit (mainFilePath);
Reader br = new Reader(mainFile);
char[] first, second;
br(first)(second);
writefln(first);
writefln(mainFileFirstLine);
writefln("?d", cmp(first,mainFileFirstLine));
writefln(first);
if (cmp(first, mainFileFirstLine) != 0) {
writefln(first);
writefln("?d", cmp(first,mainFileFirstLine));
throw new nnStoreException("Specified database does not exist or is corrupted. '" ~ first ~ "'");
} |
Why would that code ever produce the following output:
Code: |
neuralNexusDB
-13
neuralNexusDB
0
Error: Specified database does not exist or is corrupted. 'neuralNexusDB'
|
Please note that the first line is blank. What seems to be happening here is that the first variable doesn't have anything in it until we get inside the if. WHY?!?!?!?!
You ever get that feeling like you're going insane?... What I wouldn't give for dmd's linux debugging support to be correct... |
|
Back to top |
|
|
Derek Parnell
Joined: 22 Apr 2004 Posts: 408 Location: Melbourne, Australia
|
Posted: Wed Feb 23, 2005 6:46 pm Post subject: |
|
|
I'm guessing its D's loose definition that a null char[] is the same thing as an empty string.
Why don't you code it comparing the string lengths instead ...
Code: |
auto FileConduit mainFile = new FileConduit (mainFilePath);
Reader br = new Reader(mainFile);
char[] first, second;
br(first)(second);
writefln(first);
writefln(mainFileFirstLine);
writefln("?d", (first.length==mainFileFirstLine.length));
writefln(first);
if ( first != mainFileFirstLine) {
writefln(first);
writefln("?d", (first.length ==mainFileFirstLine.length));
throw new nnStoreException("Specified database does not exist or is corrupted. '" ~ first ~ "'");
}
|
_________________ --
Derek
skype name: derek.j.parnell |
|
Back to top |
|
|
teqdruid
Joined: 11 May 2004 Posts: 390 Location: UMD
|
Posted: Wed Feb 23, 2005 8:18 pm Post subject: |
|
|
So here's another hint. If, right after the whisper syntax, I insert:
Code: | foreach(char c; first){} |
Then it all works fine.
I so don't get what's going on. I should probably add that I'm running mango SVN and DMD 0.113 |
|
Back to top |
|
|
kris
Joined: 27 Mar 2004 Posts: 1494 Location: South Pacific
|
Posted: Thu Feb 24, 2005 8:12 pm Post subject: |
|
|
Strange. I assume the file you're reading is formatted in a manner suitable for the (binary) reader? I mean, with an element-count prefix for each of the strings?
- Kris |
|
Back to top |
|
|
teqdruid
Joined: 11 May 2004 Posts: 390 Location: UMD
|
Posted: Fri Feb 25, 2005 10:13 am Post subject: |
|
|
Quote: | I assume the file you're reading is formatted in a manner suitable for the (binary) reader? I mean, with an element-count prefix for each of the strings? |
You assume correctly. The file was written using Mango's Writer class. |
|
Back to top |
|
|
kris
Joined: 27 Mar 2004 Posts: 1494 Location: South Pacific
|
Posted: Fri Feb 25, 2005 12:21 pm Post subject: |
|
|
I'll run your example through the debugger tonight. |
|
Back to top |
|
|
kris
Joined: 27 Mar 2004 Posts: 1494 Location: South Pacific
|
Posted: Wed Mar 02, 2005 10:30 pm Post subject: |
|
|
Sorry for taking so long to reply, John; I hope you got it fixed by this time
Code: | void testDruid()
{
auto FileConduit mainFile = new FileConduit ("foo.bar", FileStyle.ReadWriteCreate);
char[] first, second;
Reader input = new Reader (mainFile);
Writer output = new Writer (mainFile);
output ("123") ("abcdef") ();
mainFile.seek (0);
input (first) (second);
printf ("'?.*s' '?.*s'\n", first, second);
} |
I did run the above code through the debugger, but it doesn't exhibit the problem you ran into. Perhaps there is something else involved? |
|
Back to top |
|
|
|