rdmd

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Wed Mar 4 14:18:02 PST 2009


Georg Wrede wrote:
> The one at http://www.digitalmars.com/d/2.0/rdmd.html has the following 
> code:
> 
> int eval(string todo)
> {
>     auto progname = tmpDir~"/eval.d";
>     std.file.write(progname, todo);
>     scope(exit) std.file.remove(progname);
>     run("dmd -run " ~ progname);
>     return 0;
> }
> 
> I think this is a problem when there are several users.
> Probably eval.d could be in a directory with a temporary name.

Yah, I changed it to:

int eval(string todo)
{
     MD5_CTX context;
     context.start();
     context.update(todo);
     ubyte digest[16];
     context.finish(digest);
     auto progname = std.path.join(tmpDir,
             "rdmd_eval" ~ digestToString(digest) ~ ".d");

     std.file.write(progname, todo);
     scope(exit) std.file.remove(progname);
     run("dmd -run " ~ progname);
     return 0;
}

By the way, md5 is so tedious to use. Five lines!! Should be one line to 
get a digest string. It's like, "let's see how to define an API that 
would take the most lines of code possible to use". Sigh.

Anyway, now with md5 in place I can reuse the executable filename such 
that successive calls to e.g. rdmd --eval "writeln(1 + 1)" do not 
compile anything. Can I assume the tmp directory will get cleaned in 
reasonable time by the system on both Windows and Unix?


Andrei



More information about the Digitalmars-d mailing list