FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Stupid IO Issue

 
Post new topic   Reply to topic     Forum Index -> Mango
View previous topic :: View next topic  
Author Message
teqdruid



Joined: 11 May 2004
Posts: 390
Location: UMD

PostPosted: Wed Feb 23, 2005 6:21 pm    Post subject: Stupid IO Issue Reply with quote

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
View user's profile Send private message Send e-mail AIM Address
Derek Parnell



Joined: 22 Apr 2004
Posts: 408
Location: Melbourne, Australia

PostPosted: Wed Feb 23, 2005 6:46 pm    Post subject: Reply with quote

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
View user's profile Send private message
teqdruid



Joined: 11 May 2004
Posts: 390
Location: UMD

PostPosted: Wed Feb 23, 2005 8:18 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail AIM Address
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Thu Feb 24, 2005 8:12 pm    Post subject: Reply with quote

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
View user's profile Send private message
teqdruid



Joined: 11 May 2004
Posts: 390
Location: UMD

PostPosted: Fri Feb 25, 2005 10:13 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail AIM Address
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Fri Feb 25, 2005 12:21 pm    Post subject: Reply with quote

I'll run your example through the debugger tonight.
Back to top
View user's profile Send private message
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Wed Mar 02, 2005 10:30 pm    Post subject: Reply with quote

Sorry for taking so long to reply, John; I hope you got it fixed by this time Embarassed

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Mango All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group