November 06, 2003 Re: possible bug with remove? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam Harper | Hmnh...
I wasn't even getting any output from the first printf statement. The one with a simple text string. So something else was wrong, but it isn't wrong now. Don't know what. (I tried it in several variations...the one assigning an integer parameter was merely the last effort.)
Whatever, I'm past that now, and I've downloaded the new version of dmd, so I'll be putting the std's back on. But you have defused all of my possible guesses as to what was happening.
Adam Harper wrote:
> On Wed, 05 Nov 2003 17:21:55 -0800, Charles Hixson wrote:
>
>>Nope. The std was just you having a different library structure than I do
>>(you probably reconfigured it to match the recent discussions). My
>
>
> One of the files I attached (replace-0.75.d) is using the new (as of dmd
> 0.75) phobos/standard library layout, which has the "std." prefix. The
> other file I attached should work on all dmd's prior to 0.75.
>
>
>>current guess is that it's the way you prefixed c.stdio. to all of the
>>printf's etc. (I had been assuming that they were being recognized
>>properly as no error messages were being thrown.) Anyway, I'm now
>>starting to see messages, so I can *try* to figure out what's happening. Yeah!!
>
>
> Actually, the "c.stdio" prefix is completely superfluous, you can delete
> it without any ramifications. You can also remove the "import c.stdio;"
> line, it won't effect anything.
>
>
>>(So far it's said "Usage:\n\treplace filename(s)\n", but that's what it
>>*should* have said.)
>
>
> Having just tried the file I posted on Linux, I noticed that it was
> missing a "\n" at the end of the printf on line 112. That line should
> read:
>
>
>>c.stdio.printf( "%d strings replaced in <<%.*s>>\n",
>> strcount, sourcename );
>
>
> This was preventing it from outputting the "xx strings replaced in
> <<file>>" line(s). I could have sworn they were there on Windows.
>
> With the one change above the "replace.d" from my last message is
> compiling and working just fine in Linux. What's happening when you
> compile/run it?
>
>
>>Charles Hixson wrote:
>>
>>>That's a better critique than I could have hoped for. (Some of the
>>>errors you corrected are due to my going into a "try anything to just
>>>get SOMETHING working" after the original printf didn't work [and
>>>originally it didn't ask for a return value...so I looked through phobos
>>>trying for inspiration, and found a place where it specified printf with
>>>an integer return, so I tried that ..and that's why you only find that
>>>in a couple of places.)
>>>
>>>OTOH...I did get it to compile with several of the options (possibly not
>>>the final one). I just couldn't get it to print out anything, or
>>>appearantly to get past the first readLine. OTOH, it did echo back
>>>everything I typed whenever I hit a carriage return, so it wasn't hung.
>>>
>>>However, I notice that you changed the names of the files being
>>>imported. That's probably the key right there. I had said:
>>>
>>>//import file;
>>>import stream;
>>>//import c.stdio;
>>>(with various choices of commenting out) while you said: import
>>>std.file;
>>>import std.stream;
>>>import std.c.stdio;
>>>
>>>That's probably the answer that blocked me so that every approach I
>>>tried failed. Now, at least I should get far enough to get errors.
>>>
>>>
>>>Adam Harper wrote:
>>>
>>>
>>>><snip>
>>>>
>>>>Hi Charles, Walter (and anyone else who may be reading this thread),
>>>>
>>>>I've taken the liberty of going over the "replace.d" supplied by
>>>>Charles, below are the changes needed to get it to compile. Apologies
>>>>in advance if it comes across as overly critical.
>>>>
>>>>----
>
>
|
November 07, 2003 Re: possible bug with remove? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Charles Hixson | On Thu, 06 Nov 2003 14:47:03 -0800, Charles Hixson wrote: > Hmnh... > I wasn't even getting any output from the first printf statement. The one > with a simple text string. So something else was wrong, but it isn't > wrong now. Don't know what. (I tried it in several variations...the one > assigning an integer parameter was merely the last effort.) Hmm... I don't really know what was going wrong for you originally, I haven't even been able to reproduce your original error message using the file you posted on 04/11/2003. Below are the steps I went through to get that file compiling and working (to a degree) on my Linux box. First some basic info: > aharper@slinky:~$ uname -a > Linux slinky 2.4.20 #11 Fri May 2 12:56:47 BST 2003 i686 GNU/Linux > aharper@slinky:~$ gcc -v > Reading specs from /usr/lib/gcc-lib/i486-linux/3.3.2/specs > Configured with: ... > Thread model: posix > gcc version 3.3.2 (Debian) > aharper@slinky:~$ apps/devel/d/dmd/bin/dmd -v > Digital Mars D Compiler Beta v0.69 > Copyright (c) 1999-2003 by Digital Mars written by Walter Bright > ... Now the changes I made line by line, in the order I made them. Line 12: Change 'file' to 'File' Still not compiling, error message is: > replace-ch.d(12): identifier 'file' is not defined Line 5: Uncomment 'import stream;' Now compiles. Prints: > aharper@slinky:~/apps/devel/d$ ./replace-ch > start > Usage: > replace filename(s) When run. Attempting to use results in the following: > aharper@slinky:~/apps/devel/d$ echo test atest btest ctestde > > test.txt > aharper@slinky:~/apps/devel/d$ ./replace-ch test.txt > start > String to be replaced? (terminate with a CR) > test > Replacement string? (terminate with a CR) > TEST > Segmentation fault Line 34: Change to 'printf ("File <<%.*s>>\n", sourcename);' Running now results in: > aharper@slinky:~/apps/devel/d$ ./replace-ch test.txt > start > String to be replaced? (terminate with a CR) > test > Replacement string? (terminate with a CR) > TEST > File <<test.txt>> > test.txt.bak > Error: Assertion Failure replace-ch.d(76) Line 18: Add a new line above with the text 'return 0;' Running now results in: > aharper@slinky:~/apps/devel/d$ ./replace-ch test.txt > start > String to be replaced? (terminate with a CR) > test > Replacement string? (terminate with a CR) > TEST > File <<test.txt>> > test.txt.bak > aharper@slinky:~/apps/devel/d$ cat test.txt > test atest btest ctestde > aharper@slinky:~/apps/devel/d$ Line 46: Delete the line. Running now results in: > aharper@slinky:~/apps/devel/d$ ./replace-ch test.txt > start > String to be replaced? (terminate with a CR) > test > Replacement string? (terminate with a CR) > TEST > File <<test.txt>> > test.txt.bak > No changes > 0 strings replaced > aharper@slinky:~/apps/devel/d$ cat test.txt > test atest btest ctestde > aharper@slinky:~/apps/devel/d$ Line 92: Move within while loop beginning on line 93. Running now results in: > aharper@slinky:~/apps/devel/d$ ./replace-ch test.txt > start > String to be replaced? (terminate with a CR) > test > Replacement string? (terminate with a CR) > TEST > File <<test.txt>> > test.txt.bak > File rename error with file <<test.txt>> > Error: File rename error with file <<test.txt>>: file I/O Line 50: Move out of current try/catch loop and into separate try/catch loop above. Lines 49 to 58 should now look something like: > { try > { file_remove_365 (backupname); > } > catch > { > /* Ignore any errors */ > } > > try > { file.rename (sourcename, backupname); Running now results in: > aharper@slinky:~/apps/devel/d$ ./replace-ch test.txt > start > String to be replaced? (terminate with a CR) > test > Replacement string? (terminate with a CR) > TEST > File <<test.txt>> > test.txt.bak > 4 strings replaced > aharper@slinky:~/apps/devel/d$ cat test.txt > > aharper@slinky:~/apps/devel/d$ Line 117: Make 'outLine' an out parameter: > uint replaceInLine(char[] inpLine, > char[] old, > char[] to, > out char[] outLine) Running now results in: > aharper@slinky:~/apps/devel/d$ ./replace-ch test.txt > start > String to be replaced? (terminate with a CR) > test > Replacement string? (terminate with a CR) > TEST > File <<test.txt>> > test.txt.bak > 4 strings replaced > aharper@slinky:~/apps/devel/d$ cat test.txt > TEST aTEST bTEST cTEST > aharper@slinky:~/apps/devel/d$ Obviously there are still a few things that need doing, but the program compiles and runs without error. Now to try and reproduce your error... Starting with the file you originally posted again (discarding the changes made above) if we do the following: - Uncomment lines 5 and 6 (import stream and c.stdio) - Change 'file' on line 12 to 'File' Then when we compile we get (apologies for the wrapping): > aharper@slinky:~/apps/devel/d$ dmd/bin/dmd -c \ -I~/apps/devel/d/dmd/src/phobos replace-ch.d /home/aharper/apps/devel/d/dmd/src/phobos/file.d(367): function \ remove conflicts with stdio.remove at \ /home/aharper/apps/devel/d/dmd/src/phobos/c/stdio.d(179) aharper@slinky:~/apps/devel/d$ Which is your original error message! Re-commenting out line 6 (import c.stdio) results in a compile with no errors: > aharper@slinky:~/apps/devel/d$ dmd/bin/dmd -c \ -I~/apps/devel/d/dmd/src/phobos replace-ch.d aharper@slinky:~/apps/devel/d$ So there is a conflict between the 'c.stdio' import and the 'stream' import, or so it seems. The file I ended up with (after making the changes above, and then whatever other changes I mentioned in my first message) imports both and compiles and runs quite happily. So there isn't a conflict, or is but only in some particular circumstance. I don't particularly have the inclination to go any further in tracking this down, DMD 0.75 is out and with it a new library structure, one that for the most part uses private imports to avoid exactly this sort of thing. The one piece of advice I can give, having looked at this, is that import c.stdio isn't necessary, the compiler will import/link the symbols anyway (so, for example, printf works without having imported c.stdio). In fact it would seem that you should *avoid* explicitly importing c.stdio, otherwise you may get cryptic messages about conflicting functions from within the standard lib. At least that /was/ the situation with DMD's prior to 0.75, I don't know how things stand now. Anyway, I hope this has helped you Charles, and that you've now got at least a partial understanding of what was going on, me I am more confused than I was when I started :-) Also, the previous 'replace.d' I posted contains a few minor errors, like trying to catch the wrong sort of errors (FileError's instead of Open/WriteError's), so if you do anything with those keep that in mind. |
Copyright © 1999-2021 by the D Language Foundation