digitalmars.D.learn - D1: std.md5: corrections for the given example
- notna (10/10) Sep 16 2009 Hi.
-
Stewart Gordon
(7/11)
Sep 16 2009
- notna (27/32) Sep 16 2009 Thank Stewart.
- downs (7/45) Sep 17 2009 // int len;
- notna (2/6) Sep 17 2009 Thanks, that looks "cleaner"...
-
Stewart Gordon
(8/9)
Sep 17 2009
- notna (25/37) Sep 17 2009 yeah, you're right again.
- downs (4/16) Sep 17 2009 God I'm stupid.
- grauzone (2/21) Sep 18 2009 http://d.puremagic.com/issues/enter_bug.cgi
- notna (6/21) Sep 18 2009 ???
- Stewart Gordon (8/18) Sep 18 2009 Where to report bugs.
- grauzone (3/28) Sep 19 2009 Enhancement request to allow auto in while, to make it consistent with
- Stewart Gordon (5/13) Sep 19 2009 The chance of an enhancement request being landed in the D1 line has
Hi. In the given example of the D1 std.md5, this line can be found: while ((len = fread(buffer, 1, buffer.sizeof, file)) != 0) This isn't working here (DMD v1.042, Windows XP Pro). I had to replace it with: while ((len = fread(buffer.ptr, cast(uint)1, buffer.sizeof, file)) != 0) ^^^ ^^^^^^^^^^ Someone may want to check & adopt this in the std.md5 module... Thanks & regards notna
Sep 16 2009
notna wrote: <snip>This isn't working here (DMD v1.042, Windows XP Pro). I had to replace it with: while ((len = fread(buffer.ptr, cast(uint)1, buffer.sizeof, file)) != 0) ^^^ ^^^^^^^^^^<snip> The .ptr is necessary, but the cast(uint) isn't. Even if a change of type were necessary, just 1U would do. (U is a suffix meaning unsigned. There's also L meaning long.) Stewart.
Sep 16 2009
Stewart Gordon schrieb:The .ptr is necessary, but the cast(uint) isn't. Even if a change of type were necessary, just 1U would do. (U is a suffix meaning unsigned. There's also L meaning long.) Stewart.Thank Stewart. As the std.md5-example is not working with "unicode" file names (fopen...) I rewrote the "MDFile" function and use "file.readBlock" instead now. Maybe the std.md5 example should be changed to use a "file.read" or "file.readBlock". Here is my code (I've checkedthe file exists and is readable before): string MD5File(string fileName) { File file = new File; MD5_CTX context; int len; ubyte[4 * 1024] buffer; ubyte digest[16]; file.open(fileName, FileMode.In); context.start(); while ((len = file.readBlock(buffer.ptr, buffer.sizeof)) != 0) context.update(buffer[0 .. len]); context.finish(digest); file.close(); string MD5Sum = (digestToString(digest)); return MD5Sum; } Regards notna
Sep 16 2009
notna wrote:Stewart Gordon schrieb:scope file = new File(fileName, FileMode.In);The .ptr is necessary, but the cast(uint) isn't. Even if a change of type were necessary, just 1U would do. (U is a suffix meaning unsigned. There's also L meaning long.) Stewart.Thank Stewart. As the std.md5-example is not working with "unicode" file names (fopen...) I rewrote the "MDFile" function and use "file.readBlock" instead now. Maybe the std.md5 example should be changed to use a "file.read" or "file.readBlock". Here is my code (I've checkedthe file exists and is readable before): string MD5File(string fileName) { File file = new File;MD5_CTX context; int len;// int len;ubyte[4 * 1024] buffer; ubyte digest[16]; file.open(fileName, FileMode.In);// file.open(fileName, FileMode.In);context.start(); while ((len = file.readBlock(buffer.ptr, buffer.sizeof)) != 0)while (auto len = file.readBlock(buffer.ptr, buffer.sizeof))context.update(buffer[0 .. len]); context.finish(digest); file.close();// What's up with this?string MD5Sum = (digestToString(digest)); return MD5Sum;// return digestToString(digest);} Regards notna
Sep 17 2009
downs wrote:scope file = new File(fileName, FileMode.In); // int len; while (auto len = file.readBlock(buffer.ptr, buffer.sizeof)) // return digestToString(digest);Thanks, that looks "cleaner"...
Sep 17 2009
downs wrote: <snip>while (auto len = file.readBlock(buffer.ptr, buffer.sizeof))<snip> md5_example_2.d(7): expression expected, not 'auto' md5_example_2.d(7): found 'len' when expecting ')' md5_example_2.d(7): found '=' instead of statement (this is line 7 after I removed comments and blank lines from your edit) Stewart.
Sep 17 2009
Stewart Gordon schrieb:downs wrote: <snip>yeah, you're right again. sorr, I had'n the time to test as I posted the message before. that's why I wrote "it looks cleaner" :-( anyhow, also the " != 0 " is needed. otherwise I get this: Error: '=' does not give a boolean result so, the working code is: string MD5File(string fileName) { File file = new File(fileName, FileMode.In); MD5_CTX context; int len; ubyte[4 * 1024] buffer; ubyte digest[16]; context.start(); while ((len = file.readBlock(buffer.ptr, buffer.sizeof)) != 0) context.update(buffer[0 .. len]); context.finish(digest); file.close(); return digestToString(digest); }while (auto len = file.readBlock(buffer.ptr, buffer.sizeof))<snip> md5_example_2.d(7): expression expected, not 'auto' md5_example_2.d(7): found 'len' when expecting ')' md5_example_2.d(7): found '=' instead of statement (this is line 7 after I removed comments and blank lines from your edit) Stewart.
Sep 17 2009
Stewart Gordon wrote:downs wrote: <snip>God I'm stupid. Sorry. I guess I wish that worked.while (auto len = file.readBlock(buffer.ptr, buffer.sizeof))<snip> md5_example_2.d(7): expression expected, not 'auto' md5_example_2.d(7): found 'len' when expecting ')' md5_example_2.d(7): found '=' instead of statement (this is line 7 after I removed comments and blank lines from your edit) Stewart.
Sep 17 2009
downs wrote:Stewart Gordon wrote:http://d.puremagic.com/issues/enter_bug.cgidowns wrote: <snip>God I'm stupid. Sorry. I guess I wish that worked.while (auto len = file.readBlock(buffer.ptr, buffer.sizeof))<snip> md5_example_2.d(7): expression expected, not 'auto' md5_example_2.d(7): found 'len' when expecting ')' md5_example_2.d(7): found '=' instead of statement (this is line 7 after I removed comments and blank lines from your edit) Stewart.
Sep 18 2009
grauzone schrieb:??? What do you wanna tell us? That while (auto len = file.readBlock(buffer.ptr, buffer.sizeof)) has to work and does not because it's a bug? And that's why you think a bug report should be opened?http://d.puremagic.com/issues/enter_bug.cgimd5_example_2.d(7): expression expected, not 'auto' md5_example_2.d(7): found 'len' when expecting ')' md5_example_2.d(7): found '=' instead of statement (this is line 7 after I removed comments and blank lines from your edit) Stewart.God I'm stupid. Sorry. I guess I wish that worked.
Sep 18 2009
notna wrote:grauzone schrieb:<snip>Where to report bugs.http://d.puremagic.com/issues/enter_bug.cgi??? What do you wanna tell us?That while (auto len = file.readBlock(buffer.ptr, buffer.sizeof)) has to work and does not because it's a bug?If you want to know whether a piece of code is legal or not, try reading the D documentation.And that's why you think a bug report should be opened?No, that this code example in the Phobos documentation is wrong and therefore a bug report should be opened. Stewart.
Sep 18 2009
notna wrote:grauzone schrieb:Enhancement request to allow auto in while, to make it consistent with if. (You can write "if(auto x = foo()) {...}")??? What do you wanna tell us? That while (auto len = file.readBlock(buffer.ptr, buffer.sizeof)) has to work and does not because it's a bug? And that's why you think a bug report should be opened?http://d.puremagic.com/issues/enter_bug.cgimd5_example_2.d(7): expression expected, not 'auto' md5_example_2.d(7): found 'len' when expecting ')' md5_example_2.d(7): found '=' instead of statement (this is line 7 after I removed comments and blank lines from your edit) Stewart.God I'm stupid. Sorry. I guess I wish that worked.
Sep 19 2009
grauzone wrote:notna wrote:<snip>The chance of an enhancement request being landed in the D1 line has always been small, and now it's even smaller. Stewart.What do you wanna tell us? That while (auto len = file.readBlock(buffer.ptr, buffer.sizeof)) has to work and does not because it's a bug? And that's why you think a bug report should be opened?Enhancement request to allow auto in while, to make it consistent with if. (You can write "if(auto x = foo()) {...}")
Sep 19 2009