Boost.ScopeExit based on D's scope(exit)

Georg Wrede georg.wrede at iki.fi
Wed Mar 4 12:38:09 PST 2009


Andrei Alexandrescu wrote:
> Georg Wrede wrote:
>>> I had no idea. Good you told me, I've put an ack in the source file.
>>
>> Thanks. I tried to locate the source in the dmd tree, but in vain.
>> So probably it should appear when rdmd is run with no arguments for 
>> there to be any effect... :-)
> 
> It's on dsource under phobos/tools. On 
> http://www.digitalmars.com/d/2.0/rdmd.html, there's a "download" link. 
> (I have just checked it in.)

Yes! Had to make the following changes to compile it (I'm on dmd2025):

$ diff rdmd.d-orig rdmd.d
34c34
< immutable string importWorld = "
---
 > immutable string importWorld = """
46c46
<     std.zlib;";
---
 >     std.zlib;""";
298,300c298,299
<     File depsReader;
<     depsReader.popen(depsGetter);
<     scope(exit) collectException(depsReader.close); // we don't care 
for errors
---
 >     auto depsReader = popen(depsGetter);
 >     scope(exit) fclose(depsReader);  // we don't care for errors


>> then you're already running rdmd. So, where do you use --shebang?
> 
> Because of the primitive way the shell parses the shebang line. Consider:
> 
> #!/usr/bin/rdmd -unittest
> ... code ...
> 
> All's dandy. Now say I want also -O:
> 
> #!/usr/bin/rdmd -unittest -O
> ... code ...
> 
> No go. The shell passes "-unittest -O" as one argument to rdmd, which is 
> not recognized as a flag. Always parsing the spaces away is not an 
> option because there are filenames and string arguments with spaces. So 
> I added --shebang to mean, parse the spaces in this argument:
> 
> #!/usr/bin/rdmd --shebang=-unittest -O
> ... code ...

Yes, I've many times wondered about that. Somehow, with linux, (and 
previously with unices) most of the time when something lookes stupid, 
turns out there is a profound reason for it.

>>> Of particular interest are --eval and --loop. Very helpful :o).
>>
>> Oh, these both are cool!
>>
>> PS: are you using zsh? The examples on 
>> http://www.digitalmars.com/d/2.0/rdmd.html have a percent prompt 
>> instead of the dollar prompt. Zsh seems to be fading out, the faq 
>> http://zsh.sourceforge.net/FAQ/zshfaq01.html is from 2005, and the 
>> last Fedora doesn't even have zsh as an option.
> 
> Yah. I didn't know it was going away. To me it seems pretty powerful, 
> e.g. more so than bash. Bummer...

Yeah, I used csh back when the only other option was sh. Had to switch 
later, too.


And now a major gripe: I have just spent *half a day* trying to figure 
out what's wrong when I try to use shebang with rdmd. I was basically 
using hello.d with a shebang. And with rdmd I got this peculiar error 
message:

.d'nnot read file '
/usr/local/digitalmars/dmd1040/linux/bin/rdmd: Couldn't compile or 
execute ./numma.d.

Just now I figured it out: numma.d was a copy of hello.d, which of 
course has Windows line endings. Aaaaaaaaaaaaaaaarrrrghhhhhh!



More information about the Digitalmars-d-announce mailing list